element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Just Encase
  • Challenges & Projects
  • Design Challenges
  • Just Encase
  • More
  • Cancel
Just Encase
Blog Just Encase Design Challenge - Winter Driving Safety (Blog #4)
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Just Encase to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dwinhold
  • Date Created: 14 Feb 2022 6:13 PM Date Created
  • Views 688 views
  • Likes 7 likes
  • Comments 1 comment
  • just encase design challenge
  • sensors
  • dwinhold
  • Winter_driving_safety
Related
Recommended

Just Encase Design Challenge - Winter Driving Safety (Blog #4)

dwinhold
dwinhold
14 Feb 2022

Blog #4 Sensor updates

 

I advanced a fair bit with the programming of my project. I changed the TFT screen display to show what is needed for the driver.

The accelerometer will register any sudden movements from the vehicle, indicating you to slow down.

The GPS is now a speedometer to check to see if you are driving to fast for the weather conditions.

The temperature and humidity sensor are for the interior of the vehicle.

 

To be Completed:

Barometer: This is programmed but not set up yet. This will predict the current and changing weather, this lets the driver know what is coming up for road conditions.

Carbon Monoxide detector: This is programmed as well. This will warn you of the Carbon Monoxide levels in your vehicle if they start to get to high.

Temperature sensor: Set up but not programmed. This will be for outside temperature. This helps the computer know if the roads will be icy.

TFT display (to date)

The "Warning: " displays the Accelerometer movement warnings.

image

Updated Code:

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
#include <dht.h>
#include "ADXL335.h"
#include <SoftwareSerial.h>
#include <TinyGPS.h>


#define DHT11_PIN     5
#define TFT_CS        10
#define TFT_RST        9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC         8


#define TFT_MOSI 11  // Data out
#define TFT_SCLK 13  // Clock out

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);

float lat,lon; // create variable for latitude and longitude object 
SoftwareSerial gpsSerial(3,4);//rx,tx
TinyGPS gps;

dht DHT;
ADXL335 accelerometer;


void setup(void) {
  Serial.begin(9600);
  gpsSerial.begin(9600);
  accelerometer.begin();

  pinMode(2, OUTPUT);

  // Use this initializer if using a 1.8" TFT screen:
  tft.initR(INITR_BLACKTAB);      // Init ST7735S chip, black tab

  // Screen size 128x160
 

  tft.fillScreen(ST77XX_BLACK);


  // large block of text
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(30,40);
  tft.setTextColor(ST77XX_RED);
  tft.setTextSize(1);
  tft.println("Just");
  tft.setCursor(30,60);
  tft.println("Encase");
  tft.setCursor(30,80);
  tft.println("Design");
  tft.setCursor(30,100);
  tft.println("Challenge !!");
  delay(1500);
  tft.fillScreen(ST77XX_BLACK);
  tft.setCursor(30,40);
  tft.println("Winter");
  tft.setCursor(30,60);
  tft.println("Driving");
  tft.setCursor(30,80);
  tft.println("Safety!! ");
  delay(1500);
  tft.fillScreen(ST77XX_BLACK);
}

void loop() {

  // Start and display temperature and humidity
  int chk = DHT.read11(DHT11_PIN);
  switch (chk)
  
  tft.setTextWrap(false);
  tft.setCursor(0, 1);
  tft.setTextColor(ST77XX_RED);
  tft.setTextSize(1);
  tft.println("Temperature: ");
  tft.setCursor(80,1);
  tft.println(DHT.temperature, 1);
  tft.setCursor(0, 20);
  tft.println("Humidity: ");
  tft.setCursor(80,20);
  tft.println(DHT.humidity, 1);
  
  //Start and display Accelerometer information
  tft.setCursor(0, 40);
  tft.println("Warning: ");
  
  float ax,ay,az;
  accelerometer.getAcceleration(&ax,&ay,&az);
  if (ax<0 || ay<0 || az<0)
  {
   tft.setCursor(60,40);
   tft.println("Slow Down!!");
   digitalWrite(2,HIGH);
  }
  else
  {
   tft.setCursor(60,40);
   tft.println("None");
   digitalWrite(2,LOW);
  }

  //Get GPS information
  
  while(gpsSerial.available()){ // check for gps data
    if(gps.encode(gpsSerial.read()))// encode gps data
    { 
    gps.f_get_position(&lat,&lon); // get latitude and longitude
    }

  }

  //Get first GPS location

    double latitude = double(lat,6);
    double longitude = double(lon,6);

    delay(1000);

  while(gpsSerial.available()){ // check for gps data
    if(gps.encode(gpsSerial.read()))// encode gps data
    { 
    gps.f_get_position(&lat,&lon); // get latitude and longitude
    }
  }
  
  //Get second GPS location (1 second after first)
  
    double latitude2 = double(lat,6);
    double longitude2 = double(lon,6);

  //Change GPS coordinates to KmPH	
    
    double kmh = acos(cos(radians(90-(latitude,6))*cos(radians(90-(latitude2,6))+sin(radians(90-(latitude,6)))*sin(radians(90-(latitude2,6)))*cos(radians((longitude,6)-(longitude2,6)))*6371*60;
	

  //Display GPS Speed  

  tft.setTextSize(2);
  tft.setCursor(0,60);
  tft.println("Speed:");
  tft.setCursor(0,100);
  tft.println(kmh);
  
   
  delay(1000);


  //Clear displayed information
  
  tft.setTextColor(ST77XX_BLACK);
  tft.setTextSize(1);
  tft.setCursor(80, 1);
  tft.println(DHT.temperature, 1);
  
  tft.setCursor(80,20);
  tft.println(DHT.humidity, 1);
  
  tft.setCursor(60,40);
  tft.println("None");
  
  tft.setCursor(60,40);
  tft.println("Slow Down!!");
   
  tft.setTextSize(2);  
  tft.setCursor(0,100);
  tft.println(kmh);
  

  
}

The code and display will change as I advance to completing this project.

Dale Winhold

  • Sign in to reply
  • DAB
    DAB over 4 years ago

    Good start.

    Reminds me of our early programming of display graphics back in the 1980's.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube