Sunday, 31 May 2026

AI-Based Real-Time Air Pollution Monitoring and Prediction

AI-Based Real-Time Air Pollution Monitoring and Prediction System ESP32 + AI Agent + IoT Cloud + n8n Automation + Telegram Voice Alerts + Google Sheets + ThingSpeak Dashboard
AI-Based Real-Time Air Pollution Monitoring and Prediction System Project Overview This project develops an AI-Powered Real-Time Air Pollution Monitoring and Prediction System using ESP32, environmental sensors, Agentic AI Analytics, n8n Automation, Telegram Voice Alerts, Google Sheets Logging, and ThingSpeak Cloud Dashboard. The system continuously monitors air quality parameters, predicts future pollution trends using AI models, and automatically sends intelligent alerts when pollution levels exceed safe limits. Main Features Real-Time Monitoring Air Quality Index (AQI) PM2.5 Concentration PM10 Concentration Carbon Monoxide (CO) Carbon Dioxide (CO₂) Smoke Detection Temperature Humidity AI Analytics AQI Prediction Pollution Trend Analysis Risk Classification Anomaly Detection Power Consumption Forecasting Cloud Integration ThingSpeak Dashboard Google Sheets Database Telegram Notifications AI Agent Monitoring Interface Automation n8n Workflow Voice Alerts Automatic Data Logging AI Recommendations System Architecture Air Sensors │ ▼ ESP32 Controller │ WiFi Internet │ ▼ ThingSpeak Cloud │ ▼ n8n Workflow Engine │ ┌───┼─────────────┐ ▼ ▼ ▼ AI Agent Google Sheets Analysis Database │ ▼ Telegram Bot (Text + Voice Alerts) Components Required Component Quantity ESP32 Dev Board 1 MQ135 Air Quality Sensor 1 PMS5003 PM2.5 Sensor 1 DHT22 Temperature Sensor 1 OLED Display 0.96" 1 Buzzer Module 1 LED Indicators 3 Breadboard 1 Jumper Wires As Required 5V Power Supply 1 WiFi Internet Connection 1 Sensor Functions MQ135 Measures: CO₂ Smoke Air Quality Output Clean Air : < 200 Moderate Air : 200-400 Poor Air : > 400 PMS5003 Measures: PM1.0 PM2.5 PM10 Used for AQI calculation. DHT22 Measures: Temperature Humidity Environmental compensation. Circuit Connections MQ135 MQ135 → ESP32 VCC → 5V GND → GND AO → GPIO34 DHT22 DHT22 → ESP32 VCC → 3.3V GND → GND DATA → GPIO4 PMS5003 PMS5003 → ESP32 VCC → 5V GND → GND TX → GPIO16 (RX2) RX → GPIO17 (TX2) OLED Display OLED → ESP32 VCC → 3.3V GND → GND SDA → GPIO21 SCL → GPIO22 Buzzer Positive → GPIO27 Negative → GND Circuit Schematic +-------------------+ | ESP32 | | | MQ135 --->| GPIO34 | DHT22 --->| GPIO4 | PMS TX -->| GPIO16 | PMS RX -->| GPIO17 | OLED SDA->| GPIO21 | OLED SCL->| GPIO22 | BUZZER -->| GPIO27 | +-------------------+ Flowchart Start │ Initialize Sensors │ Connect WiFi │ Read Sensor Values │ Calculate AQI │ Upload ThingSpeak │ Store Google Sheets │ AI Prediction │ Check Threshold │ Send Telegram Alert │ Generate Voice Message │ Repeat AQI Prediction Logic Inputs PM2.5 PM10 CO2 Temperature Humidity AI Formula Predicted AQI AQI Future = 0.5 × PM2.5 + 0.3 × PM10 + 0.1 × CO2 + 0.1 × Temperature Classification AQI Status 0-50 Good 51-100 Moderate 101-150 Unhealthy 151-200 Very Unhealthy >200 Hazardous ESP32 Source Code Structure Required Libraries WiFi.h HTTPClient.h DHT.h ThingSpeak.h ArduinoJson.h WiFi Setup const char* ssid = "YOUR_WIFI"; const char* password = "PASSWORD"; ThingSpeak Setup unsigned long channelID = XXXXX; const char* writeAPIKey = "WRITE_KEY"; Sensor Reading Function float temperature = dht.readTemperature(); float humidity = dht.readHumidity(); int mq135 = analogRead(34); float pm25 = getPM25(); float pm10 = getPM10(); AQI Calculation float AQI = (pm25*0.5) + (pm10*0.3) + (mq135*0.2); Upload to ThingSpeak ThingSpeak.setField(1, pm25); ThingSpeak.setField(2, pm10); ThingSpeak.setField(3, AQI); ThingSpeak.writeFields( channelID, writeAPIKey ); ThingSpeak Dashboard Setup Create Channel Fields: Field1 = PM2.5 Field2 = PM10 Field3 = AQI Field4 = CO2 Field5 = Temperature Field6 = Humidity Dashboard Widgets AQI Gauge PM2.5 Graph PM10 Graph Temperature Graph Humidity Graph Pollution Heatmap Google Sheets Integration Create Sheet Timestamp PM2.5 PM10 AQI Temperature Humidity Status n8n Webhook Receives { "pm25": 35, "pm10": 55, "aqi": 92, "temp": 30, "humidity": 70 } Append Row Node Automatically stores every reading. n8n Workflow Workflow Steps Webhook Trigger │ ▼ Data Validation │ ▼ AI Agent Analysis │ ▼ Google Sheets │ ▼ Threshold Check │ ▼ Telegram Message │ ▼ Telegram Voice Alert Sample n8n Workflow JSON Structure { "nodes":[ { "name":"Webhook" }, { "name":"Google Sheets" }, { "name":"Telegram" } ] } Telegram Bot Setup Step 1 Open Telegram Search: @BotFather Step 2 Create Bot /newbot Step 3 Copy Token 123456:ABCDEF Step 4 Get Chat ID https://api.telegram.org/botTOKEN/getUpdates Telegram Alert Message 🚨 Air Pollution Alert AQI: 175 Status: Very Unhealthy PM2.5: 120 PM10: 180 Recommendation: Wear mask and avoid outdoor activities. Voice Notification Automation n8n Process AQI > 150 │ Generate Text │ Text-to-Speech │ Telegram Voice Message Voice Message Example Warning. Air quality is unhealthy. AQI has reached one hundred seventy five. Avoid outdoor activities. AI Agent Analytics The AI Agent continuously evaluates: Pollution Trend Increasing Stable Decreasing Health Risk Low Risk Medium Risk High Risk Prediction Horizon 1 Hour 6 Hours 24 Hours Recommendations Wear Mask Close Windows Avoid Outdoor Exercise Use Air Purifier Power Consumption Prediction Data Used WiFi Usage Sensor Sampling Rate OLED ON Time Cloud Upload Frequency Simple Model Power = ESP32 Current + Sensor Current + Display Current Predicted Daily Usage 0.8 to 1.5 Wh/day IoT Web Dashboard Features Live Monitoring Current AQI PM2.5 PM10 CO2 Temperature Humidity AI Panel Future AQI Pollution Forecast Risk Level Recommendations Alert Panel Last Alert Voice Alert History Telegram Logs Future Enhancements Machine Learning Random Forest AQI Prediction LSTM Time-Series Forecasting XGBoost Prediction Models Advanced Sensors SDS011 BME680 CCS811 SGP30 Mobile App Flutter Dashboard Push Notifications Live Maps Smart City Integration Multiple ESP32 Nodes Central Cloud Server GIS Pollution Mapping Deployment Guide Indoor Installation Schools Hospitals Offices Laboratories Outdoor Installation Traffic Junctions Industrial Zones Smart Cities Construction Sites Final Outcome This project creates a complete Industry 4.0 AI-Powered Air Pollution Monitoring Platform combining: ✅ ESP32 IoT Monitoring ✅ Real-Time AQI Calculation ✅ AI Agent Analytics ✅ n8n Workflow Automation ✅ Google Sheets Database ✅ Telegram Text Alerts ✅ Telegram Voice Notifications ✅ ThingSpeak Cloud Dashboard ✅ Pollution Forecasting ✅ Power Consumption Prediction ✅ Cloud-Based Monitoring ✅ Smart City Ready Architecture ✅ Environmental Safety Intelligence System The result is a scalable, low-cost, AI-enabled environmental monitoring solution capable of detecting pollution in real time, predicting future air-quality conditions, and automatically notifying users through cloud dashboards and voice alerts.

No comments:

Post a Comment

AI-Based Real-Time Air Pollution Monitoring and Prediction

AI-Based Real-Time Air Pollution Monitoring and Prediction System ESP32 + AI Agent + IoT Cloud + n8n Automation + Telegram Voice Alerts + Go...