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

Arduino Nano-Based Panic Button System with GPS and GSM Modules

View and Edit Project In Cirkit DesignerImage of Arduino Nano-Based Panic Button System with GPS and GSM Modules

Circuit Documentation

Summary of the Circuit

The circuit is designed to operate as a panic button system, utilizing an Arduino Nano as the central microcontroller. It interfaces with a NEO6MV2 GPS module to obtain location data and three SIM800L GSM modules to communicate with external services such as hospital, fire department, and police. The system includes four pushbuttons that trigger different actions: three are dedicated to calling specific hotline numbers, and one is used to send the GPS location. A slide switch is used to control the power supply from a lithium battery, which is charged via a charging module. The circuit is designed to handle simultaneous button presses, allowing for the GPS location to be sent along with the hotline call.

Component List

Arduino Nano

GPS NEO 6M

Pushbutton (x4)

Resistor (x4)

lipo battery charger module

Polymer Lithium Ion Battery - 850mAh

SIM800L (x3)

Toggle Switch

Wiring Details

Arduino Nano

GPS NEO 6M

Pushbuttons

Resistor (x4)

lipo battery charger module

Polymer Lithium Ion Battery - 850mAh

SIM800L (x3)

Toggle Switch

Documented Code

/*
 * Panic Button System
 * This Arduino sketch controls a panic button system with an Arduino Nano,
 * NEO6MV2 GPS module, 3 SIM800L GSM modules, 4 panic buttons, a slide switch,
 * a lithium battery, and a charging module. The first three buttons are
 * connected to each GSM module to call specific hotline numbers (hospital,
 * fire department, police). The fourth button sends the GPS location. If a
 * hotline button and the GPS button are pressed simultaneously, the GPS
 * location is sent to the corresponding hotline number.
 */

#include <SoftwareSerial.h>

// Define pins for buttons
const int button1Pin = 8; // Hospital
const int button2Pin = 9; // Fire Department
const int button3Pin = 10; // Police
const int button4Pin = 11; // GPS

// Define pins for GSM modules
const int gsm1RxPin = 6;
const int gsm1TxPin = 7;
const int gsm2RxPin = 4;
const int gsm2TxPin = 5;
const int gsm3RxPin = 2;
const int gsm3TxPin = 3;

// Define pins for GPS module
const int gpsRxPin = 12;
const int gpsTxPin = 13;

// Create SoftwareSerial objects for GSM modules
SoftwareSerial gsm1(gsm1RxPin, gsm1TxPin);
SoftwareSerial gsm2(gsm2RxPin, gsm2TxPin);
SoftwareSerial gsm3(gsm3RxPin, gsm3TxPin);

// Create SoftwareSerial object for GPS module
SoftwareSerial gps(gpsRxPin, gpsTxPin);

void setup() {
  // Initialize serial communication
  Serial.begin(9600);
  gsm1.begin(9600);
  gsm2.begin(9600);
  gsm3.begin(9600);
  gps.begin(9600);

  // Initialize button pins as inputs
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);
  pinMode(button3Pin, INPUT);
  pinMode(button4Pin, INPUT);
}

void loop() {
  // Read button states
  bool button1State = digitalRead(button1Pin);
  bool button2State = digitalRead(button2Pin);
  bool button3State = digitalRead(button3Pin);
  bool button4State = digitalRead(button4Pin);

  // Check if any button is pressed
  if (button1State) {
    callHotline(gsm1, "hospital");
    if (button4State) {
      sendGPSLocation(gsm1);
    }
  } else if (button2State) {
    callHotline(gsm2, "fire department");
    if (button4State) {
      sendGPSLocation(gsm2);
    }
  } else if (button3State) {
    callHotline(gsm3, "police");
    if (button4State) {
      sendGPSLocation(gsm3);
    }
  } else if (button4State) {
    sendGPSLocation(gsm1); // Default to hospital if only GPS button is pressed
  }
}

void callHotline(SoftwareSerial &gsm, const char *hotline) {
  Serial.print("Calling ");
  Serial.println(hotline);

  // Dial the hotline number using the GSM module
  if (strcmp(hotline, "hospital") == 0) {
    gsm.print("+639066353525;\r"); // Replace with the actual hospital number
  } else if (strcmp(hotline, "fire department") == 0) {
    gsm.print("+639286294539;\r"); // Replace with the actual fire department number
  } else if (strcmp(hotline, "police") == 0) {
    gsm.print("+639060244955;\r"); // Replace with the actual police number
  }
}

void sendGPSLocation(SoftwareSerial &gsm) {
  Serial.println("Sending GPS location...");

  // Buffer to store GPS data
  char gpsData[100];
  int index = 0;

  // Read data from GPS module
  while (gps.available()) {
    char c = gps.read();
    if (c == '\n') {
      break;
    }
    gpsData[index++] = c;
  }
  gpsData[index] = '\0'; // Null-terminate the string

  // Send GPS data via GSM module
  gsm.print("AT+CMGF=1\r"); // Set SMS mode to text
  delay(100);
  gsm.print("AT+CMGS=\"+1234567890\"\r"); // Replace with the recipient's phone number
  delay(100);
  gsm.print("GPS Location: ");
  gsm.print(gpsData);
  delay(100);
  gsm.write(26); // ASCII code for CTRL+Z to send the SMS
  delay(100);
}

This code is responsible for the operation of the panic button system. It initializes the communication with the GSM and GPS modules, reads the state of the buttons, and performs actions such as calling hotlines or sending GPS location based on button presses. The callHotline function dials a predefined number, and the sendGPSLocation function reads GPS data and sends it via SMS.