Arduino UNO-Based Accident Detection and Emergency Alert System with GPS and GSM
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary of the Circuit
This circuit is designed to integrate an Arduino UNO with an ADXXL335 accelerometer, a Neo 6M GPS Module, and a Sim800l GSM module. The primary function of this circuit is to detect impacts using the accelerometer and then use the GPS module to acquire location data. Upon detecting an impact, the system can send an SMS alert with the location coordinates and make an emergency call using the GSM module. The Arduino UNO serves as the central processing unit, interfacing with the sensors and the GSM module, and executing the embedded code to perform the required tasks.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13.
ADXXL335 Accelerometer
- Description: A small, thin, low power, complete 3-axis accelerometer with signal conditioned voltage outputs.
- Pins: VCC, X-OUT, Y-OUT, Z-OUT, GND.
Neo 6M GPS Module
- Description: A standalone GPS receiver module that can track up to 22 satellites on 66 channels.
- Pins: GND, TX, RX, VCC.
Sim800l GSM Module
- Description: A complete Quad-band GSM/GPRS solution in an SMT type, allowing you to benefit from small dimensions and cost-effective solutions.
- Pins: NET, RST, VCC, RXD, TXD, GND.
Wiring Details
Arduino UNO
- GND connected to ADXXL335 GND, Neo 6M GPS Module GND, and Sim800l GND.
- Vin connected to Sim800l VCC.
- A1 connected to ADXXL335 X-OUT.
- A2 connected to ADXXL335 Y-OUT.
- A3 connected to ADXXL335 Z-OUT.
- D10 connected to Neo 6M GPS Module RX.
- D9 connected to Neo 6M GPS Module TX.
- D3 connected to Sim800l RXD.
- D2 connected to Sim800l TXD.
ADXXL335 Accelerometer
- VCC connected to Neo 6M GPS Module VCC.
- X-OUT connected to Arduino UNO A1.
- Y-OUT connected to Arduino UNO A2.
- Z-OUT connected to Arduino UNO A3.
- GND connected to Arduino UNO GND.
Neo 6M GPS Module
- GND connected to Arduino UNO GND and Sim800l GND.
- TX connected to Arduino UNO D9.
- RX connected to Arduino UNO D10.
- VCC connected to ADXXL335 VCC.
Sim800l GSM Module
- NET not connected.
- RST not connected.
- VCC connected to Arduino UNO Vin.
- RXD connected to Arduino UNO D3.
- TXD connected to Arduino UNO D2.
- GND connected to Arduino UNO GND.
Documented Code
The code is written for the Arduino UNO and is responsible for interfacing with the ADXXL335 accelerometer, the Neo 6M GPS Module, and the Sim800l GSM module. It includes functionality to detect impacts, acquire GPS coordinates, send SMS alerts, and make emergency calls.
#include <AltSoftSerial.h>
#include <TinyGPS++.h>
#include <Wire.h>
#include <math.h>
#include <SoftwareSerial.h>
const String EMERGENCY_PHONE = "+91xxxxxxxxxx";
#define rxPin 2
#define txPin 3
SoftwareSerial sim800(rxPin, txPin);
AltSoftSerial neogps;
TinyGPSPlus gps;
String sms_status, sender_number, received_date, msg;
String latitude, longitude;
#define BUZZER 5
#define BUTTON 6
#define xPin A0
#define yPin A1
#define zPin A2
byte updateflag;
int xaxis = 0, yaxis = 0, zaxis = 0;
int deltx = 0, delty = 0, deltz = 0;
int vibration = 2;
int devibrate = 75;
int magnitude = 0;
int sensitivity = 20;
double angle;
boolean impact_detected = false;
unsigned long time1;
unsigned long impact_time;
unsigned long alert_delay = 30000;
void setup() {
Serial.begin(9600);
sim800.begin(9600);
neogps.begin(9600);
pinMode(BUZZER, OUTPUT);
pinMode(BUTTON, INPUT_PULLUP);
sms_status = "";
sender_number = "";
received_date = "";
msg = "";
sim800.println("AT");
delay(1000);
sim800.println("ATE1");
delay(1000);
sim800.println("AT+CPIN?");
delay(1000);
sim800.println("AT+CMGF=1");
delay(1000);
sim800.println("AT+CNMI=1,1,0,0,0");
delay(1000);
time1 = micros();
xaxis = analogRead(xPin);
yaxis = analogRead(yPin);
zaxis = analogRead(zPin);
}
void loop() {
if (micros() - time1 > 4999) Impact();
if (updateflag > 0) {
updateflag = 0;
Serial.println("Impact detected!!");
Serial.print("Magnitude:");
Serial.println(magnitude);
getGps();
digitalWrite(BUZZER, HIGH);
impact_detected = true;
impact_time = millis();
}
if (impact_detected == true) {
if (millis() - impact_time >= alert_delay) {
digitalWrite(BUZZER, LOW);
makeCall();
delay(1000);
sendAlert();
impact_detected = false;
impact_time = 0;
}
}
if (digitalRead(BUTTON) == LOW) {
delay(200);
digitalWrite(BUZZER, LOW);
impact_detected = false;
impact_time = 0;
}
while (sim800.available()) {
parseData(sim800.readString());
}
while (Serial.available()) {
sim800.println(Serial.readString());
}
}
void Impact() {
time1 = micros();
int oldx = xaxis;
int oldy = yaxis;
int oldz = zaxis;
xaxis = analogRead(xPin);
yaxis = analogRead(yPin);
zaxis = analogRead(zPin);
vibration--;
Serial.print("Vibration = ");
Serial.println(vibration);
if (vibration < 0) vibration = 0;
if (vibration > 0) return;
deltx = xaxis - oldx;
delty = yaxis - oldy;
deltz = zaxis - oldz;
magnitude = sqrt(sq(deltx) + sq(delty) + sq(deltz));
if (magnitude >= sensitivity) {
updateflag = 1;
vibration = devibrate;
} else {
magnitude = 0;
}
}
void parseData(String buff) {
Serial.println(buff);
unsigned int len, index;
index = buff.indexOf("\r");
buff.remove(0, index + 2);
buff.trim();
if (buff != "OK") {
index = buff.indexOf(":");
String cmd = buff.substring(0, index);
cmd.trim();
buff.remove(0, index + 2);
if (cmd == "+CMTI") {
index = buff.indexOf(",");
String temp = buff.substring(index + 1, buff.length());
temp = "AT+CMGR=" + temp + "\r";
sim800.println(temp);
} else if (cmd == "+CMGR") {
if (buff.indexOf(EMERGENCY_PHONE) > 1) {
buff.toLowerCase();
if (buff.indexOf("get gps") > 1) {
getGps();
String sms_data;
sms_data = "GPS Location Data\r";
sms_data += "http://maps.google.com/maps?q=loc:";
sms_data += latitude + "," + longitude;
sendSms(sms_data);
}
}
}
} else {
}
}
void getGps() {
boolean newData = false;
for (unsigned long start = millis(); millis() - start < 2000;) {
while (neogps.available()) {
if (gps.encode(neogps.read())) {
newData = true;
break;
}
}
}
if (newData) {
latitude = String(gps.location.lat(), 6);
longitude = String(gps.location.lng(), 6);
newData = false;
} else {
Serial.println("No GPS data is available");
latitude = "";
longitude = "";
}
Serial.print("Latitude= "); Serial.println(latitude);
Serial.print("Lngitude= "); Serial.println(longitude);
}
void sendAlert() {
String sms_data;
sms_data = "Accident Alert!!\r";
sms_data += "http://maps.google.com/maps?q=loc:";
sms_data += latitude + "," + longitude;
sendSms(sms