Arduino Nano-Based Accident Detection and GPS Tracking System
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor for impacts using an accelerometer and to provide location data using a GPS module. It features an Arduino Nano as the central microcontroller, interfaced with a SIM800L GSM module for communication, a GPS NEO 6M module for location tracking, an ADXL335 accelerometer for impact detection, a buzzer for audio alerts, a pushbutton for user interaction, and an LM2596 voltage regulator to step down the voltage from a 12V battery to a suitable level for the other components.
Component List
Arduino Nano
- Microcontroller board based on the ATmega328P
- Provides digital and analog I/O pins
- Capable of serial communication
SIM800L
- GSM/GPRS module
- Allows for SMS and voice communication
- Interfaces with the Arduino via serial connection
ADXL335
- 3-axis accelerometer
- Measures acceleration in x, y, and z directions
- Used for impact detection
GPS NEO 6M
- GPS module
- Provides location data
- Communicates with the Arduino via serial connection
LM2596
- Voltage regulator
- Steps down the input voltage to a lower level
- Powers the SIM800L module
Pushbutton
- Momentary switch
- Used for user input to control the circuit
Buzzer
- Audio signaling device
- Provides audible alerts
12V Battery (Small Size)
- Power source for the circuit
- Provides 12V which is regulated down for other components
Wiring Details
Arduino Nano
GNDconnected to the common ground net5Vconnected to the 5V net from the LM2596D2connected to SIM800LRXDD3connected to SIM800LTXDD5connected to BuzzerPIND6connected to PushbuttonPin 1 (in)D8connected to GPS NEO 6MTXD9connected to GPS NEO 6MRXVINconnected to 12V BatteryVCCA0connected to ADXL335X-OUTA1connected to ADXL335Y-OUTA2connected to ADXL335Z-OUT
SIM800L
RXDconnected to Arduino NanoD2TXDconnected to Arduino NanoD3VCCconnected to LM2596OUTGNDconnected to the common ground net
ADXL335
VCCconnected to the 5V net from the LM2596GNDconnected to the common ground netX-OUTconnected to Arduino NanoA0Y-OUTconnected to Arduino NanoA1Z-OUTconnected to Arduino NanoA2
GPS NEO 6M
VCCconnected to the 5V net from the LM2596GNDconnected to the common ground netRXconnected to Arduino NanoD9TXconnected to Arduino NanoD8
LM2596
INconnected to 12V BatteryVCCand the common ground netOUTconnected to SIM800LVCCandGND, and provides the 5V net
Pushbutton
Pin 3 (out)connected to the common ground netPin 1 (in)connected to Arduino NanoD6
Buzzer
PINconnected to Arduino NanoD5GNDconnected to the common ground net
12V Battery (Small Size)
VCCconnected to Arduino NanoVINand LM2596INGNDconnected to the common ground net
Documented Code
The code is written for the Arduino Nano and is responsible for the following functions:
- Initializing the SIM800L module and GPS module
- Reading the ADXL335 accelerometer values and detecting impacts
- Sending an SMS with GPS location data when an impact is detected
- Allowing the user to cancel the alert with the pushbutton
- Handling incoming SMS commands to retrieve GPS location data
#include <AltSoftSerial.h>
#include <TinyGPS++.h>
#include <Wire.h>
#include <math.h>
#include <SoftwareSerial.h>
const String EMERGENCY_PHONE = "+918939843825";
#define rxPin 2
#define txPin 3
SoftwareSerial sim800(rxPin, txPin);
AltSoftSerial neogps;
TinyGPSPlus gps;
//RX Pin To D9
//TX Pin To D8
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) //impact detected
{
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