Skip to content

Latest commit

Β 

History

History
204 lines (145 loc) Β· 3.59 KB

File metadata and controls

204 lines (145 loc) Β· 3.59 KB

🌫️ 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

  1. Flash ESP32 with firmware
  2. Open Serial Monitor β€” check IP
  3. Open browser:
http://<ESP-IP>
  1. View live dashboard
  2. 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