IoT Fire Detection
Multi-sensor fire detection with a digital twin.
- Started
- Nov 2025
- Stack
- ESP32 · Python · Scikit-Learn · Flask · Dash
01 · Problem
The problem
Most fire alarms react to a single signal, so cooking smoke, steam, a humidity swing or dust can set them off. Frequent false alarms teach people to ignore the real one.
- Classify the room as normal, warning or fire from several signals at once.
- Keep the hardware cheap (a single ESP32-S3) and show the building's state live.
02 · Approach
How it works
- 01Five sensors on one boardAn ESP32-S3 N8R8 reads carbon monoxide (MQ-7), temperature and humidity (DHT22), a 5-channel IR flame sensor, motion (PIR) and light flicker (LDR), using only ADC1 pins because ADC2 conflicts with Wi-Fi.
- 02A model trained on real firesA Random Forest (300 trees, balanced class weights) trained on 367,550 rows from real indoor fire experiments rather than synthetic data.
- 03Safety rules above the modelRule-based overrides sit on top of the ML prediction, so a clear hazard can't be explained away by the classifier.
- 04A live digital twinThe board posts JSON every 2 seconds to a Flask receiver that runs inference and logs to CSV, and a Dash dashboard redraws telemetry, gauges and detection history.
03 · Architecture
Architecture
From five sensors to a live digital twin, every 2 seconds.
- 01Five sensors, one picture
CO, temperature, humidity, flame, motion and light flicker, read together.
- 02ESP32-S3 at the edge
Waits out the MQ-7's 90-second warm-up, then posts a JSON reading every 2 seconds over Wi-Fi.
- 03Flask receives
Each reading is logged to CSV alongside its prediction.
- 04Safety rules, then the forest
Four rules run first and can confirm a fire, keep cooking smoke at normal or flag smouldering as a warning; otherwise the Random Forest's fire / no-fire vote decides.
- 05Digital twin
A Dash dashboard redraws telemetry, gauges and history every 2 seconds.
- 06Alerts, next
A buzzer, relay-driven fan or pump and SIM800L SMS alerts are designed in but not yet automated.
04 · Results
Results
- test accuracy
- 94.93%
- fire recall
- 98%
- no-fire precision
- 99%
- rows of real sensor data in the training set
- 367,550
- PM2.5 / smoke proxy46.6%
- H₂ / CO proxy26.6%
- CO (MQ-7 reading)13.8%
- Temperature6.8%
- Humidity6.2%
05 · Next
Taking it off the bench
- 01The model was trained on lab datasets, so the next step is to collect labelled readings from this hardware and retrain on them.
- 02Its most important feature is a smoke/PM2.5 reading, so the PMS7003 particulate sensor is the next one to integrate.
- 03Automate the response: buzzer, relay-driven fan or pump, and SIM800L SMS alerts.