Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

ESP32-Based GSM and GPS Emergency Locator with Pushbutton Activation

Image of ESP32-Based GSM and GPS Emergency Locator with Pushbutton Activation

Circuit Documentation

Summary

The circuit in question is designed to interface a SIM800L GSM module, a Neo 6M GPS module, and a pushbutton with an ESP32 microcontroller. The circuit is powered by a 9V battery and includes a resistor for voltage regulation. The primary function of this circuit is to send an SMS message with GPS coordinates when the pushbutton is pressed, indicating an emergency situation that requires attention.

Component List

SIM800L GSM Module

  • Pins: 5V, GND, VDD, SIM_TXD, SIM_RXD, RST
  • Description: A GSM/GPRS module that allows cellular network connectivity, capable of sending SMS and making voice calls.

Neo 6M GPS Module

  • Pins: GND, TX, RX, VCC
  • Description: A GPS receiver module that provides location data.

Pushbutton

  • Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)
  • Description: A simple pushbutton used to trigger an action, in this case, sending an SMS.

9V Battery

  • Pins: -, +
  • Description: Provides power to the circuit.

Resistor

  • Pins: pin1, pin2
  • Description: A 200 Ohm resistor, likely used for current limiting or pull-up/down purposes.

ESP32

  • Pins: 3V3, GND, D15, D2, D4, RX2, TX2, D5, D18, D19, D21, RX0, TX0, D22, D23, EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, VIN
  • Description: A powerful microcontroller with Wi-Fi and Bluetooth capabilities, used as the main controller in this circuit.

Wiring Details

SIM800L GSM Module

  • 5V connected to 9V Battery (+)
  • GND connected to 9V Battery (-), Neo 6M GPS Module (GND), and ESP32 (GND)
  • SIM_TXD connected to ESP32 (D18)
  • SIM_RXD connected to ESP32 (D19)

Neo 6M GPS Module

  • GND connected to SIM800L GSM Module (GND) and ESP32 (GND)
  • TX connected to ESP32 (RX2)
  • RX connected to ESP32 (TX2)
  • VCC connected to Resistor (pin2) and ESP32 (3V3)

Pushbutton

  • Pin 3 (out) connected to ESP32 (GND)
  • Pin 4 (out) connected to ESP32 (D4)
  • Pin 2 (in) connected to Resistor (pin1)

9V Battery

  • + connected to SIM800L GSM Module (5V)
  • - connected to SIM800L GSM Module (GND)

Resistor

  • pin1 connected to Pushbutton (Pin 2 (in))
  • pin2 connected to Neo 6M GPS Module (VCC) and ESP32 (3V3)

ESP32

  • 3V3 connected to Neo 6M GPS Module (VCC) and Resistor (pin2)
  • GND connected to SIM800L GSM Module (GND), Neo 6M GPS Module (GND), and Pushbutton (Pin 3 (out))
  • D18 connected to SIM800L GSM Module (SIM_TXD)
  • D19 connected to SIM800L GSM Module (SIM_RXD)
  • RX2 connected to Neo 6M GPS Module (TX)
  • TX2 connected to Neo 6M GPS Module (RX)
  • D4 connected to Pushbutton (Pin 4 (out))

Documented Code

#include <TinyGPS++.h>

// GSM module connection - use ESP32's hardware serial 1
#define GSM_SERIAL_NUM 1
#define GSM_RX_PIN 18
#define GSM_TX_PIN 19

// GPS module connection - use ESP32's hardware serial 2
#define GPS_SERIAL_NUM 2
#define GPS_RX_PIN 16
#define GPS_TX_PIN 17

// Pin definitions
const int buttonPin = 4;  // Push button connected to GPIO 4

// TinyGPS++ object
TinyGPSPlus gps;

// Variables
int buttonState = 0;
bool messageSent = false;
const char* phoneNumber = "+1234567890";  // Replace with the desired phone number
const char* message = "Emergency! Help needed at this location: ";

void setup() {
  Serial.begin(115200);
  
  // Initialize GSM serial
  Serial1.begin(9600, SERIAL_8N1, GSM_RX_PIN, GSM_TX_PIN);
  
  // Initialize GPS serial
  Serial2.begin(9600, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN);
  
  // Set up button pin
  pinMode(buttonPin, INPUT_PULLUP);
  
  // Initialize GSM module
  initGSM();
}

void loop() {
  // Update GPS data
  while (Serial2.available() > 0) {
    gps.encode(Serial2.read());
  }

  buttonState = digitalRead(buttonPin);

  if (buttonState == LOW && !messageSent) {
    sendSMS();
    messageSent = true;
  }
  
  if (buttonState == HIGH) {
    messageSent = false;
  }
}

void initGSM() {
  Serial.println("Initializing GSM module...");
  delay(1000);
  Serial1.println("AT");
  delay(1000);
  Serial1.println("AT+CMGF=1"); // Set SMS text mode
  delay(1000);
}

void sendSMS() {
  Serial.println("Button pressed, sending SMS with location...");
  
  String locationMessage = message;
  
  if (gps.location.isValid()) {
    locationMessage += "http://maps.google.com/maps?q=";
    locationMessage += String(gps.location.lat(), 6);
    locationMessage += ",";
    locationMessage += String(gps.location.lng(), 6);
  } else {
    locationMessage += "GPS location not available";
  }
  
  // Send SMS
  Serial1.println("AT+CMGS=\"" + String(phoneNumber) + "\"");
  delay(1000);
  Serial1.print(locationMessage);
  delay(100);
  Serial1.write(26); // End SMS with Ctrl+Z character
  
  Serial.println("SMS sent with location!");
  delay(1000);
}

This code is designed to run on the ESP32 microcontroller. It initializes communication with the SIM800L GSM module and the Neo 6M GPS module, reads the GPS data, and sends an SMS with the current location when the pushbutton is pressed. The code uses the TinyGPS++ library to parse the GPS data.