Build a Smart Safety Device
That Can Save Lives 🛡️
Press one button → your phone gets your GPS location → a loud alarm goes off. Learn to build this real-world safety gadget using ESP32!
How does this safety device work? 🧠
Imagine your friend is in trouble and needs help fast. She presses one button on this small wearable gadget. Instantly, the device does three things at the same time — it screams loudly with a buzzer, lights up a red warning LED, and sends a text message with her exact GPS location to a trusted person's phone.
The "brain" of our device is an ESP32 — a powerful little microcontroller with built-in Wi-Fi and Bluetooth. It talks to a GPS module (to find location) and a GSM module (to send SMS messages).
Button Pressed
Person presses the panic button
GPS Locates
GPS module finds latitude and longitude
SMS Sent
GSM sends location SMS to trusted number
Alarm Sounds
Buzzer screams to scare away danger
LED Flashes
Red LED blinks to signal distress
Key features of our safety device ✨
One-Button SOS
Hold the panic button for 2 seconds to trigger everything automatically — no typing needed.
Real GPS Tracking
The NEO-6M GPS module gives real latitude and longitude coordinates accurate to within 3 metres!
SMS to 3 Numbers
Sends a Google Maps link with location to up to 3 trusted phone numbers instantly.
Battery Powered
Runs on an 18650 rechargeable battery. Lasts 6–8 hours on a full charge.
Components you need 🛒
Get these parts from your local electronics shop or online (Amazon, Robu.in, Flipkart). Total cost: roughly ₹800–₹1200.
How to connect everything 🔌
The circuit diagram below shows all connections. Take your time — double-check every wire before turning it on!
Pin Connection Table 📌
| Component | Component Pin | ESP32 Pin | Notes |
|---|---|---|---|
| NEO-6M GPS | VCC | 3.3V | GPS runs on 3.3V only! |
| NEO-6M GPS | GND | GND | |
| NEO-6M GPS | TX | GPIO 4 (RX1) | GPS sends data here |
| NEO-6M GPS | RX | GPIO 5 (TX1) | ESP32 sends to GPS |
| SIM800L GSM | VCC | Battery 4V | SIM800L needs 3.7–4.2V — do NOT use 5V! |
| SIM800L GSM | GND | GND | Common ground |
| SIM800L GSM | TX | GPIO 16 (RX2) | GSM sends data to ESP32 |
| SIM800L GSM | RX | GPIO 17 (TX2) | ESP32 sends AT commands to GSM |
| Buzzer | + (positive) | GPIO 12 | Active buzzer — no resistor needed |
| Buzzer | – (negative) | GND | |
| Red LED | Anode (+) | GPIO 13 → 220Ω | Always use a resistor with LED! |
| Red LED | Cathode (–) | GND | |
| Panic Button | Pin 1 | GPIO 2 | Also connect 1kΩ pull-up to 3.3V |
| Panic Button | Pin 2 | GND | |
| TP4056 Charger | B+ B– | 18650 battery | OUT+ → VIN ESP32 via boost |
Step-by-step instructions 🔧
Follow every step carefully! Ask an adult to help especially with the battery connections.
Insert the SIM card into SIM800L
Before anything else, insert an active prepaid nano SIM card into the SIM800L module's SIM card slot. Make sure the SIM has balance for SMS. The module won't work without a working SIM.
Set up the ESP32 on the breadboard
Place the ESP32 in the centre of the breadboard so that pins are accessible on both sides. Connect the breadboard's red (+) rail to ESP32's 3.3V pin and the blue (–) rail to a GND pin.
Connect the NEO-6M GPS module
Connect GPS VCC to the 3.3V rail (not 5V!), GND to the GND rail, GPS TX pin to ESP32 GPIO 4, and GPS RX pin to ESP32 GPIO 5 using jumper wires.
Connect the SIM800L GSM module
Connect SIM800L VCC directly to the positive terminal of the 18650 battery (through the TP4056 OUT+). Connect GND to common ground. Connect SIM800L TX to ESP32 GPIO 16, and SIM800L RX to ESP32 GPIO 17.
Connect the buzzer
Place the active piezo buzzer on the breadboard. Connect the positive (+) pin to ESP32 GPIO 12, and the negative (–) pin to GND. No resistor needed for an active buzzer!
Connect the red LED
Place the LED on the breadboard. Connect the longer leg (anode/+) to ESP32 GPIO 13 through a 220Ω resistor. Connect the shorter leg (cathode/–) to GND.
Connect the panic button
Place the push button on the breadboard. Connect one leg to ESP32 GPIO 2. Connect the other leg to GND. Also add a 1kΩ resistor between GPIO 2 and the 3.3V rail — this is called a pull-up resistor and makes the button work properly.
Connect the battery and charger
Connect the 18650 battery to the TP4056 charger module (B+ and B–). The OUT+ and OUT– of TP4056 power the SIM800L directly. Use a separate 5V USB power bank or the same battery through a boost converter to power the ESP32's VIN pin.
Upload the code and test!
Connect the ESP32 to your computer via USB. Open Arduino IDE, install the TinyGPS++ library and SoftwareSerial, copy the code below, change the phone numbers, and click Upload. Open the Serial Monitor at 115200 baud to see what's happening.
ESP32 Arduino code 💻
Copy this into Arduino IDE. Change the phone numbers to real trusted numbers before uploading. Every section is explained with comments!
TinyGPS++ by Mikal Hart | ESP32 board via Board Manager
// ========================================================= // SMART WOMEN SAFETY DEVICE // Uses ESP32 + GPS + GSM to send SOS with location // Built for kids learning robotics! // ========================================================= #include <HardwareSerial.h> // For ESP32 serial ports #include <TinyGPS++.h> // Reads GPS coordinates // ---- Pin Definitions ---- const int PANIC_BTN = 2; // Panic button pin const int BUZZER_PIN = 12; // Buzzer pin const int LED_PIN = 13; // Red LED pin // ---- GPS Setup ---- // GPS uses ESP32's UART1: RX=GPIO4, TX=GPIO5 HardwareSerial gpsSerial(1); TinyGPSPlus gps; // ---- GSM Setup ---- // GSM uses ESP32's UART2: RX=GPIO16, TX=GPIO17 HardwareSerial gsmSerial(2); // ---- TRUSTED PHONE NUMBERS ---- // ⚠️ CHANGE THESE to real trusted numbers! const char* phone1 = "+919876543210"; // Mom/Dad const char* phone2 = "+919123456789"; // Trusted friend const char* phone3 = "+919000000000"; // Family member // ---- Button timing ---- const unsigned long HOLD_TIME = 2000; // Hold 2 seconds unsigned long btnPressTime = 0; bool btnHeld = false; bool sosActive = false; // ========================================================= // SETUP — runs once when ESP32 turns on // ========================================================= void setup() { Serial.begin(115200); // For debugging gpsSerial.begin(9600, SERIAL_8N1, 4, 5); // GPS baud rate gsmSerial.begin(9600, SERIAL_8N1, 16, 17); // GSM baud rate pinMode(PANIC_BTN, INPUT_PULLUP); // Button with internal pull-up pinMode(BUZZER_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT); Serial.println("Safety Device Starting..."); initGSM(); // Wake up the GSM module // Quick startup blink — 3 times = ready for (int i = 0; i < 3; i++) { digitalWrite(LED_PIN, HIGH); delay(200); digitalWrite(LED_PIN, LOW); delay(200); } Serial.println("Device Ready! Press button for 2s to activate SOS."); } // ========================================================= // LOOP — checks button and GPS every moment // ========================================================= void loop() { // Feed GPS data continuously while (gpsSerial.available()) { gps.encode(gpsSerial.read()); } int btnState = digitalRead(PANIC_BTN); // Button pressed (LOW because of pull-up) if (btnState == LOW) { if (!btnHeld) { btnPressTime = millis(); // Start timer btnHeld = true; } // Check if held long enough if (millis() - btnPressTime >= HOLD_TIME && !sosActive) { Serial.println("SOS TRIGGERED!"); sosActive = true; triggerSOS(); } } else { btnHeld = false; } } // ========================================================= // TRIGGER SOS — the main safety action // ========================================================= void triggerSOS() { Serial.println("🚨 SOS Activated!"); // 1. Start alarm — buzzer ON, LED blinking digitalWrite(BUZZER_PIN, HIGH); // 2. Wait for GPS fix (up to 30 seconds) float lat = 0.0, lng = 0.0; unsigned long gpsWait = millis(); while (millis() - gpsWait < 30000) { while (gpsSerial.available()) gps.encode(gpsSerial.read()); // Blink LED while waiting digitalWrite(LED_PIN, (millis() / 300) % 2); if (gps.location.isValid()) { lat = gps.location.lat(); lng = gps.location.lng(); Serial.print("GPS Fix! Lat: "); Serial.print(lat, 6); Serial.print(" Lng: "); Serial.println(lng, 6); break; } } // 3. Build the SMS message String message = "🆘 SOS ALERT! I need help!\n"; if (lat != 0.0) { message += "📍 My Location:\n"; message += "https://maps.google.com/?q="; message += String(lat, 6) + "," + String(lng, 6); message += "\nPlease come quickly!"; } else { message += "GPS signal not found. Please track my phone!"; } // 4. Send SMS to all 3 trusted numbers Serial.println("Sending SMS..."); sendSMS(phone1, message); delay(2000); sendSMS(phone2, message); delay(2000); sendSMS(phone3, message); Serial.println("SMS sent! Alarm will ring for 30 seconds."); // 5. Alarm rings for 30 seconds, then standby delay(30000); digitalWrite(BUZZER_PIN, LOW); digitalWrite(LED_PIN, HIGH); // LED stays ON = SOS sent sosActive = false; } // ========================================================= // SEND SMS using AT Commands // ========================================================= void sendSMS(const char* number, String message) { gsmSerial.println("AT+CMGF=1"); // Set SMS text mode delay(500); gsmSerial.print("AT+CMGS=\""); gsmSerial.print(number); gsmSerial.println("\""); // Enter phone number delay(500); gsmSerial.print(message); // Type the message delay(200); gsmSerial.write(26); // CTRL+Z = send SMS! delay(3000); Serial.print("SMS sent to: "); Serial.println(number); } // ========================================================= // INIT GSM — wake up and configure the SIM800L // ========================================================= void initGSM() { Serial.println("Initialising GSM..."); gsmSerial.println("AT"); // Test communication delay(1000); gsmSerial.println("AT+CMGF=1"); // SMS text mode delay(500); gsmSerial.println("AT+CNMI=1,2,0,0,0"); // SMS notification delay(500); Serial.println("GSM Ready!"); }
SOS Simulator 🎮
See exactly what happens when someone presses the panic button — simulate the SMS and alarm sequence right here!
Press a button below to simulate an event →
Cool upgrades to try 🚀
Once your basic device works perfectly, try adding these features to make it even more powerful!
WhatsApp Alerts
Use Twilio API with ESP32 Wi-Fi to send WhatsApp messages instead of SMS
Live Camera
Add an ESP32-CAM module to automatically take a photo and send it along with the SOS
Wearable Design
Put everything into a small wristband case with a hidden button — like a real smartwatch!
Live Tracking
Build a web dashboard that shows the live moving location on Google Maps in real time
Shake Detection
Add an MPU-6050 accelerometer to automatically trigger SOS if the device senses a fall or struggle
Solar Charging
Add a tiny solar panel to keep the battery charged through the day — no plugging needed!
Comments
Post a Comment