Vehicle Position Tracking System
The autonomous device will send the vehicle position to the android app with time and will show the location on google maps.
Components and supplies
1
Buzzer, Piezo
1
SparkFun GPS Module - Copernicus II DIP (12 Channel)
1
Arduino UNO
1
Analog Accelerometer: ADXL335
1
Temperature Sensor
1
NodeMCU ESP8266 Breakout Board
Tools and machines
1
Mastech MS8217 Autorange Digital Multimeter
1
Soldering iron (generic)
Apps and platforms
1
Blynk
1
Arduino IDE
Project description
Code
CODE
c_cpp
1#include <TinyGPS++.h> 2#include <SoftwareSerial.h> 3#define BLYNK_PRINT Serial 4#include <ESP8266WiFi.h> 5#include <BlynkSimpleEsp8266.h> 6#include <SparkFun_ADXL345.h> 7 8static const int RXPin = 0, TXPin = 2; // GPIO 4=D2(conneect Tx of GPS) and GPIO 5=D1(Connect Rx of GPS 9static const uint32_t GPSBaud = 9600; 10 11#define Addr 0x53 12 13int buzz=D6; 14int led = D7; 15const uint8_t scl = D1; //D5 16const uint8_t sda = D2; //D6 17ADXL345 adxl = ADXL345();//if Baud rate 9600 didn't work in your case 0then use 4800 18 19TinyGPSPlus gps; // The TinyGPS++ object 20WidgetMap myMap(V8); // V0 for virtual pin of Map Widget 21 22SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device 23 24BlynkTimer timer; 25 //Variable to store the speed //Variable to store no. of satellites response 26String direc; //Variable to store orientation or direction of GPS 27 28char auth[] = "7d81ed3031614e37be9dcaa5ef75c86d"; //Your Project authentication key 29char ssid[] = "diksha"; // Name of your network (HotSpot or Router name) 30char pass[] = "diksha19"; // Corresponding Password 31 32 33 34 35//unsigned int move_index; // moving index, to be used later 36unsigned int move_index = 1; 37int adcPin = A0; 38float temperature; 39//SimpleTimer timer;// fixed location for now 40/* HC-SR501 Motion Detector */ 41 //Place to store read PIR Value 42#define XValue V0 43#define YValue V1 44#define ZValue V2 45#define VIRTUAL_LCD V3 46 47WidgetLCD lcd(VIRTUAL_LCD); 48 49void checkGPS(){ 50 if (gps.charsProcessed() < 10) 51 { 52 Serial.println(F("No GPS detected: check wiring.")); 53 Blynk.virtualWrite(V4, "GPS ERROR"); // Value Display widget on V4 if GPS not detected 54 } 55} 56void sendReadings() 57{ 58 Blynk.virtualWrite(10, temperature); // virtual pin 10 59} 60void refreshTime() 61{ 62 long uptime = millis() / 60000L; 63 64 // Output the following every minute: 65 lcd.clear(); // Clear LCD Screen on Blynk 66 lcd.print(0, 0, " ACCIDENT "); // Outputs Application Name 67 lcd.print(0, 1, " DETECTION "); 68} 69 70void setup() 71{ 72 Serial.begin(115200); 73 Serial.println(); 74 ss.begin(GPSBaud); 75 Blynk.begin(auth, ssid, pass); 76 77 78 timer.setInterval(5000L, checkGPS); 79 timer.setInterval(1000L, sendReadings); 80 while (Blynk.connect() == false) { // Be patient. 81 // Wait for Blynk to come online 82 } 83 84 // Notify immediately on startup 85 Blynk.notify("Device Started"); // Notification to smartphone 86 87 // Setup a function to be called every minute 88 //timer.setInterval(60000L, refreshTime); 89 90 adxl.powerOn(); // Power on the ADXL345 91 92 adxl.setRangeSetting(8); // Give the range settings 93// Blynk.virtualWrite(buzzer, LOW); 94 pinMode(buzz, OUTPUT); 95 pinMode(led, OUTPUT); 96 97lcd.clear(); 98 lcd.print(0, 0, " ACCIDENT "); 99 lcd.print(0, 1, "DETECTION"); 100} 101 102 103 104 105void loop() 106{ 107 Blynk.run(); 108 int x,y,z; 109 adxl.readAccel(&x, &y, &z); // Read the accelerometer values in variables x,y,z 110 111 // Write the values to Blynk: 112 Serial.println(x); 113 Blynk.virtualWrite(V0, x); 114 115 Serial.println(y); 116 Blynk.virtualWrite(V1, y); 117 Serial.println(z); 118 Blynk.virtualWrite(V2, z); 119 120 121 if((x >= -2 ) & (x <= 10) & ((y>=50) &(y<=70))) 122{ 123 lcd.clear(); 124 lcd.print(0, 0, " NORMAL "); 125 126 delay(100); 127 digitalWrite(buzz,LOW); 128 digitalWrite(led,LOW); 129 130} 131if(((x>=-50) & (x<=-10)) & ((y>=10) & (y<=40))) 132 133{ 134 lcd.clear(); 135 lcd.print(0, 0, " RIGHT "); 136 lcd.print(0, 1, " ACCIDENT "); 137 138// Blynk.virtualWrite(buzzer, HIGH); 139 digitalWrite(buzz,HIGH); 140 digitalWrite(led,HIGH); 141 delay(2000); 142 lcd.clear(); 143 lcd.print(0, 0, " ARE YOU OKAY? "); 144 delay(100); 145 lcd.print(0, 0, " PRESS RST "); 146 lcd.print(0, 1, " SWITCH "); 147 delay(2000); 148 lcd.print(0,0," LEFT "); 149 lcd.print(0,1,"ACCIDENT"); 150 lcd.clear(); 151 Blynk.notify("HELP! ADDIDENT OCCURED"); 152} 153if(((x>=10)&(x<=60))&((y>=30)&(y<=60))) 154{ 155 lcd.clear(); 156 lcd.print(0, 0, " LEFT"); 157 lcd.print(0, 1, " ACCIDENT "); 158// Blynk.virtualWrite(buzzer, HIGH); 159 digitalWrite(buzz,HIGH); 160 digitalWrite(led,HIGH); 161 delay(2000); 162 lcd.clear(); 163 lcd.print(0,0,"ARE YOU OKAY?"); 164 delay(100); 165 lcd.print(0, 0, " PRESS RST"); 166 lcd.print(0, 1, " SWITCH "); 167 delay(2000); 168 lcd.clear(); 169 lcd.print(0, 0,"RIGHT "); 170 171 lcd.print(0,1,"ACCIDENT"); 172 173 Blynk.notify("HELP! ADDIDENT OCCURED"); 174 175 176 177} 178if(((x>=0)&(x<=2))&((y>=40)&(y<=60))) 179 180{lcd.clear(); 181 lcd.print(0, 0, " FRONT"); 182 lcd.print(0, 1, " ACCIDENT "); 183// Blynk.virtualWrite(buzzer, HIGH); 184 digitalWrite(buzz,HIGH); 185 digitalWrite(led,HIGH); 186 delay(2000); 187 lcd.clear(); 188 lcd.print(0,0,"ARE YOU OKAY?"); 189 delay(100); 190 lcd.print(0, 0, " PRESS RST"); 191 lcd.print(0, 1, " SWITCH "); 192 delay(2000); 193 lcd.clear(); 194 lcd.print(0, 0,"FRONT"); 195 196 lcd.print(0,1,"ACCIDENT"); 197 198 Blynk.notify("HELP! ADDIDENT OCCURED"); 199 200 201} 202 203if(((x>=-2)&(x<=3))&((y>=50)&(y<=60))) 204{ 205 lcd.clear(); 206 lcd.print(0, 0, " BACK"); 207 lcd.print(0, 1, " ACCIDENT "); 208 // Blynk.virtualWrite(buzzer, HIGH); 209 digitalWrite(buzz,HIGH); 210 digitalWrite(led,HIGH); 211 delay(2000); 212 lcd.clear(); 213 lcd.print(0,0,"ARE YOU OKAY?"); 214 delay(100); 215 lcd.print(0, 0, " PRESS RST"); 216 lcd.print(0, 1, " SWITCH "); 217 delay(2000); 218 lcd.clear(); 219 lcd.print(0, 0,"BACK"); 220 221 lcd.print(0,1,"ACCIDENT"); 222 223 Blynk.notify("HELP! ADDIDENT OCCURED"); 224 225} 226 227 while (ss.available() > 0) 228 { 229 // sketch displays information every time a new sentence is correctly encoded. 230 if (gps.encode(ss.read())) 231 displayInfo(); 232 } 233 234 timer.run(); 235 unsigned int adcValue = analogRead(adcPin); 236 temperature = adcValue * 330 / 1024; // 3.3 VREF, 10-bit ADC, 10mV = 1 degree Celsius 237 238 // Just for debugging 239 if (millis() % 1000 == 0) { 240 Serial.print("ADC value: "); 241 Serial.print(adcValue); 242 Serial.print("; Current temperature (Celsius): "); 243 Serial.println(temperature); 244 } 245} 246 247 248 249 250 251void displayInfo() 252{ 253 254 if (gps.location.isValid() ) 255 { 256 257 float latitude = (gps.location.lat()); //Storing the Lat. and Lon. 258 float longitude = (gps.location.lng()); 259 260 Serial.print("LAT: "); 261 Serial.println(latitude, 6); // float to x decimal places 262 Serial.print("LONG: "); 263 Serial.println(longitude, 6); 264 Blynk.virtualWrite(V5, String(latitude, 6)); 265 Blynk.virtualWrite(V6, String(longitude, 6)); 266 myMap.location(move_index, latitude, longitude, "GPS_Location"); 267 268Serial.println(); 269} 270
Comments
Only logged in users can leave comments