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.
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