Skip to content

IoT-based environmental monitoring system using an ESP32 microcontroller. It integrates sensors for temperature, humidity, smoke, carbon monoxide (CO), and dust.

Notifications You must be signed in to change notification settings

JordyMail/Fire-and-Smoke-Detection-ESP32

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 

Repository files navigation

IoT Environmental Monitoring System with Fire and Smoke Detection (ESP32)

Project Benefits

This project is an IoT-based environmental monitoring system using an ESP32 microcontroller. It integrates sensors for temperature, humidity, smoke, carbon monoxide (CO), and dust to:

  • Detect potential fire or smoke hazards in real-time.
  • Provide alerts through a buzzer and indicator LEDs.
  • Send sensor data to an MQTT broker for remote monitoring.
  • Improve safety and air quality awareness in homes, offices, warehouses, or labs.

Hardware Requirements

  • ESP32 (microcontroller)
  • DHT22 (temperature & humidity sensor)
  • MQ7 (carbon monoxide sensor)
  • MQ135 (air quality / smoke sensor)
  • Dust sensor (optical-based)
  • Buzzer, Red/Yellow/Green LEDs
  • Wi-Fi connection
  • MQTT Broker (e.g., broker.emqx.io)

Required Libraries

  • WiFi.h
  • PubSubClient.h
  • DHT.h
  • ArduinoJson.h

Install these via Arduino IDE Library Manager.


Configuration

  • Wi-Fi SSID: Your-Wifi-name, example: jo-wifi
  • Password: Your-passowrd-name, example: 123
  • MQTT Broker: broker.emqx.io
  • Port: 1883
  • MQTT Topic: example: IoT/group8

Monitoring Web

click this Link to direct you to the websiete monitorng repository

Sensor Design

CIRCUIT SMOKING DETECTION FIXXXX

Code Overview

WiFi Setup

void setupWifi()

Connects the ESP32 to the configured Wi-Fi network and prints the local IP address.


MQTT Reconnection

void reconnectMQTT()

Attempts to reconnect to the MQTT broker if disconnected, using client ID ESP32Client.


Read Temperature & Humidity

float readDHTTemperature()
float readDHTHumidity()

Reads values from the DHT22 sensor. Returns 0 if the reading fails.


Dust Sensor Reading

int readDustSensor()

Triggers the LED inside the dust sensor, reads analog value from dust pin, and calculates concentration.


CO Conversion (MQ7)

float convertMQ7(int rawValue)

Converts raw analog value into an estimated CO concentration in ppm using a basic formula.


MQTT Publish

void publishSensorData(...)

Sends a JSON-formatted payload to the MQTT topic with sensor readings and environment status.


Output Control

void setOutputs(bool buzzer, bool red, bool yellow, bool green)

Controls the buzzer and LEDs (ON/OFF) based on the condition detected.


Setup

void setup()
  • Initializes sensors and pin modes.
  • Turns on the green LED as default state.
  • Connects to Wi-Fi and sets up MQTT.

Main Loop

void loop()
  • Reads all sensor data.

  • Evaluates the following conditions:

    • 🔴 FIRE DETECTED: MQ135 > 1800, Temp > 45°C, Dust > 2000, Humidity < 30%
    • 🟡 SMOKE DETECTED: MQ135 > 800 and CO > 50 ppm
    • 🟢 NORMAL: All values within safe range
  • Controls outputs and sends data via MQTT every second.


Example JSON Payload

{
  "temperature": 30.5,
  "humidity": 45.3,
  "dust": 1000,
  "co": 80.2,
  "air_quality": 900,
  "status": "WARNING: Smoke detected"
}

Notes

  • For accurate CO measurement, calibrate the MQ7 sensor’s R0 resistance value.
  • MQTT data can be visualized using tools like Node-RED, ThingsBoard, or custom dashboards.
  • Can be extended with cloud logging or mobile notifications.

License

This project is open-source and free to use for educational and non-commercial purposes.


Contributors

Developed by Group 8 - IoT Project 2025

Hotel Room Design 1 (700cm x 320cm)



About

IoT-based environmental monitoring system using an ESP32 microcontroller. It integrates sensors for temperature, humidity, smoke, carbon monoxide (CO), and dust.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages