A complete end-to-end IoT air quality monitoring system built using ESP32, MicroPython, and Flask to measure real-time AQI from multiple gas sensors and display it live on an OLED screen.
This project collects real-time air quality data from multiple sensors connected to an ESP32, sends it to a Flask backend which calculates the Air Quality Index (AQI), and displays the result live on an SSD1306 OLED screen along with temperature and humidity.
- Real-time AQI calculation from multiple gas sensors
- Temperature & Humidity monitoring (DHT11)
- Live OLED display (AQI, Status, Temp, Humidity)
- Flask backend for AQI computation
- WiFi-based HTTP communication (ESP32 → Server)
- AQI Status: Good / Moderate / Unhealthy / Hazardous
- ESP32
- MQ-135 (NO / NOx)
- MQ-7 (CO)
- GP2Y1010AU0F (PM2.5 Dust Sensor)
- DHT11 (Temperature & Humidity)
- SSD1306 OLED Display (128x64, I2C)
- MicroPython (ESP32)
- Python (Flask Backend)
- ESP32 reads sensor values from MQ-135, MQ-7, and PM2.5 sensor
- Data is sent to Flask server via HTTP POST as JSON
- Flask backend:
- Converts raw ADC values to AQI-friendly units
- Calculates overall AQI
- Returns AQI value + status
- ESP32 displays AQI, status, temperature & humidity on OLED
Endpoint: POST /predict
Request:
{
"no": 1024,
"co": 860,
"nox": 1024,
"pm25": 0.85
}Response:
{
"predicted_aqi": 104.5,
"status": "Unhealthy"
}| Sensor | ESP32 Pin | Description |
|---|---|---|
| MQ-135 (AO) | GPIO 34 | NO / NOx analog value |
| MQ-7 (AO) | GPIO 33 | CO analog value |
| PM2.5 Analog Out | GPIO 35 | Dust sensor analog |
| PM2.5 LED Control | GPIO 4 | Pulse LED for PM sensor |
| DHT11 Data | GPIO 27 | Temp & Humidity |
| OLED SDA | GPIO 21 | I2C Data |
| OLED SCL | GPIO 22 | I2C Clock |
pip install flask
python app.py- Flash MicroPython on ESP32
- Upload
main.pyandssd1306.py - Update
SSID,PASSWORD, andSERVER_URLinmain.py - Reset the board
| AQI Range | Status |
|---|---|
| 0 – 50 | Good |
| 51 – 100 | Moderate |
| 101 – 200 | Unhealthy |
| 201+ | Hazardous |
- Cloud deployment (Firebase / AWS)
- Mobile dashboard
- Alert notifications (Email / WhatsApp)
- Data logging & graphs
Kritish Mohapatra
B.Tech Electrical Engineering (3rd Year)
IoT | Embedded Systems | MicroPython | ESP32
If you like this project, give it a ⭐ on GitHub and feel free to fork it!
Happy hacking 🚀
