Jayashree
Published

Live Tracking and Accident Detection System

If an accident or any gas or smoke leakage is detected, it notifies through call and through Blynk app.

IntermediateFull instructions provided10 hours4,952
Live Tracking and Accident Detection System

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
TinyShield GPS
TinyCircuits TinyShield GPS
×1
Analog Accelerometer: ADXL335
Adafruit Analog Accelerometer: ADXL335
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×1
Grove - Gas Sensor(MQ2)
Seeed Grove - Gas Sensor(MQ2)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Story

Read more

Schematics

Accident_detection

gps_tracking & gas_detection

Code

Accident_detection

Arduino
using accelerometer readings x,y,z range we detect accident.
#include "TinyGPS++.h"
#include "SoftwareSerial.h"
SoftwareSerial GPRS(2,3);
SoftwareSerial serial_connection(10, 11); //RX=pin 10, TX=pin 11
TinyGPSPlus gps;//This is the GPS object that will pretty much do all the grunt work with the NMEA data
float latitude=0; 
float longitude=0;                       
String Speed="";
int Contrast=20;
#define x A1
#define y A2
#define z A3
int xsample=0;
int ysample=0;
int zsample=0;
#define samples 10
#define minVal -50
#define MaxVal 50
void setup()
{
  Serial.begin(9600);//This opens up communications to the Serial monitor in the Arduino IDE
  serial_connection.begin(9600);//This opens up communications to the GPS 
  Serial.println("successfully Initialized....");
  Serial.println("GPS Start");//Just show to the monitor that the sketch has started
  for(int i=0;i<samples;i++)
  {
    xsample+=analogRead(x);
    ysample+=analogRead(y);
    zsample+=analogRead(z);
  }

  xsample/=samples;
  ysample/=samples;
  zsample/=samples;

  Serial.println(xsample);
  Serial.println(ysample);
  Serial.println(zsample);
  delay(1000);
}

void loop()
{
  while(serial_connection.available())//While there are characters to come from the GPS
  {
    gps.encode(serial_connection.read());//This feeds the serial NMEA data into the library one char at a time
    //Serial.println("Satellite Count:");
  }
  if(gps.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in
  {
    //Get the latest info from the gps object which it derived from the data sent by the GPS unit
    Serial.println("Satellite Count:");
    Serial.println(gps.satellites.value());
    Serial.prin tln("Latitude:");
    Serial.println(gps.location.lat(), 6);
    Serial.println("Longitude:");
    Serial.println(gps.location.lng(), 6);
    Serial.println("Speed MPH:");
    Serial.println(gps.speed.mph());
    Serial.println("Altitude Feet:");
    Serial.println(gps.altitude.feet());
    Serial.println("");
  delay(1000);
  }
   int value1=analogRead(x);
    int value2=analogRead(y);
    int value3=analogRead(z);

    int xValue=xsample-value1;
    int yValue=ysample-value2;
    int zValue=zsample-value3;
    
    Serial.print("x=");
    Serial.println(xValue);
    Serial.print("y=");
    Serial.println(yValue);
    Serial.print("z=");
    Serial.println(zValue);
  delay(1000);
  //condition for accident detection
    if(xValue < minVal || xValue > MaxVal  || yValue < minVal || yValue > MaxVal  || zValue < minVal || zValue > MaxVal)
    {//in case of accident calling to a number 5 times if needed we can add multiple numbers.
      for(int i=0;i<5;i++)
      {
      Serial.println("calling");
      GPRS.begin(9600);
      Serial.println("Connecting to network");
      delay(20000);
      Serial.println("Should be connected to network by now");
      GPRS.print("ATD+xxxxxxxxxxxx;\r");
      Serial.println("Dialing");
      delay(12000); //Give it time to connect
      //GPRS.print("ATH\r"); // And disconnect
      Serial.println("Disconnect");
      }
    }`
    delay(1000);
}

tracking_accident_location

Arduino
Here, we used nodemcu, gps, gasdetector
Connecting nodemcu to wifi network and blynk app we can trace the location of person.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
static const int RXPin = 4, TXPin = 5;   // GPIO 4=D2(conneect Tx of GPS) and GPIO 5=D1(Connect Rx of GPS
static const uint32_t GPSBaud = 9600; 
char auth[] = "authentication key";              //Your Project authentication key
char ssid[] = "wifi id";                                       // Name of your network (HotSpot or Router name)
char pass[] = "wifi pwd";                                      // Corresponding Password
TinyGPSPlus gps; // The TinyGPS++ object
WidgetMap myMap(V0);
SoftwareSerial ss(RXPin, TXPin);  // The serial connection to the GPS device

BlynkTimer timer;
int gas_value;
int gas_avalue;
float spd;       //Variable  to store the speed
float sats;      //Variable to store no. of satellites response
String bearing;
unsigned int move_index = 1;   
void setup()
{
  pinMode(16, INPUT);
  Serial.begin(9600);
  ss.begin(GPSBaud);
  Blynk.begin(auth, ssid, pass);
  timer.setInterval(5000L, checkGPS); 
}
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 loop()
{
  gas_avalue = digitalRead(D3);
  if (gas_avalue < 1)
  {
    Serial.println("DANGER!!!!");
    digitalWrite(D4,HIGH);
    Blynk.notify("gas and smoke alert");
  }
  else
  {
    Serial.println("NO LEAKAGE");
    Blynk.notify("no leakage");
    digitalWrite(D4,LOW);
  }
  delay(100);
   while (ss.available() > 0) 
    {
      // sketch displays information every time a new sentence is correctly encoded.
      if (gps.encode(ss.read()))
        displayInfo();
  }
  Blynk.run();
  timer.run();
}
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(V1, String(latitude, 6));   
    Blynk.virtualWrite(V2, String(longitude, 6));  
    myMap.location(move_index, latitude, longitude, "GPS_Location");
    spd = gps.speed.kmph();               //get speed
       Blynk.virtualWrite(V3, spd);
       
       sats = gps.satellites.value();    //get number of satellites
       Blynk.virtualWrite(V4, sats);

       bearing = TinyGPSPlus::cardinal(gps.course.value()); // get the direction
       Blynk.virtualWrite(V5, bearing);               
      
    
  }
  

  Serial.println();
}

Credits

Jayashree

Jayashree

2 projects • 10 followers
Thanks to sai kumar chukka and saptadwipa rakshit.

Comments

Add projectSign up / Login