Skip to content
All projects
HARDWARE/MLIoT + ML · hardware prototype

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.

MQ-7carbon monoxideDHT22temp + humidityIR FLAME5-channelPIRmotion contextLDRflicker signatureESP32-S3JSON every 2 sFLASKreceiver + CSV logRANDOM FOREST300 treesSAFETY RULESoverride the MLDIGITAL TWINDash dashboardALERTSbuzzer · SMS (next)
  1. 01
    Five sensors, one picture

    CO, temperature, humidity, flame, motion and light flicker, read together.

  2. 02
    ESP32-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.

  3. 03
    Flask receives

    Each reading is logged to CSV alongside its prediction.

  4. 04
    Safety 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.

  5. 05
    Digital twin

    A Dash dashboard redraws telemetry, gauges and history every 2 seconds.

  6. 06
    Alerts, 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
What the model relies onRandom Forest feature importance (%).
  • 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.
Next case studyRoad Scene SegmentationPixel-level perception for autonomous driving.