Integrated IoT Helmet Accident Detection & Autonomous Emergency Telematics System.
SafeHelm connects embedded physical impact sensing with Android emergency telematics over Bluetooth Low Energy (BLE). When severe impact is detected across distributed helmet zones or when the manual SOS button is pressed, the system coordinates a synchronized 15-second cancellation window across both the helmet hardware and smartphone. If not cancelled, the system autonomously acquires the best available GPS coordinates and dispatches SMS alerts to the rider's designated emergency contacts, tracking exact cell-tower delivery callbacks through a local transactional SQLite journal.
- System Architecture
- Hardware Wiring & Pinout
- Synchronized Emergency Workflow
- Native SQLite Journal & SMS Tracking
- Firmware Setup & Flashing
- Android Setup & Permissions
- Build & Test Verification
- Known Limitations & Safety Disclaimer
flowchart TD
subgraph Helmet["πͺ ESP32 Helmet Firmware"]
FSR["3x Analog FSR Sensors\nLeft: GPIO36 | Right: GPIO39 | Center: GPIO34"] --> Debounce["10ms ADC Sampling & Confirmation Window"]
Debounce --> Vote{"Majority Voting\n(β₯2 zones β₯ Threshold 150?)"}
Vote -- Confirmed --> BLE_Notify["BLE Notification: ACCIDENT\n(Immediately Syncs with Phone)"]
BLE_Notify --> HelmetAlarm["Pulsing Buzzer (GPIO12)\n15s Countdown"]
Btn["Helmet Button (GPIO13)"] -- Press During Countdown --> HelmetCancel["Halt Buzzer & Send CANCEL over BLE"]
Btn -- Long Press When Idle --> ManualSOS["Send MANUAL_SOS over BLE"]
end
subgraph Phone["π± Android Mobile Application"]
BLE_Notify --> NativeJournal["Native SQLite Journal\nIngest Incident: COUNTDOWN"]
NativeJournal --> PrewarmGPS["Pre-warm GPS Acquisition (Background)"]
NativeJournal --> PhoneAlarm["15s Countdown Overlay\nHigh-Priority Siren & Vibrator"]
PhoneAlarm -- Tap 'I'm OK' --> PhoneCancel["Halt Siren, Send CANCEL to Helmet\nUpdate SQLite: CANCELLED"]
HelmetCancel --> PhoneCancel
PhoneAlarm -- 15s Expired --> Dispatch["Update SQLite: DISPATCHING"]
Dispatch --> SendSMS["Android SmsManager + Tracked PendingIntents\nSubmit to RIL"]
SendSMS --> RadioCallback["BroadcastReceiver (ACTION_SMS_SENT)\nCell Tower Success / Radio Failure"]
RadioCallback --> UpdateRecord["Update SQLite Dispatch Status & UI Audit"]
end
SafeHelm uses an ESP32 DevKit (38-pin) with three analog Force Sensitive Resistors (FSR402), an active buzzer driver, and a momentary tactile push button.
| Component | ESP32 GPIO | Electrical Circuit Topology | Function |
|---|---|---|---|
| Left FSR | GPIO 36 (VP) |
3.3V β FSR β GPIO 36 β 1kΞ© Pulldown β GND |
Left temporal impact zone |
| Right FSR | GPIO 39 (VN) |
3.3V β FSR β GPIO 39 β 1kΞ© Pulldown β GND |
Right temporal impact zone |
| Center FSR | GPIO 34 (D34) |
3.3V β FSR β GPIO 34 β 1kΞ© Pulldown β GND |
Crown / forehead impact zone |
| Active Buzzer | GPIO 12 |
GPIO 12 β 1kΞ© Base Resistor β 2N2222A Base Collector β Buzzer - terminal Emitter β GND Buzzer + terminal β 5V VIN 1N4007 Diode across buzzer terminals (Cathode to +5V, Anode to Collector) |
Pre-dispatch audio alarm (flyback diode protects transistor from reverse EMF) |
| Control Button | GPIO 13 |
Button pin 1 β GPIO 13 Button pin 2 β GND Uses internal INPUT_PULLUP (HIGH released, LOW pressed) |
Hardware countdown abort & manual SOS trigger |
- When at least 2 out of 3 FSR sensors exceed the crash threshold (default:
150) within a 50ms confirmation window, the firmware entersCRASH_CONFIRMED. - The firmware immediately transmits an
"ACCIDENT"BLE notification to the smartphone and starts pulsing the helmet buzzer (GPIO 12). - The smartphone immediately ingests the incident into its Native SQLite Journal, triggers a high-priority audio siren and vibration, and displays a full-screen 15-second countdown gauge.
- Simultaneously, the smartphone pre-warms the GPS receiver in the background so that coordinates are ready the moment the timer hits zero.
- From the Helmet: Pressing the helmet button during the 15-second window immediately silences the helmet buzzer, resets firmware state to
MONITORING, and transmits a"CANCEL"event over BLE to cancel the smartphone countdown and siren. - From the Phone: Tapping "I'M OK β CANCEL ALERT" on the smartphone screen immediately stops the siren, writes
"CANCEL"to the helmet's BLE characteristic (halting the helmet buzzer), and marks the incidentCANCELLEDin the SQLite journal and audit history.
- If the 15-second countdown expires without cancellation:
- Phone acquires the best available location fix: Tier 1: High-precision fresh GPS fix (up to 12s budget) β Tier 2: Hardware-cached last-known location β Tier 3: Network/cell tower approximate fix.
- Location coordinates, accuracy (in meters), timestamp, and provenance source are saved to the SQLite incident record.
- Emergency SMS messages are formatted with the rider's name, blood group, medical notes, coordinates, and Google Maps link (
https://maps.google.com/?q=lat,lng). - Messages are sent exclusively to the user's explicitly configured, enabled emergency contacts.
SafeHelm avoids naive assumptions that calling an SMS API means a message was delivered.
DETECTED β COUNTDOWN β LOCATION_ACQUIRED β DISPATCHING β DISPATCHED
β β β
β βββ CANCELLED βββ PARTIAL_FAILURE
β βββ FAILED
βββ QUEUED_OFFLINE βββ QUEUED_OFFLINE
- When SMS dispatch begins, each contact message is divided via
SmsManager.divideMessage(body). - A unique
dispatchId(<incidentId>_<phone>) and dispatch draft record are persisted to SQLite before submitting to telephony. - Tracked
PendingIntents are attached to each message part withACTION_SMS_SENT. - A registered
BroadcastReceiverreceives the actual radio callback from Android Telephony:Activity.RESULT_OK: MarkedSENT_RADIO_CONFIRMEDin SQLite and live event stream.SmsManager.RESULT_ERROR_NO_SERVICE: MarkedRADIO_NO_SERVICE.SmsManager.RESULT_ERROR_RADIO_OFF: MarkedRADIO_RADIO_OFF(airplane mode).SmsManager.RESULT_ERROR_GENERIC_FAILURE: MarkedRADIO_GENERIC_FAILURE.
- Riders can tap any incident in the History tab to inspect recipient-by-recipient status, confirmed parts, and radio result codes.
- PlatformIO Core or PlatformIO VS Code Extension.
- Micro-USB cable connected to the ESP32.
# Navigate to firmware directory
cd firmware
# Compile firmware
pio run
# Flash to connected ESP32
pio run --target upload
# Open serial monitor at 115200 baud
pio device monitor -b 115200- Flutter SDK: 3.20+ (stable channel).
- JDK: Java 17 or Java 21 (Gradle 8.11 / AGP compatible).
- Android Target: SDK 35 (Android 15), minimum SDK 26 (Android 8.0).
SafeHelm requests the following permissions for emergency operation:
android.permission.SEND_SMS: Required to dispatch emergency text messages directly without manual user confirmation in a crash.android.permission.ACCESS_FINE_LOCATION&ACCESS_COARSE_LOCATION: Required to capture GPS coordinates for emergency responders.android.permission.BLUETOOTH_SCAN&BLUETOOTH_CONNECT: Required on Android 12+ (SDK 31+) to pair with the ESP32 helmet over BLE.android.permission.POST_NOTIFICATIONS: Required for foreground service telematics monitoring.android.permission.VIBRATE: Required for high-priority haptic alarm during countdown.
All automated tests have been executed and verified in the environment:
Tests protocol parsing, contact validation, storage persistence, and EmergencyController countdown/cancellation/journal integration:
cd mobile
flutter testResult: 16 of 16 tests passing.
Tests schema creation, WAL mode, foreign keys, transaction rollbacks, state transitions, duplicate incident rejection, and corruption recovery on the JVM:
cd mobile/android
.\gradlew :app:testDebugUnitTestResult: 10 of 10 tests passing (0.89s).
Validates ESP32 FreeRTOS compilation, NimBLE GATT server, 10ms ADC sampling, and JSON serialization:
cd firmware
pio runResult: Flash 46.7%, RAM 11.0%, 0 errors.
cd mobile
flutter build apk --debugResult: app-debug.apk built successfully.
- Academic & Research Prototype: SafeHelm is an experimental engineering research system. It is not a substitute for certified protective headgear meeting DOT (FMVSS 218), ECE 22.06, or SNELL M2020 standards.
- Sensor Scope: The current hardware configuration utilizes three Force Sensitive Resistors (FSRs) to detect direct external compressive force across the helmet shell. It does not detect rotational brain acceleration or high-g freefall without an IMU (accelerometer/gyroscope).
- SMS & Carrier Dependency: Autonomous SMS dispatch requires an active carrier SIM card, sufficient cellular reception, and granted Android runtime permissions. SafeHelm reports
RADIO_NO_SERVICEif cellular towers are unreachable. - Emergency Contact Configuration: SafeHelm alerts are sent exclusively to the rider's explicitly configured emergency contacts. SafeHelm does not automatically dial 911, 112, or public emergency response services.
- No Destructive Crash Testing: Do not strike or crush safety-certified riding helmets for testing. Use the built-in app simulation mode or apply controlled fingertip pressure to test FSR threshold triggers.
Developed by Saifuddin (Saif). Licensed under the MIT License β see LICENSE for details.