Sunday, 16 August 2026

AI Air Pollution Monitoring and Prediction System

AI Air Pollution Monitoring and Prediction System — Full Project Description

This project is an AI-powered IoT air pollution monitoring, prediction, and automated alert system built using ESP32, environmental sensors, n8n workflow automation, an AI Agent, Telegram, Google Sheets, ThingSpeak, and a web/cloud dashboard.

The system continuously measures air-quality parameters through sensors connected to an ESP32 microcontroller, sends the collected data to the cloud, analyzes the measurements using AI, stores historical records, predicts possible pollution trends, and automatically sends Telegram notifications and voice alerts when pollution reaches dangerous levels.

1. Project Objective

The main objective is to develop a smart, low-cost, real-time air-pollution monitoring system that can:

  • Continuously monitor air-quality parameters.
  • Collect sensor data using ESP32.
  • Upload measurements to a cloud platform.
  • Display live and historical data on a dashboard.
  • Store data automatically in Google Sheets.
  • Use AI to analyze pollution conditions.
  • Predict increasing or decreasing pollution trends.
  • Automatically trigger alerts when predefined thresholds are exceeded.
  • Send Telegram text and voice notifications.
  • Use an AI Agent to make intelligent decisions based on sensor data.
  • Automate the complete workflow using n8n.

This creates an agentic IoT architecture, where the ESP32 collects physical-world data and the AI/automation layer interprets that data and takes appropriate actions.


2. System Architecture

The overall system can be represented as:

Air Pollution Sensors → ESP32 → Internet/Wi-Fi → n8n → AI Agent → Database/Google Sheets/ThingSpeak → Dashboard → Telegram Alerts

A more detailed flow is:

┌──────────────────────┐
│ Air Quality Sensors │
│ PM2.5 / PM10 / Gas │
│ Temp / Humidity etc. │
└──────────┬───────────┘
┌──────────────────────┐
│ ESP32 │
│ Sensor Data Collector│
│ Wi-Fi Connectivity │
└──────────┬───────────┘
Internet/Wi-Fi
┌──────────────────────┐
│ n8n │
│ Workflow Automation │
└──────────┬───────────┘
┌──────────────────────┐
│ AI Agent │
│ Analysis & Prediction│
│ Decision Making │
└──────┬───────┬───────┘
│ │
┌─────────────┘ └──────────────┐
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ ThingSpeak │ │ Google Sheets │
│ Cloud Monitoring │ │ Historical Data │
└────────┬─────────┘ └──────────────────┘
┌──────────────────┐
│ Web Dashboard │
│ Live AQ Data │
│ Graphs & Trends │
└──────────────────┘
AI Decision
┌──────────────────┐
│ Telegram Bot │
│ Text Notification│
│ Voice Alert │
└──────────────────┘

3. Hardware Components

ESP32

The ESP32 acts as the main IoT controller. It reads the sensor values, processes the measurements, connects to Wi-Fi, and transmits the information to the cloud/automation system.

Typical responsibilities include:

  • Reading sensor data.
  • Basic sensor-data validation.
  • Wi-Fi connectivity.
  • Sending data using HTTP/MQTT/API.
  • Periodic data transmission.
  • Handling connection failures.
  • Generating timestamps or device IDs.

Air Quality Sensors

Depending on the project implementation, different sensors can be used.

Possible parameters include:

Parameter Example Sensor
PM2.5 PMS5003 / SDS011
PM10 PMS5003 / SDS011
CO₂ MH-Z19B / SCD30
CO MQ-7
Air-quality gases MQ-series sensors
Temperature DHT22 / BME280
Humidity DHT22 / BME280
Pressure BMP280 / BME280

For a serious air-quality project, calibrated particulate and gas sensors are preferable to relying exclusively on inexpensive MQ-series sensors.


4. ESP32 Data Collection

The ESP32 periodically collects readings from the connected sensors.

Example data:

Device ID: ESP32_AQI_01
Temperature: 31.4 °C
Humidity: 68 %
PM2.5: 48 µg/m³
PM10: 91 µg/m³
CO2: 870 ppm
Timestamp: 2026-08-16 15:30:00

The ESP32 packages the readings into a structured payload such as:

{
"device_id": "ESP32_AQI_01",
"temperature": 31.4,
"humidity": 68,
"pm25": 48,
"pm10": 91,
"co2": 870
}

The payload is then transmitted over Wi-Fi.


5. n8n Automation

n8n acts as the central automation and integration layer.

Instead of manually checking sensor readings, n8n automatically receives the ESP32 data and performs a sequence of operations.

A typical workflow is:

ESP32
Webhook/API
Validate Sensor Data
Store Data
AI Agent
Analyze Pollution
Predict Trend
Check Threshold
┌───────────────┐
│ │
Normal Dangerous
│ │
▼ ▼
Store Telegram Alert
Data + Voice Alert

n8n can connect the ESP32 system with:

  • Webhooks
  • HTTP APIs
  • AI models
  • Google Sheets
  • ThingSpeak
  • Telegram
  • Databases
  • Notification services
  • Custom web applications

6. AI Agent

The AI Agent is one of the most important parts of the project.

Instead of simply applying fixed IF/ELSE rules, the AI layer can analyze multiple sensor values together and provide a more meaningful interpretation.

For example:

PM2.5 = 82
PM10 = 140
CO2 = 1250
Humidity = 75%
Temperature = 34°C

The AI Agent can determine that the overall condition indicates poor air quality and recommend an action such as sending an immediate warning.

The AI Agent can be designed to:

  1. Analyze current sensor readings.
  2. Compare measurements against configured limits.
  3. Examine recent historical readings.
  4. Identify increasing pollution trends.
  5. Classify air quality.
  6. Generate a human-readable explanation.
  7. Decide whether an alert is necessary.
  8. Generate an alert message.
  9. Trigger downstream automation.

7. AI-Based Pollution Prediction

The system can go beyond monitoring and implement pollution prediction.

Historical measurements are collected continuously and used to identify trends.

For example:

10:00 → PM2.5 = 32
10:10 → PM2.5 = 39
10:20 → PM2.5 = 47
10:30 → PM2.5 = 59
10:40 → PM2.5 = 71

The system recognizes that PM2.5 is increasing rapidly.

The AI layer can generate an interpretation such as:

Pollution levels are increasing rapidly and may reach an unhealthy range if the current trend continues.

Prediction can be implemented using:

  • Statistical trend analysis
  • Moving averages
  • Regression
  • Time-series models
  • Machine-learning models
  • AI-assisted interpretation

For a more advanced version, historical data can be used to train a dedicated prediction model.


8. Google Sheets Integration

Google Sheets provides a simple historical database for the project.

Each measurement can automatically create a new row:

Timestamp Device PM2.5 PM10 CO₂ Temp Humidity Status
15:00 ESP32-01 32 61 720 30.2 62 Good
15:10 ESP32-01 41 75 810 30.8 64 Moderate
15:20 ESP32-01 59 103 980 31.2 67 Poor

This provides an inexpensive historical data store and makes it easy to:

  • Analyze pollution trends.
  • Create reports.
  • Export data.
  • Build graphs.
  • Train prediction models.
  • Maintain a project log.

9. ThingSpeak Cloud Dashboard

ThingSpeak can be used as an IoT cloud visualization platform.

ESP32 sensor measurements can be published to individual channels/fields.

Example:

Field 1 → PM2.5
Field 2 → PM10
Field 3 → CO2
Field 4 → Temperature
Field 5 → Humidity
Field 6 → AQI

The dashboard can show:

  • Live sensor values.
  • Historical graphs.
  • Pollution trends.
  • Temperature variation.
  • Humidity variation.
  • PM2.5/PM10 trends.
  • AQI trends.

This provides a convenient cloud-based monitoring interface.


10. Webpage / IoT Dashboard

A dedicated webpage can provide a user-friendly interface for monitoring the system.

The dashboard can contain:

Live Monitoring

┌─────────────────────────────────┐
│ AIR QUALITY MONITOR │
├─────────────────────────────────┤
│ PM2.5 48 µg/m³ │
│ PM10 91 µg/m³ │
│ CO₂ 870 ppm │
│ Temperature 31.4 °C │
│ Humidity 68 % │
│ │
│ Status: ⚠ POOR │
└─────────────────────────────────┘

Additional dashboard features

  • Real-time sensor cards.
  • Interactive graphs.
  • Historical pollution charts.
  • Device status.
  • Last update time.
  • AQI indicator.
  • Pollution prediction.
  • Alert history.
  • AI-generated recommendations.
  • Multiple ESP32 device support.

11. Telegram Notification System

Telegram provides the real-time notification mechanism.

When the AI Agent determines that pollution has reached a dangerous level, n8n automatically sends a Telegram message.

Example:

🚨 AIR QUALITY ALERT
Device: ESP32_AQI_01
PM2.5: 82 µg/m³
PM10: 146 µg/m³
CO₂: 1250 ppm
Temperature: 34°C
Humidity: 74%
Status: UNHEALTHY
⚠ Pollution levels are increasing.
Recommended action: Reduce outdoor exposure
and investigate the pollution source.

12. Telegram Voice Alerts

A major feature of the project is voice-based alerting.

Instead of sending only text, the automation workflow can generate a spoken alert.

The workflow can be:

Sensor Data
AI Agent
Danger Detected
Generate Alert Text
Text-to-Speech
Generate Audio
Telegram Bot
Voice Message

For example, the user could receive a voice notification saying:

"Warning. Air pollution levels are currently unhealthy. PM2.5 concentration is increasing. Please reduce outdoor exposure."

This makes the system more useful for immediate alerts, especially when the user is not actively looking at the dashboard.


13. Agentic IoT Concept

The project can be described as an Agentic IoT system because the system does not merely collect and display sensor data.

It follows a continuous:

Sense → Analyze → Decide → Act → Learn/Record

cycle.

Sense

ESP32 collects environmental data.

Analyze

The AI Agent analyzes the measurements.

Decide

The system determines whether the current situation requires action.

Act

n8n executes the appropriate workflow:

  • Store data.
  • Update dashboard.
  • Send Telegram notification.
  • Generate voice alert.
  • Trigger additional actions.

Learn / Historical Analysis

Historical data can be retained for future prediction and trend analysis.


14. Example Intelligent Workflow

Consider the following scenario.

The ESP32 detects:

PM2.5 = 95
PM10 = 175
CO₂ = 1380
Temperature = 35°C
Humidity = 76%

The ESP32 sends the data to n8n.

n8n validates the data and sends it to the AI Agent.

The AI Agent analyzes the current measurements and historical trend.

It determines:

Current condition: Unhealthy
Pollution trend: Increasing
Alert required: YES
Priority: HIGH

n8n then automatically:

  1. Stores the measurement in Google Sheets.
  2. Updates ThingSpeak.
  3. Updates the web dashboard.
  4. Generates an alert message.
  5. Generates a voice notification.
  6. Sends the voice message through Telegram.
  7. Records the alert event.

No manual intervention is required.


15. Fault Detection

The system can also monitor the ESP32 and sensors themselves.

For example, if the ESP32 stops transmitting:

Last update: 30 minutes ago
Device status: OFFLINE

n8n can automatically send:

⚠ DEVICE OFFLINE
ESP32_AQI_01 has not transmitted
sensor data for 30 minutes.
Please check the device,
power supply, or Wi-Fi connection.

This makes the system more reliable.


16. Security Considerations

Because the ESP32 communicates with cloud services, security should be considered.

Recommended features include:

  • HTTPS communication.
  • API authentication.
  • Secure Wi-Fi configuration.
  • Unique device IDs.
  • Protected webhook endpoints.
  • Secure storage of API keys.
  • n8n credential management.
  • Telegram bot-token protection.
  • Input validation.
  • Rate limiting.
  • Avoiding hard-coded credentials in public firmware.

17. Complete End-to-End Workflow

The complete system can be summarized as:

ENVIRONMENT
┌─────────────────┐
│ Air Quality │
│ Sensors │
└────────┬────────┘
┌─────────────────┐
│ ESP32 │
│ IoT Controller │
└────────┬────────┘
│ Wi-Fi
┌─────────────────┐
│ n8n Webhook/API │
└────────┬────────┘
┌─────────────────┐
│ Data Validation │
└────────┬────────┘
┌─────┴─────┐
▼ ▼
Google Sheets ThingSpeak
│ │
└─────┬─────┘
┌───────────┐
│ AI Agent │
└─────┬─────┘
┌─────┴──────────┐
▼ ▼
Prediction Alert Decision
│ │
▼ ▼
Web Dashboard Telegram Bot
┌────┴────┐
▼ ▼
Text Voice
Alert Alert

18. Major Features

Hardware

  • ESP32-based IoT controller.
  • Air-quality sensors.
  • Temperature and humidity monitoring.
  • Wi-Fi connectivity.
  • Continuous data acquisition.

Cloud & Automation

  • n8n workflow automation.
  • Webhook/API communication.
  • Google Sheets data logging.
  • ThingSpeak cloud visualization.
  • Automated processing.

AI

  • AI-powered pollution analysis.
  • Pollution classification.
  • Trend detection.
  • Short-term prediction.
  • Intelligent alert decisions.
  • AI-generated recommendations.

Notifications

  • Telegram notifications.
  • Telegram voice alerts.
  • High-pollution warnings.
  • Device-offline notifications.
  • Automated alert messages.

Dashboard

  • Live sensor readings.
  • Historical graphs.
  • AQI/pollution status.
  • Prediction display.
  • Device health.
  • Alert history.

19. Advantages

The proposed system provides several advantages over a conventional IoT monitoring system:

  1. Real-time monitoring — environmental conditions can be monitored continuously.
  2. Remote access — data can be viewed from anywhere with Internet access.
  3. Automation — n8n eliminates repetitive manual operations.
  4. AI intelligence — the system can interpret sensor data instead of simply displaying numbers.
  5. Prediction — historical trends can be used to anticipate worsening pollution.
  6. Immediate alerts — Telegram notifications can be delivered automatically.
  7. Voice notifications — critical events can be communicated through audio.
  8. Historical records — Google Sheets provides easily accessible data storage.
  9. Cloud visualization — ThingSpeak provides IoT-oriented graphs and monitoring.
  10. Scalability — additional ESP32 devices and sensors can be incorporated.
  11. Low cost — ESP32-based hardware makes prototyping relatively inexpensive.
  12. Agentic architecture — the system can sense, reason, and take automated actions.

20. Future Enhancements

The project can be expanded into a more advanced smart-city environmental platform.

Possible improvements include:

  • Multiple ESP32 sensor stations.
  • GPS-based pollution mapping.
  • City-wide pollution heatmaps.
  • Weather API integration.
  • Wind-speed and wind-direction analysis.
  • Advanced machine-learning prediction.
  • Anomaly detection.
  • Automatic sensor calibration.
  • Mobile application.
  • Voice-based user interaction with the AI Agent.
  • Automatic generation of daily pollution reports.
  • SMS/email emergency notifications.
  • Integration with smart-home systems.
  • Automatic ventilation control.
  • Solar-powered ESP32 stations.
  • Edge AI processing directly on ESP32 or an edge gateway.

21. Project Outcome

The final system becomes a complete AI-enabled environmental IoT platform rather than a simple sensor-monitoring project.

It combines:

ESP32 + Air Quality Sensors + IoT + n8n + AI Agent + Google Sheets + ThingSpeak + Web Dashboard + Telegram + Voice Alerts

to create an automated pipeline:

Sense → Send → Store → Analyze → Predict → Decide → Alert → Visualize

The key innovation is the integration of Agentic AI with IoT automation. The ESP32 provides real-world environmental observations, while the AI and n8n automation layer converts those observations into intelligent decisions and automated actions. This makes the project suitable as an IoT, AI, automation, environmental monitoring, smart-city, or final-year engineering project.

No comments:

Post a Comment