π«οΈ Air Quality Monitoring System with ESP32 + Edge ML
A real-time smart air quality monitoring system using ESP32, MQ-135 gas sensor, and DHT11 (temperature/humidity), integrated with an on-device machine-learning classifier and a beautiful live web dashboard.
This project collects sensor data, classifies air quality using a trained ML model, logs data for continuous learning, and displays live readings over WiFi on any browser.
π Features
β Real-time Air Quality Monitoring β Edge Machine Learning on ESP32 (no cloud required) β Web Dashboard accessible from browser β Live updating graph (MQ135 trend) β WiFi connectivity for UI β Local data logging Python script β Retraining pipeline via Jupyter Notebook β Modular firmware architecture β Easily expandable with more sensors β Sensor-fusion ready
π§ System Architecture
MQ-135 β
βββ ESP32 β ML model β Classification β Dashboard
DHT11 β β
ββ Serial Output β Python Logger β CSV
β
ββ Retraining β deploy new model
π Hardware Used
ESP32 Dev Module
MQ-135 Gas Sensor
DHT11 Temperature/Humidity Sensor
USB data cable
Jumper wires
Breadboard
π Wiring Connections MQ135
VCC β 3.3V
GND β GND
AOUT β GPIO 34 (ADC input)
DHT11 (3-pin module recommended)
VCC β 3.3V
DATA β GPIO 4
GND β GND
π§© Software Components Firmware (C++ / Arduino)
AirQualityFirmware.ino
sensors.cpp β reads sensors
classifier.cpp β ML decision logic
wifi_comm.cpp β hosts web dashboard
/data/index.html β UI
Python
log_data.py β logs COM port output to CSV
Machine Learning
training_notebook.ipynb
trains model from:
online datasets
logged sensor data
exports rules as C++ logic for ESP32
π Web Dashboard
Accessible at:
http://<ESP32-IP>
Displays:
Air Quality status with colored indicator
MQ135 gas reading
Temperature (Β°C)
Humidity (%)
Live line graph of gas readings over time
No internet required β local intranet only.
π§ͺ Training the ML Model
Collect real sensor data using:
python log_data.py
Run notebook:
training_notebook.ipynb
ML model retrains based on:
master_log.csv (local real data)
indoor_data.csv (reference dataset)
Export model as decision tree
Insert into classifier.cpp
Upload firmware to ESP32
π Project Structure
AirQualityMonitoringSystem/
β
βββ firmware/
β βββ AirQualityFirmware.ino
β βββ sensors.cpp
β βββ classifier.cpp
β βββ wifi_comm.cpp
β βββ config.h
β βββ data/
β βββ index.html
β βββ style.css
β βββ script.js
β
βββ ML_model/
β βββ training_notebook.ipynb
β βββ model_exported_rules.txt
β
βββ dataset/
β βββ indoor_data.csv
β βββ master_log.csv (ignored in .gitignore)
β
βββ log_data.py
βββ README.md
π§ Machine Learning Concept
Using Decision Tree Classifier:
Predicts AQI label from:
MQ135 raw (gas sensor)
Temperature
Humidity
Example output:
Good
Moderate
Unhealthy
π Getting Started
- Flash ESP32 with firmware
- Open Serial Monitor β check IP
- Open browser:
http://<ESP-IP>
- View live dashboard
- Optionally log data with:
python log_data.py
π§© Future Improvements
Add dust sensor (GP2Y1010)
Add CO sensor (MQ-7)
Add PM2.5 / PM10
Weather API integration
WiFi hotspot mode
Cloud sync + alerts
ESP32 BLE β phone app