Introduction: IoT BASED ACCIDENT DETECTION AND EMERGENCY SOS DEVICE

An emergency alert / SoS device that can connect with emergency services and family members in the event of an accident or fall from a 2-wheeler

Supplies

  • EM-506 GPS Module
  • Arduino UNO X4
  • Buzzer 5V
  • Mini Push Button Switch - 5-6mm
  • L298N Motor driver
  • MPU6050 Gyroscope and Accelerometer
  • DC Gear Motor
  • 12V Rechargeable Lithium Iron Battery
  • GSM Module
  • FORCE SENSING RESISTOR X2
  • RF TRANSMITTER
  • RF RECEIVER
  • MERCURY TILT SENSOR

Step 1: Need of the Project

  • An accident is an unpredictable and unintentional event. The vehicle accident especially two wheeler accident could be a major drawback in several countries, notably in India.
  • This is due to riders poor behaviors like drunk driving, speed driving etc, which leads to the high risk of people's life.
  • Therefore motorbike makers have developed safety devices to protect riders from accidental injuries like IoT based tracking devices and panic buttons.
  • This system helps in detecting the accident and sends a message with location to
  • the family and relatives

Step 2: Solution

  • Our proposed system mainly focuses on detecting the accident with different test cases, and actuates the corresponding system based on the results from the test cases.
  • GSM technology is used in order to send messages to the friends and family along with the nearby hospital names and their contact details.
  • In order to retrieve the nearby hospital data from the web, we used Google cloud API.
  • This system is also integrated with the Bike ignition control system, which ignites the bike engine unless the driver wears the helmet.

Step 3: Work Flow

  1. First and second test case deals with the detection of bike tilt and the driver occupancy in the bike seat. 
  2. The third test case gets into play when there is a fall detected in the bike and still the driver is sitting in the seat, in this case we're about to check the driver consciousness with the help of sensors and buzzers. 
  3. The system is employed with the mercury tilt sensor along with the helmet which finds the tilt in the helmet, a buzzer with the push button is also employed in the system to test the driver conscious
  4. Incase of helmet tilt, the buzzer gets turned up for 20 seconds waiting for the driver to press the push button to test his consciousness, incase if the push button state remains unchanged for the entire 20 seconds then the system calls it as an accident and starts the alerting process by turning down the buzzer. and if any state change is noticed in the push button within the buzzing period the system assumes that he is in a conscious state that he can take care of himself and no need for any assistances and the entire system repeats its process of testing the first test case.
  5. This system gets activated only in two cases, the working is quite a simple flow, where it fetches the gps coordinates of the location at the instance in which the system gets activa
  6. The acquired coordinates is further used in finding the nearby hospitals and their contact details which can be extracted from the json data acquired from the google map api. 
  7. The alert message along with the google location link in addition to the name and contact details of the nearby hospitals is sent to the specified phone numbers.


Hardware setup:



Step 4: Circuit Diagrams

Step 5: Codes

1st: Bike_Ignition_RX.ino

#include <VirtualWire.h>

int in1=2;

int in2=4;

int enA=3;

void setup()

{

pinMode(enA, OUTPUT);

pinMode(in1, OUTPUT);

pinMode(in2, OUTPUT);

vw_set_rx_pin(11);

vw_setup(2000);

vw_rx_start();

}

void loop()

{

uint8_t buf[VW_MAX_MESSAGE_LEN];

uint8_t buflen = VW_MAX_MESSAGE_LEN;



if (vw_get_message(buf, &buflen))

{

if(buf[0]=='a')

{

Serial.println("print");

digitalWrite(in1,HIGH);

digitalWrite(in2,LOW);

digitalWrite(enA, 100);

}

else if(buf[0]=='b')

{

delay(2000);

}

}

}


2nd: Google_API.ino

#include <ESP8266WiFi.h>

#include <WiFiClient.h>

#include <ESP8266HTTPClient.h>

#include <ArduinoJson.h>

const char* wifiName = "VIMALRAJ";

const char* wifiPass = "vimot4263";

const char *host_1 = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=27.2046%2C77.4977&radius=10000&type=hospital,medical&keyword=hospital&key=AIzaSyDFXOnblgz9iXzSQtsIsxwCWtVNMOCPRmI";

const char *host_2 = "https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJ02wsjiYhqTsRANPFIdaY-lo&key=AIzaSyDFXOnblgz9iXzSQtsIsxwCWtVNMOCPRmI";

void setup()

{

Serial.begin(115200);

delay(10);

Serial.println();

Serial.print("Connecting to ");

Serial.println(wifiName);

WiFi.begin(wifiName, wifiPass);

while (WiFi.status() != WL_CONNECTED)

{

delay(500);

Serial.print(".");

}

Serial.println("");

Serial.println("WiFi connected");

Serial.println("IP address: ");

Serial.println(WiFi.localIP());

}

void loop()

{

HTTPClient http;

Serial.print("Request Link:");

Serial.println(host_1);

http.begin(host_1);

int httpCode = http.GET();

String payload_1 = http.getString();

Serial.print("Response Code:");

Serial.println(httpCode);

Serial.print("Returned data from Server:");

Serial.println(payload_1);



if(httpCode == 200)

{

place();

const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 60;

DynamicJsonDocument capacity(1024);

JsonObject root = JsonBuffer.parseObject(payload_2);

Serial.println(F("Response:"));

Serial.print(root["name"].as<char*>());

Serial.println(root["formatted_phone_number"].as<char*>());

Serial.println(root["data"][0].as<char*>());

Serial.println(root["data"][1].as<char*>());

}

else

{

Serial.println("Error in response");

}

http.end();

delay(5000);

}

void place()

{

Serial.print("Request Link:");

Serial.println(host_2);

http.begin(host_2);

int httpCode = http.GET();

String payload_2 = http.getString();

Serial.print("Response Code:");

Serial.println(httpCode);

}


3rd: Bike_Ignition_TX.ino

#include <VirtualWire.h>

int fsrAnalogPin = 0;

int fsrReading;

int val;

int value = 0;

void setup()

{

Serial.begin(115200);

vw_set_tx_pin(12);

vw_setup(2000);

}

void loop()

{

fsrReading = analogRead(fsrAnalogPin);

Serial.print("Analog reading = ");

Serial.println(fsrReading);

if(fsrReading==0 && value==0)

{

const char *data="a";

vw_send((uint8_t *)data, strlen(data));

vw_wait_tx();

value = 1;

}

else

{

const char *data="b";

vw_send((uint8_t *)data, strlen(data));

vw_wait_tx();

value = 0;

}

}


4th: Main_Unit_Code.ino

#include <SoftwareSerial.h>

#include <Wire.h>

#include <TinyGPS.h>

#include <RH_ASK.h>

#include <SPI.h>

RH_ASK rf_driver;

const int MPU_addr=0x68;

int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

float ax=0, ay=0, az=0, gx=0, gy=0, gz=0;

float flat, flon;

unsigned long age;

int angleChange=0;

int fsrReading_2;

int fsrPin = 0;

int value = 0;

bool newData = false;

unsigned long chars;

unsigned short sentences, failed;

SoftwareSerial mySerial(3, 2);

SoftwareSerial GPSserial(12,11);

TinyGPS gps;

void setup()

{

Wire.begin();

Wire.beginTransmission(MPU_addr);

Wire.write(0x6B);

Wire.write(0);

Wire.endTransmission(true);

rf_driver.init();

Serial.begin(9600);

mySerial.begin(9600);

delay(500);

}

void loop()

{

mpu_read();

ax = (AcX-2050)/16384.00;

ay = (AcY-77)/16384.00;

az = (AcZ-1947)/16384.00;

gx = (GyX+270)/131.07;

gy = (GyY-351)/131.07;

gz = (GyZ+136)/131.07;

float Raw_AM = pow(pow(ax,2)+pow(ay,2)+pow(az,2),0.5);

int angleChange = pow(pow(gx,2)+pow(gy,2)+pow(gz,2),0.5);

int AM = Raw_AM * 10;

if((angleChange>10)&&(AM!=7&AM!=8))

{

Serial.println("FALL DETECTED");

seat_read();

delay(500);

}

else

{

Serial.println("NO FALL DETECTED");}

delay(1000);

}

void mpu_read()

{

Wire.beginTransmission(MPU_addr);

Wire.write(0x3B);

Wire.endTransmission(false);

Wire.requestFrom(MPU_addr,14,true);

AcX=Wire.read()<<8|Wire.read();

AcY=Wire.read()<<8|Wire.read();

AcZ=Wire.read()<<8|Wire.read();

Tmp=Wire.read()<<8|Wire.read();

GyX=Wire.read()<<8|Wire.read();

GyY=Wire.read()<<8|Wire.read();

GyZ=Wire.read()<<8|Wire.read();

}

void gsm_read()

{

gps_read();

Serial.println("Initializing...");

mySerial.println("AT");

updateSerial();

mySerial.println("AT+CMGF=1");

updateSerial();

mySerial.println("AT+CMGS=\"+917604912953\"");

updateSerial();

mySerial.println("Accident Detected");

updateSerial();

mySerial.print("http://maps.google.com/maps?q=loc:");

updateSerial();

mySerial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);

updateSerial();

mySerial.println(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);

updateSerial();

mySerial.println();

updateSerial();

mySerial.write(26);

}

void gps_read()

{

gps.f_get_position(&flat, &flon);

}

void updateSerial()

{

delay(500);

while (Serial.available())

{

mySerial.write(Serial.read());

}

while(mySerial.available())

{

Serial.write(mySerial.read());

}

}

void seat_read()

{

fsrReading_2 = analogRead(fsrPin);

if(fsrReading_2>1000 && value==0)

{

Serial.println("Person in the Seat");

helmet_tilt_read();

}

else

{

Serial.println("Person not in the Seat");

gsm_read();

}

}

void helmet_tilt_read()

{

uint8_t buf[11];

uint8_t buflen = sizeof(buf);

if (rf_driver.recv(buf, &buflen))

{

if((char*)buf=="a")

{

Serial.println("Person is Conscious");

loop();

}

else if((char*)buf=="b")

{

Serial.println("Person is Unconscious");

gsm_read();

}

}

}


5th: Helmet_tilt_Tx.ino

#include <VirtualWire.h>

#define Tilt 6

#define buzz 7

const int datain = 10;

char *data;

bool ce;

void setup()

{

Serial.begin(9600);

pinMode(Tilt, INPUT);

pinMode(buzz, OUTPUT);

vw_set_ptt_inverted(true);

vw_set_tx_pin(12);

vw_setup(4000);

}

void loop()

{

ce=digitalRead(Tilt);

if(ce==HIGH)

{

digitalWrite(buzz,HIGH);

delay(5000);

digitalWrite(buzz,LOW);

Serial.println("high");

transmitter_1();

}

else

{

digitalWrite(buzz,LOW);

delay(1000);

Serial.println("low");

transmitter_2();

}

}

void transmitter_1()

{

data="1";

vw_send((uint8_t *)data, strlen(data));

vw_wait_tx();

}

void transmitter_2()

{

data="2";

vw_send((uint8_t *)data, strlen(data));

vw_wait_tx();

}


Step 6: Detailed Video

Anything Goes Contest

Participated in the
Anything Goes Contest