Air Quality Monitoring System using ESP32 and AGS10 (I2C)
Monitoring indoor or outdoor air quality is important for health and smart environments.
This project uses ESP32 and AGS10 sensor via I2C to measure:
- PM2.5 (Particulate Matter)
- CO2 (Carbon Dioxide)
- VOCs (Volatile Organic Compounds)
ESP32 can log the data over Wi-Fi, visualize it on a dashboard, or send alerts if thresholds are exceeded.
Hardware Requirements
- ESP32 Development Board
- AGS10 I2C Sensor Module
- Jumper wires and breadboard
- USB cable for programming
- Optional: OLED display for local readings
Working Principle
I2C Communication:
- AGS10 I2C module connects to ESP32 using SDA/SCL pins.
- ESP32 reads data registers containing PM2.5, CO2, and VOC values.
Data Processing:
- Sensor raw data is converted into meaningful units (µg/m³ for PM2.5, ppm for CO2, ppb for VOCs).
Visualization & Logging:
- Data can be displayed on OLED/LCD or sent to a Wi-Fi dashboard, MQTT broker, or cloud.
Arduino Code Example (I2C)
This example assumes the AGS10 has a default I2C address of 0x58. Adjust if needed.
c
#include <Wire.h>
#define AGS10_ADDR 0x58 // default I2C address
void setup() {
Serial.begin(115200);
Wire.begin(); // ESP32 default: SDA=21, SCL=22
Serial.println("AGS10 Air Quality Monitoring (I2C) Ready");
}
void loop() {
// Request data from AGS10
Wire.beginTransmission(AGS10_ADDR);
Wire.write(0x00); // Command/register to read data (check datasheet)
Wire.endTransmission();
delay(10); // short delay
Wire.requestFrom(AGS10_ADDR, 6); // read 6 bytes (example)
if (Wire.available() == 6) {
uint16_t pm25 = (Wire.read() << 8) | Wire.read();
uint16_t co2 = (Wire.read() << 8) | Wire.read();
uint16_t voc = (Wire.read() << 8) | Wire.read();
Serial.printf("PM2.5: %d µg/m³, CO2: %d ppm, VOC: %d ppb\n", pm25, co2, voc);
}
delay(2000); // read every 2 seconds
}How to Use
Connect the AGS10 I2C to ESP32:
VCC → 3.3V
GND → GND
SDA → GPIO21
SCL → GPIO22
Upload the code to ESP32 and open Serial Monitor.