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

Arduino UNO-Based GPS and GSM Emergency Alert System with Wi-Fi Connectivity

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based GPS and GSM Emergency Alert System with Wi-Fi Connectivity

Circuit Documentation

Summary

This circuit integrates an Arduino UNO microcontroller with several modules and components to create a GPS tracking and emergency alert system. The system includes a GSM module (Sim800l) for communication, a GPS module (Ublox NEO-M8N) for location tracking, a WiFi module (ESP8266 ESP-01) for network connectivity, an LED for visual indication, and a buzzer for audible alerts. The Arduino UNO is programmed to read GPS data, send location updates to a server, and trigger emergency alerts via SMS and calls.

Component List

Arduino UNO

Sim800l

Ublox NEO-M8N GPS module

ESP8266 ESP-01 WiFi Module

LED: Two Pin (red)

Buzzer

Resistor

Wiring Details

Arduino UNO

Sim800l

Ublox NEO-M8N GPS module

ESP8266 ESP-01 WiFi Module

LED: Two Pin (red)

Buzzer

Resistor

Code Documentation

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

// Pin configurations for GSM and GPS modules
SoftwareSerial gsmSerial(10, 11);  // RX, TX for GSM module
SoftwareSerial gpsSerial(3, 4);    // RX, TX for GPS module

TinyGPSPlus gps;

// Pin configuration for emergency button
const int buttonPin = 2;  // Emergency button pin

// Server URL for sending data
const char* serverURL = "https://cuboid-rigorous-red.glitch.me/"; // Replace with your server URL

bool buttonPressed = false;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);   // Configure button pin as input with pull-up resistor
  gsmSerial.begin(9600);              // Initialize GSM serial communication
  gpsSerial.begin(9600);              // Initialize GPS serial communication
  Serial.begin(9600);                 // Start the serial monitor for debugging

  // Send SMS to confirm system startup
  sendSMS("System started. GPS tracking enabled.");
}

void loop() {
  // Process incoming GPS data
  while (gpsSerial.available() > 0) {
    gps.encode(gpsSerial.read());

    // Check if new GPS location is available
    if (gps.location.isUpdated()) {
      float latitude = gps.location.lat();
      float longitude = gps.location.lng();
      Serial.print("Latitude= "); Serial.print(latitude, 6);
      Serial.print(" Longitude= "); Serial.println(longitude, 6);

      // Send the location to the server
      sendLocationToServer(latitude, longitude);
    }
  }

  // Check if the emergency button is pressed
  if (digitalRead(buttonPin) == LOW) {
    buttonPressed = true;
    delay(200);  // Debounce delay
  }

  if (buttonPressed) {
    // Trigger emergency alert
    sendEmergencyAlert();
    buttonPressed = false;  // Reset button pressed flag
  }
}

// Function to send GPS location to the server
void sendLocationToServer(float lat, float lng) {
  String postData = "lat=" + String(lat, 6) + "&lng=" + String(lng, 6);
  sendHTTPPostRequest("/update-location", postData);
}

// Function to trigger an emergency alert
void sendEmergencyAlert() {
  // Send alert message
  sendSMS("Emergency! Sending location to contacts.");
  
  // Call predefined contact (example number)
  makeCall("+918454044438");

  // Send alert to server
  String postData = "";
  sendHTTPPostRequest("/alert", postData);
}

// Function to send SMS using GSM module
void sendSMS(String message) {
  gsmSerial.println("AT+CMGF=1");    // Set SMS mode to text
  delay(1000);
  gsmSerial.println("AT+CMGS=\"+918454044438\"");  // Replace with predefined emergency contact
  delay(1000);
  gsmSerial.print(message);
  delay(1000);
  gsmSerial.write(26);  // Send CTRL+Z to indicate the end of the message
  delay(5000);
}

// Function to make a call using GSM module
void makeCall(String phoneNumber) {
  gsmSerial.println("ATD" + phoneNumber + ";");  // Dial the phone number
  delay(10000);  // Wait for 10 seconds
  gsmSerial.println("ATH");  // Hang up the call
}

// Function to send an HTTP POST request to the server
void sendHTTPPostRequest(String endpoint, String postData) {
  gsmSerial.println("AT+CGATT=1");  // Attach to GPRS network
  delay(1000);
  gsmSerial.println("AT+CGDCONT=1,\"IP\",\"your-apn\"");  // Set APN (replace with your APN)
  delay(1000);
  gsmSerial.println("AT+CGACT=1,1");  // Activate GPRS context
  delay(1000);

  gsmSerial.println("AT+HTTPINIT");  // Initialize HTTP service
  delay(1000);
  gsmSerial.println("AT+HTTPPARA=\"URL\",\"" + String(serverURL) + endpoint + "\"");  // Set URL
  delay(1000);
  gsmSerial.println("AT+HTTPPARA=\"CONTENT\",\"application/x-www-form-urlencoded\"");  // Set content type
  delay(1000);
  gsmSerial.println("AT+HTTPDATA=" + String(postData.length()) + ",10000");  // Set data length
  delay(1000);
  gsmSerial.print(postData);  // Send POST data
  delay(1000);
  gsmSerial.println("AT+HTTPACTION=1");