Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Based Accident Detection and SOS Alert System with GPS and GSM

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Accident Detection and SOS Alert System with GPS and GSM

Circuit Documentation

Summary

The circuit in question is designed to monitor for accidents using an accelerometer and a piezo sensor. Upon detecting an accident, it activates an SOS signal and sends an SMS with the location coordinates obtained from a GPS module. The system is built around an Arduino UNO microcontroller, which interfaces with an MPU-6050 accelerometer, a Neo 6M GPS module, a Sim800l GSM module for communication, and a piezo sensor for impact detection. A resistor and a diode are also included for circuit protection and signal conditioning.

Component List

Arduino UNO

MPU-6050

Neo 6M GPS Module

Sim800l

Piezo Sensor

Resistor (1 MΩ)

1N4007 Rectifier Diode

Wiring Details

Arduino UNO

MPU-6050

Neo 6M GPS Module

Sim800l

Piezo Sensor

Resistor (1 MΩ)

1N4007 Rectifier Diode

Documented Code

#include <Wire.h>
#include <MPU6050.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>

MPU6050 accelgyro;
TinyGPSPlus gps;
SoftwareSerial gpsSerial(3, 4);    // RX, TX for GPS
SoftwareSerial gsmSerial(2, 3);    // RX, TX for GSM

const int piezoPin = A1;           // Piezo sensor connected to A1
const int piezoThreshold = 500;    // Threshold for piezo force detection
const int accelThreshold = 16000;  // Threshold for accelerometer

void setup() {
  Serial.begin(9600);
  gpsSerial.begin(9600);
  gsmSerial.begin(9600);

  // Initialize accelerometer
  Wire.begin();
  accelgyro.initialize();
  if (!accelgyro.testConnection()) {
    Serial.println("Accelerometer not connected!");
  }
}

void loop() {
  // Check for accident via accelerometer or piezo sensor
  if (detectAccident() || analogRead(piezoPin) > piezoThreshold) {
    activateSOS();
  }
}

bool detectAccident() {
  int16_t ax, ay, az;
  accelgyro.getAcceleration(&ax, &ay, &az);
  return (abs(ax) > accelThreshold || abs(ay) > accelThreshold || abs(az) > accelThreshold);
}

void activateSOS() {
  Serial.println("SOS Activated! Accident detected.");
  sendSMS();
}

void sendSMS() {
  if (gps.location.isValid()) {
    String message = "Accident detected! Location: ";
    message += "Lat: " + String(gps.location.lat(), 6) + ", ";
    message += "Lng: " + String(gps.location.lng(), 6);
    
    gsmSerial.println("AT+CMGF=1");             // Set SMS to text mode
    delay(100);
    gsmSerial.println("AT+CMGS=\"+1234567890\"");  // Replace with emergency contact number
    delay(100);
    gsmSerial.print(message);
    gsmSerial.write(26);                        // End message with Ctrl+Z
  } else {
    Serial.println("GPS location not valid.");
  }
}

This code is designed to run on the Arduino UNO and utilizes the MPU-6050 accelerometer to detect sudden changes in acceleration, indicative of an accident. When an accident is detected, it sends an SMS with the current GPS coordinates using the Sim800l GSM module. The piezo sensor is used as an additional means of detecting an impact. The code includes initialization and continuous monitoring in the setup and loop functions, respectively. The detectAccident function checks for high acceleration events, and the activateSOS function handles the SOS activation and SMS sending logic.