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.
- 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
)
WiFi.h
PubSubClient.h
DHT.h
ArduinoJson.h
Install these via Arduino IDE Library Manager.
- 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
click this Link to direct you to the websiete monitorng repository
void setupWifi()
Connects the ESP32 to the configured Wi-Fi network and prints the local IP address.
void reconnectMQTT()
Attempts to reconnect to the MQTT broker if disconnected, using client ID ESP32Client
.
float readDHTTemperature()
float readDHTHumidity()
Reads values from the DHT22 sensor. Returns 0 if the reading fails.
int readDustSensor()
Triggers the LED inside the dust sensor, reads analog value from dust pin, and calculates concentration.
float convertMQ7(int rawValue)
Converts raw analog value into an estimated CO concentration in ppm using a basic formula.
void publishSensorData(...)
Sends a JSON-formatted payload to the MQTT topic with sensor readings and environment status.
void setOutputs(bool buzzer, bool red, bool yellow, bool green)
Controls the buzzer and LEDs (ON/OFF) based on the condition detected.
void setup()
- Initializes sensors and pin modes.
- Turns on the green LED as default state.
- Connects to Wi-Fi and sets up MQTT.
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.
{
"temperature": 30.5,
"humidity": 45.3,
"dust": 1000,
"co": 80.2,
"air_quality": 900,
"status": "WARNING: Smoke detected"
}
- 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.
This project is open-source and free to use for educational and non-commercial purposes.
Developed by Group 8 - IoT Project 2025