dikshadwivedi1819
Published © GPL3+

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.

IntermediateFull instructions provided58
Vehicle Position Tracking System

Things used in this project

Hardware components

NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
SparkFun GPS Module - Copernicus II DIP (12 Channel)
SparkFun GPS Module - Copernicus II DIP (12 Channel)
×1
Analog Accelerometer: ADXL335
Adafruit Analog Accelerometer: ADXL335
×1
Buzzer, Piezo
Buzzer, Piezo
×1
Temperature Sensor
Temperature Sensor
×1
Arduino UNO
Arduino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Mastech MS8217 Autorange Digital Multimeter
Digilent Mastech MS8217 Autorange Digital Multimeter

Story

Read more

Code

CODE

C/C++
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SparkFun_ADXL345.h>

static const int RXPin = 0, TXPin = 2;   // GPIO 4=D2(conneect Tx of GPS) and GPIO 5=D1(Connect Rx of GPS
static const uint32_t GPSBaud = 9600;

#define Addr 0x53

int buzz=D6;
int led = D7;
const uint8_t scl = D1; //D5
const uint8_t sda = D2; //D6
ADXL345 adxl = ADXL345();//if Baud rate 9600 didn't work in your case 0then use 4800

TinyGPSPlus gps; // The TinyGPS++ object
WidgetMap myMap(V8);  // V0 for virtual pin of Map Widget

SoftwareSerial ss(RXPin, TXPin);  // The serial connection to the GPS device

BlynkTimer timer;
     //Variable  to store the speed      //Variable to store no. of satellites response
String direc;  //Variable to store orientation or direction of GPS

char auth[] = "7d81ed3031614e37be9dcaa5ef75c86d";              //Your Project authentication key
char ssid[] = "diksha";                                       // Name of your network (HotSpot or Router name)
char pass[] = "diksha19";                                      // Corresponding Password




//unsigned int move_index;         // moving index, to be used later
unsigned int move_index = 1;  
int adcPin = A0;
float temperature;
//SimpleTimer timer;// fixed location for now
/* HC-SR501 Motion Detector */
 //Place to store read PIR Value
#define XValue                  V0
#define YValue                  V1
#define ZValue                  V2
#define VIRTUAL_LCD             V3

WidgetLCD lcd(VIRTUAL_LCD);

void checkGPS(){
  if (gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
      Blynk.virtualWrite(V4, "GPS ERROR");  // Value Display widget  on V4 if GPS not detected
  }
}
void sendReadings()
{
  Blynk.virtualWrite(10, temperature); // virtual pin 10
}
void refreshTime()
{
  long uptime = millis() / 60000L;

  // Output the following every minute:
  lcd.clear();                              // Clear LCD Screen on Blynk
  lcd.print(0, 0, "  ACCIDENT ");     // Outputs Application Name
  lcd.print(0, 1, " DETECTION ");
}

void setup()
{
  Serial.begin(115200);
  Serial.println();
  ss.begin(GPSBaud);
  Blynk.begin(auth, ssid, pass);
 
  
  timer.setInterval(5000L, checkGPS); 
  timer.setInterval(1000L, sendReadings);
  while (Blynk.connect() == false) {        // Be patient. 
                                            // Wait for Blynk to come online   
  }

  // Notify immediately on startup
  Blynk.notify("Device Started");           // Notification to smartphone

  // Setup a function to be called every minute
  //timer.setInterval(60000L, refreshTime);

  adxl.powerOn();                     // Power on the ADXL345

  adxl.setRangeSetting(8);            // Give the range settings
//  Blynk.virtualWrite(buzzer, LOW); 
   pinMode(buzz, OUTPUT);
   pinMode(led, OUTPUT);
   
lcd.clear();
  lcd.print(0, 0, "  ACCIDENT  ");
  lcd.print(0, 1, "DETECTION");
}
  


  
void loop()
{
    Blynk.run();
    int x,y,z;   
  adxl.readAccel(&x, &y, &z);         // Read the accelerometer values in variables x,y,z

  // Write the values to Blynk:
  Serial.println(x);
  Blynk.virtualWrite(V0, x);
  
  Serial.println(y);
  Blynk.virtualWrite(V1, y);
  Serial.println(z);
  Blynk.virtualWrite(V2, z);
  

  if((x >= -2 ) & (x <= 10) & ((y>=50) &(y<=70)))
{
   lcd.clear();
  lcd.print(0, 0, "  NORMAL  ");
   
   delay(100);
   digitalWrite(buzz,LOW);
   digitalWrite(led,LOW);
   
}
if(((x>=-50) & (x<=-10)) & ((y>=10) & (y<=40)))

{
   lcd.clear();
  lcd.print(0, 0, "  RIGHT  ");
  lcd.print(0, 1, " ACCIDENT ");
   
//   Blynk.virtualWrite(buzzer, HIGH); 
  digitalWrite(buzz,HIGH);
  digitalWrite(led,HIGH);
  delay(2000);
  lcd.clear();
  lcd.print(0, 0, "  ARE YOU OKAY? ");
  delay(100);
  lcd.print(0, 0, "  PRESS RST ");
  lcd.print(0, 1, " SWITCH ");
  delay(2000);
  lcd.print(0,0,"  LEFT  ");
  lcd.print(0,1,"ACCIDENT");
  lcd.clear();
  Blynk.notify("HELP! ADDIDENT OCCURED");
}
if(((x>=10)&(x<=60))&((y>=30)&(y<=60)))
{
  lcd.clear();
  lcd.print(0, 0, "  LEFT");
  lcd.print(0, 1, " ACCIDENT ");
//   Blynk.virtualWrite(buzzer, HIGH); 
  digitalWrite(buzz,HIGH);
  digitalWrite(led,HIGH);
  delay(2000);
  lcd.clear();
  lcd.print(0,0,"ARE YOU OKAY?");
  delay(100);
  lcd.print(0, 0, "  PRESS RST");
  lcd.print(0, 1, "   SWITCH   ");
  delay(2000);
  lcd.clear();
   lcd.print(0, 0,"RIGHT ");
  
  lcd.print(0,1,"ACCIDENT");
  
  Blynk.notify("HELP! ADDIDENT OCCURED");
  
  
 
}
if(((x>=0)&(x<=2))&((y>=40)&(y<=60)))

{lcd.clear();
  lcd.print(0, 0, "  FRONT");
  lcd.print(0, 1, " ACCIDENT ");
//   Blynk.virtualWrite(buzzer, HIGH); 
  digitalWrite(buzz,HIGH);
  digitalWrite(led,HIGH);
  delay(2000);
  lcd.clear();
  lcd.print(0,0,"ARE YOU OKAY?");
  delay(100);
  lcd.print(0, 0, "  PRESS RST");
  lcd.print(0, 1, " SWITCH ");
  delay(2000);
  lcd.clear();
   lcd.print(0, 0,"FRONT");
  
  lcd.print(0,1,"ACCIDENT");
  
  Blynk.notify("HELP! ADDIDENT OCCURED");
  
  
}

if(((x>=-2)&(x<=3))&((y>=50)&(y<=60)))
{
 lcd.clear();
  lcd.print(0, 0, "  BACK");
  lcd.print(0, 1, " ACCIDENT ");
 //  Blynk.virtualWrite(buzzer, HIGH); 
  digitalWrite(buzz,HIGH);
  digitalWrite(led,HIGH);
  delay(2000);
  lcd.clear();
  lcd.print(0,0,"ARE YOU OKAY?");
  delay(100);
  lcd.print(0, 0, "  PRESS RST");
  lcd.print(0, 1, " SWITCH ");
  delay(2000);
  lcd.clear();
   lcd.print(0, 0,"BACK");
  
  lcd.print(0,1,"ACCIDENT");
  
  Blynk.notify("HELP! ADDIDENT OCCURED");
  
}
   
    while (ss.available() > 0) 
    {
      // sketch displays information every time a new sentence is correctly encoded.
      if (gps.encode(ss.read()))
        displayInfo();
  }
  
  timer.run();
  unsigned int adcValue = analogRead(adcPin);
  temperature = adcValue * 330 / 1024; // 3.3 VREF, 10-bit ADC, 10mV = 1 degree Celsius

  // Just for debugging
  if (millis() % 1000 == 0) {
    Serial.print("ADC value: ");
    Serial.print(adcValue);
    Serial.print("; Current temperature (Celsius): ");
    Serial.println(temperature);
  }
}





void displayInfo()
{ 

  if (gps.location.isValid() ) 
  {
    
    float latitude = (gps.location.lat());     //Storing the Lat. and Lon. 
    float longitude = (gps.location.lng()); 
    
    Serial.print("LAT:  ");
    Serial.println(latitude, 6);  // float to x decimal places
    Serial.print("LONG: ");
    Serial.println(longitude, 6);
    Blynk.virtualWrite(V5, String(latitude, 6));   
    Blynk.virtualWrite(V6, String(longitude, 6));  
    myMap.location(move_index, latitude, longitude, "GPS_Location");
   
Serial.println();
}

Credits

dikshadwivedi1819

dikshadwivedi1819

4 projects • 1 follower

Comments

Add projectSign up / Login