An embedded systems project built for real-world disaster resilience β inspired by the impact of Cyclone Ditwah (2025) on Sri Lankan households.
SentinelBox is a low-cost, battery-backed embedded system that continuously monitors a household for environmental hazards β floods, fires, gas leaks, earthquakes β and responds automatically with SMS alerts, local alarms, data logging, and a live web dashboard.
It is designed to survive a disaster (not just detect one): the device runs on mains power normally, switches to battery when electricity fails, and keeps logging and alerting throughout.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β POWER ARCHITECTURE β
β Mains 5V βββΊ Bus A: ATmega328P + All Sensors (150mA) β
β βββΊ Bus B: ESP32 + SIM800L (2A peak) β
β LiPo 3.7V βββΊ TP4056 βββΊ Failover on mains loss β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββ Serial (UART) ββββββββββββββββββββββββ
β ATmega328P (Core) β βββββββββββββββββββββββββββΊ β ESP32 (Utility) β
β β β β
β β’ DHT22 Temp/Humid β β β’ NEO-6M GPS β
β β’ Water Level β β β’ SIM800L GSM/GPRS β
β β’ MQ-2 Gas/Smoke β β β’ WiFi Dashboard β
β β’ Flame Sensor β β β’ MQTT Telemetry β
β β’ SW-420 Vibration β β β’ Async Web Server β
β β’ Panic Button β ββββββββββββββββββββββββ
β β’ DS3231 RTC β
β β’ SD Card Logger β
β β’ RGB LED + Buzzer β
β β’ Battery Monitor β
ββββββββββββββββββββββββ
- π‘οΈ Multi-sensor fusion β Temperature, humidity, water level, gas/smoke, flame, vibration, panic button
- π‘ SMS alerts via SIM800L β immediate notification on critical hazard detection
- π GPS location embedded in alerts β Google Maps link in every SMS
- πΎ SD card logging β timestamped CSV rows, survives power loss
- β° DS3231 RTC β accurate timestamps even without internet
- π Battery failover β TP4056 + LiPo, automatic mains/battery switching
- π Live web dashboard β ESP32 async server with SSE real-time push
- π¬ MQTT telemetry β publishes to HiveMQ broker
- π Watchdog + sleep modes β reliable recovery, ultra-low idle power
- π§ Modular codebase β test each module independently before integration
| Branch | Purpose |
|---|---|
main |
Stable, production-ready releases |
dev |
Active development, integration testing |
atmega |
ATmega328P / Mega2560 core controller firmware |
esp32 |
ESP32 utility node firmware |
Development boards: Testing is done on Arduino Mega 2560 (same pin map as ATmega328P for D4βD13, A0βA3). Production target is the bare ATmega328P-PU chip.
sentinelbox/
βββ include/
β βββ config.h β Single config file β edit only this
βββ src/
β βββ atmega/
β β βββ main.cpp β Boot-once, millis() scheduler
β β βββ sensors.cpp/.h β DHT22, water, MQ-2, flame, vibration, panic
β β βββ hazards.cpp/.h β Bitmask detection + text output
β β βββ rtc_time.cpp/.h β DS3231 timestamps
β β βββ storage.cpp/.h β SD card CSV logging
β β βββ gsm.cpp/.h β SIM800L SMS (on ESP32 in production)
β β βββ leds.cpp/.h β RGB LED + async buzzer state machine
β β βββ comms.cpp/.h β ATmega β ESP32 serial protocol
β β βββ power.cpp/.h β Battery ADC, TP4056, WDT, sleep
β βββ esp32/
β βββ gps_parser.cpp/.h β NEO-6M on UART2 via TinyGPSPlus
β βββ uno_link.cpp/.h β ATmega serial link on UART1
β βββ wifi_mqtt.cpp/.h β WiFi + AP fallback + MQTT backoff
β βββ web_server.cpp/.h β Async dashboard with SSE push
βββ test/
β βββ test_sensors/ β Sensor calibration tests
β βββ test_rtc/ β RTC read/write tests
β βββ test_sd/ β SD card write/read tests
β βββ test_gsm/ β SIM800L AT command tests
βββ platformio.ini β Multi-environment build config
[env:mega] β Arduino Mega 2560 (testing)
[env:atmega328p] β Bare ATmega328P chip (production)
[env:esp32] β ESP32 WROOM utility node# Upload to Mega for testing
pio run -e mega -t upload
# Upload to bare ATmega328P via ISP programmer
pio run -e atmega328p -t upload
# Upload to ESP32
pio run -e esp32 -t upload
# Run a specific test module
pio test -e mega -f test_sensors| Pin | Component | Notes |
|---|---|---|
| D4 | DHT22 | Temp/Humidity |
| D5 | SW-420 | Vibration |
| D6 | Buzzer (passive) | PWM tone |
| D7 | RGB LED β Red | |
| D8 | RGB LED β Green | |
| D9 | RGB LED β Blue | |
| D10 | SD Card CS | SPI |
| D2 | SIM800L RX (SoftSerial) | Via voltage divider |
| D3 | SIM800L TX (SoftSerial) | |
| A0 | Water level sensor | |
| A1 | MQ-2 Gas sensor | |
| A2 | Flame sensor | |
| A3 | Panic button | Pull-up |
| A4/SDA | DS3231 RTC | I2C |
| A5/SCL | DS3231 RTC | I2C |
| A6 | Battery voltage | 33kΞ©/10kΞ© divider |
| A7 | TP4056 CHRG pin | LOW = charging |
Mega-specific: SIM800L uses
Serial1(TX1=D18, RX1=D19) instead of SoftwareSerial. Controlled via#ifdef TARGET_MEGAinconfig.h.
| Pin | Component |
|---|---|
| GPIO16 (RX2) | NEO-6M GPS TX |
| GPIO17 (TX2) | NEO-6M GPS RX |
| GPIO4 (RX1) | ATmega TX |
| GPIO5 (TX1) | ATmega RX |
| Component | Purpose | Est. Cost (LKR) |
|---|---|---|
| ATmega328P-PU | Main controller | 350 |
| Arduino Mega 2560 | Development/testing | 1,800 |
| ESP32 WROOM-32 | Utility node | 850 |
| SIM800L EVB | GSM/GPRS alerts | 900 |
| NEO-6M GPS | Location tracking | 750 |
| DHT22 | Temp + Humidity | 350 |
| MQ-2 | Gas/Smoke detection | 250 |
| DS3231 RTC module | Timestamps | 350 |
| Micro SD module | Data logging | 200 |
| SW-420 | Vibration/Earthquake | 80 |
| TP4056 module | Battery charging | 120 |
| 18650 LiPo cell | Battery backup | 400 |
| Total (approx.) | ~13,700 LKR |
git clone https://github.com/Ravindu56/disaster-proof-blackbox-for-houses.git
cd disaster-proof-blackbox-for-houses
git checkout atmega # or dev, esp32Edit include/config.h β set your phone numbers, WiFi credentials, and MQTT broker:
#define SMS_NUMBER_1 "+94XXXXXXXXX"
#define WIFI_SSID "YOUR_SSID"
#define WIFI_PASS "YOUR_PASSWORD"pio run -e mega -t upload # Flash Mega for testing
pio device monitor -e mega # Open serial monitor=============================================
SentinelBox β booting
=============================================
[RTC] OK
[SENS] OK
[SD] OK β log.csv ready
[GSM] init deferred
[BOOT] Complete
TEL,2026-03-22 01:00:21,30.4,75.7,53,142,953,0,0,0,11.98,FULL
EVT,2026-03-22 01:00:21,NORMAL,0.000000,0.000000
GSM init is deliberately deferred 5 seconds after boot to prevent WDT reset loops.
TEL,<timestamp>,<tempC>,<humidity>,<water>,<mq2>,<flame>,<vib>,<panic>,<flags>,<battV>,<battStatus>
EVT,<timestamp>,<hazardText>,<lat>,<lon>
GPS,<lat>,<lon>,<speed_kmh>,<sats>
PING / PONG
CMD,<command>
| Bit | Flag | Trigger |
|---|---|---|
| 0 | FLOOD |
Water > threshold |
| 1 | GAS |
MQ-2 > 450 ADC |
| 2 | FIRE |
Flame < threshold OR Temp > 55Β°C |
| 3 | QUAKE |
Vibration detected |
| 4 | PANIC |
Button pressed |
| 5 | HUMID |
Humidity > 95% |
| 6 | TEMP |
Temperature > 55Β°C |
- Normal operation: Mains 5V β Buck β 3.3V/5V buses
- Mains failure detected:
PIN_TP_CHRGgoes LOW β system logs power event, ESP32 notified - All-clear state: ATmega enters WDT-gated sleep, wakes on vibration INT0 or 8s WDT overflow
- WDT timeout: 8 seconds β
Power::feedWatchdog()called at every loop iteration and inside long blocking operations
Each module has a dedicated test environment. Develop and verify in isolation before integrating:
pio test -e mega -f test_rtc # Verify DS3231 time
pio test -e mega -f test_sd # Verify SD write/read
pio test -e mega -f test_sensors # Calibrate all sensors
pio test -e mega -f test_gsm # AT command walkthroughThis project is developed for EC6020: Embedded Systems Design at the University of Jaffna.
| EC6020 ILO | How SentinelBox addresses it |
|---|---|
| ILO 1 β Embedded system characteristics | Real-time constraints, reactive to environment |
| ILO 2 β Processor selection | ATmega328P chosen over ΞΌP; AVR family analysis |
| ILO 3 β Design metrics | NRE, unit cost (~13,700 LKR), power, time-to-market |
| ILO 4 β Hardware/Software co-design | Sensor drivers, ISR, WDT, sleep modes |
| ILO 5 β Design trade-offs | FPGA vs MCU, GSM on ATmega vs ESP32 analysis |
Reference: Embedded Systems Design: A Unified Hardware/Software Introduction β Vahid & Givargis
Department of Computer Engineering | University of Jaffna
EC6020 Embedded Systems Design β 2025/2026
| Index No. | Name | GitHub |
|---|---|---|
| 2022/E/033 | D.D.R.N. Dayarathna | @Ravindu56 |
| 2022/E/042 | G.D.P.D. Ranasinghe | @Pasinduranasinghe2001 |
| 2022/E/111 | R.M.K.S. Subhasinghe | @sankalpa15388 |
| 2022/E/126 | R.M.Y.S. Malhara | @sasindumal |
| 2022/E/117 | R.A.M.G.T. Chandraweera | @GaviruThejana |
MIT License β see LICENSE for details.
Built to survive what nature throws at us πͺοΈ