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

Arduino Nano Based GPS Tracker with GSM Module for Emergency Alerts

View and Edit Project In Cirkit DesignerImage of Arduino Nano Based GPS Tracker with GSM Module for Emergency Alerts

Circuit Documentation

Summary

This circuit is designed to interface a GPS module and a GSM module with an Arduino Nano microcontroller. It includes functionality for receiving GPS data, sending SMS messages, and making calls. The circuit also features two pushbuttons with pull-up resistors and a power supply section that includes a LiPoly battery, a charger module, and a buck converter to regulate the voltage.

Component List

Arduino Nano

GPS NEO 6M

SIM800c GSM Module

Pushbutton (x2)

Resistor (x2)

LM2956 Buck Converter DC-DC

LiPoly Battery (1300mAh)

LiPo Battery Charger Module

Wiring Details

Arduino Nano

GPS NEO 6M

SIM800c GSM Module

Pushbutton (x2)

Resistor (x2)

LM2956 Buck Converter DC-DC

LiPoly Battery (1300mAh)

LiPo Battery Charger Module

Documented Code

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

TinyGPSPlus gps;          // Use TinyGPSPlus class
SoftwareSerial Gsm(6, 7); // GSM module connected to pins 6 (RX) and 7 (TX)
char phone_no[] = "+91xxxxxxxxxx"; // Replace with actual phone number

int buttonPin = 10; // Button pin
int state;
String textMessage;

void setup() {
  Serial.begin(9600);  // For GPS module
  Gsm.begin(9600);     // For SIM800L GSM module
  
  // Set GSM to text mode and configure SMS reception
  Gsm.print("AT+CMGF=1\r"); 
  delay(100);
  Gsm.print("AT+CNMI=2,2,0,0,0\r"); 
  delay(100);
  
  pinMode(buttonPin, INPUT); // Button input
  enterIdleMode();  // Start in idle mode
}

void loop() {
  state = digitalRead(buttonPin);  // Check if button is pressed

  if (state == LOW) {  // If button is pressed
    wakeUp();  // Exit idle mode
    sendEmergencyAlert();  // Send alert and call
    enterIdleMode();  // Return to idle mode after task completion
  }

  if (Gsm.available() > 0) {  // If an SMS is received
    textMessage = Gsm.readString();
    textMessage.toUpperCase();  // Convert text to uppercase for case-insensitive comparison
    
    if (textMessage.indexOf("SEND LOCATION") >= 0) {  // If "SEND LOCATION" command is received
      wakeUp();  // Exit idle mode
      sendLocation();  // Send current location
      enterIdleMode();  // Return to idle mode
    }
  }
}

void sendEmergencyAlert() {
  if (getGPSData()) {  // If GPS data is valid
    Gsm.print("AT+CMGF=1\r");
    delay(400);
    Gsm.print("AT+CMGS=\"");
    Gsm.print(phone_no);
    Gsm.println("\"");
    Gsm.println("Alert! I need help.");
    Gsm.print("http://maps.google.com/maps?q=loc:");
    Gsm.print(gps.location.lat(), 6);  // Latitude
    Gsm.print(",");
    Gsm.print(gps.location.lng(), 6);  // Longitude
    delay(200);
    Gsm.println((char)26);  // End of SMS
    delay(200);
    Serial.println("Emergency SMS Sent");

    // Make an emergency call
    Serial.println("Calling...");
    Gsm.println("ATD+91xxxxxxxxxx;");  // Replace with actual phone number
    delay(20000);  // 20 seconds call duration
    Gsm.println("ATH");  // Hang up the call
    delay(1000);
  } else {
    Serial.println("Failed to get GPS data.");
  }
}

void sendLocation() {
  if (getGPSData()) {  // If GPS data is valid
    Gsm.print("AT+CMGF=1\r");
    delay(400);
    Gsm.print("AT+CMGS=\"");
    Gsm.print(phone_no);
    Gsm.println("\"");
    Gsm.println("Here is my current location:");
    Gsm.print("http://maps.google.com/maps?q=loc:");
    Gsm.print(gps.location.lat(), 6);  // Latitude
    Gsm.print(",");
    Gsm.print(gps.location.lng(), 6);  // Longitude
    delay(200);
    Gsm.println((char)26);  // End of SMS
    delay(200);
    Serial.println("Location SMS Sent");
  } else {
    Serial.println("Failed to get GPS data.");
  }
}

bool getGPSData() {
  bool newData = false;
  unsigned long start = millis();
  
  while (millis() - start < 10000) {  // Retry for 10 seconds
    while (Serial.available()) {
      char c = Serial.read();
      gps.encode(c);  // Process GPS data
      
      if (gps.location.isUpdated()) {
        newData = true;  // New GPS data received
      }
    }
  }

  if (!newData) {
    Serial.println("GPS fix failed.");
  }
  
  return newData;
}

void enterIdleMode() {
  // Code to reduce power consumption (e.g., disabling unused peripherals)
  Serial.println("Entering idle mode...");
  delay(100);
}

void wakeUp() {
  // Code to re-enable peripherals and prepare for operation
  Serial.println("Waking up from idle mode...");
  delay(100);
}

This code is designed to run on the Arduino Nano and provides the logic for the circuit's operation. It includes functions for sending emergency alerts, sending the current location, and managing power consumption modes. The code uses the TinyGPS++ library to parse GPS data and the SoftwareSerial library to communicate with the GSM module.