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

Arduino UNO Based GPS and GSM Tracking System with Emergency Alert Feature

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based GPS and GSM Tracking System with Emergency Alert Feature

Circuit Documentation

Summary

This circuit integrates an Arduino UNO microcontroller with a SIM800L GSM module and a Ublox NEO-M8N GPS module to create a system capable of GPS tracking and GSM communication. An emergency pushbutton is also included to trigger alerts. The Arduino UNO is responsible for controlling the flow of data between the GPS and GSM modules, processing GPS data, and handling the logic for emergency alerting and communication with a remote server.

Component List

Arduino UNO

Sim800l GSM Module

Ublox NEO-M8N GPS Module

Pushbutton

Wiring Details

Arduino UNO

Sim800l GSM Module

Ublox NEO-M8N GPS Module

Pushbutton

Documented Code

#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");  // Execute HTTP POST action
  delay(5000);
  gsmSerial.println("AT+HTTPTERM");  // Terminate HTTP service
  delay(1000);
}

Note: The code provided is for the Arduino UNO microcontroller and includes functionality for GPS data processing, emergency button handling, GSM communication for SMS and calls, and HTTP POST requests for server communication. The phone number and server URL are placeholders and should be replaced with actual contact details and server endpoints. Additionally, the APN settings in the sendHTTPPostRequest function should be configured according to the GSM network provider.