← Back to IoT Blog
DIY Projects 25 min read

Home Air Quality Monitor

Build a comprehensive air quality monitor. Track PM2.5, CO2, VOC, temperature, and humidity with ESP32 and cloud dashboard for healthy indoor air.

Why Monitor Air Quality?

Indoor air can be 2-5x more polluted than outdoor air. Monitoring helps identify issues and improve health.

Key Pollutants:
  • PM2.5: Fine particles (<2.5Ξm) from cooking, smoking
  • CO2: Ventilation indicator (>1000ppm = poor)
  • VOC: Volatile compounds from cleaners, paints
  • Formaldehyde: Off-gassing from furniture

Air Quality Sensors

Hardware Setup

ESP32 → PMS5003 (Particle Sensor)
5V → 5V, GND → GND
TX → GPIO17, RX → GPIO16

ESP32 → SCD30 (CO2 Sensor)
3.3V → 3.3V, GND → GND
SDA → GPIO21, SCL → GPIO22

ESP32 → OLED Display
VCC → 3.3V, GND → GND
SDA → GPIO21, SCL → GPIO22

ESP32 Firmware

#include 
#include 
#include 
#include 

PMS pms(Serial2);
SCD30 scd30;

void setup() {
  Serial2.begin(9600, SERIAL_8N1, 17, 16);
  scd30.begin();
  scd30.startContinuousMeasurement();
  
  WiFi.begin(ssid, password);
  client.setServer(mqtt_server, 1883);
}

void loop() {
  // Read PM2.5
  pms.read();
  float pm25 = pms.readPM2_5();
  
  // Read CO2
  if (scd30.dataAvailable()) {
    float co2 = scd30.getCO2();
    float temp = scd30.getTemperature();
    float humidity = scd30.getHumidity();
  }
  
  // Publish
  publishAirQuality(pm25, co2, temp, humidity);
  
  delay(5000);
}

Dashboard Setup

Air Quality Index (AQI) calculation:

// AQI Categories
Good: PM2.5 0-12, CO2 400-800
Moderate: PM2.5 12-35, CO2 800-1000
Unhealthy (Sensitive): PM2.5 35-55, CO2 1000-1500
Unhealthy: PM2.5 55-150, CO2 1500-2000
Very Unhealthy: PM2.5 150-250, CO2 >2000
Health Guidelines:
  • CO2 > 1000ppm: Increase ventilation
  • PM2.5 > 35: Run air purifier
  • VOC High: Remove source, ventilate
  • Humidity 40-60%: Ideal range

Next Steps

  • Add formaldehyde sensor
  • Integrate with HVAC system
  • Create mobile notifications
  • Log data for trend analysis