Introduction: Breathing Smarter in a Polluted World

Air pollution silently affects millions every day, yet we rarely have access to real-time local air quality data. With an ESP32-based Smart Air Quality Monitor, you can track gas concentrations in your environment, get live readings on an OLED display, and even send data to the cloud for long-term analysis.

This project by SP Tech Solutions demonstrates a practical, low-cost system for detecting harmful gases using MQ-series sensors and the Wi-Fi-enabled ESP32 microcontroller.

Why Build an Air Quality Monitor?

  • Detect harmful gases like CO, COβ‚‚, NH₃, and smoke early
  • Improve home, lab, and factory safety
  • Log and analyze pollution levels over time
  • Promote environmental awareness and data-driven decisions

Components Required

  • ESP32 Dev Board
  • MQ135 Air Quality Sensor
  • MQ2 Gas Sensor (optional, for smoke/LPG)
  • 0.96" OLED Display (I2C)
  • Jumper wires and breadboard
  • 5V power supply or USB cable

Working Principle

The MQ135 and MQ2 sensors detect changes in gas concentration by measuring the variation in resistance of their sensing material. These analog voltage outputs are read by the ESP32's ADC pins, converted into meaningful PPM values, and displayed both locally and remotely via Wi-Fi.

Connection Diagram

MQ135 AO β†’ GPIO34 (Analog Input)
MQ135 VCC β†’ 5V
MQ135 GND β†’ GND
OLED SDA β†’ GPIO21
OLED SCL β†’ GPIO22
    

Code Summary

The following sketch displays live air quality data on the OLED and uploads it to ThingSpeak for remote visualization. You can easily modify it to use Blynk or your own web dashboard.

// SP Tech Solutions - Smart Air Quality Monitor
#include <WiFi.h>
#include <HTTPClient.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define MQ135_PIN 34
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

const char* ssid = "Your_WiFi";
const char* password = "Your_Password";
String server = "https://api.thingspeak.com/update?api_key=YOUR_KEY";

void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.setTextColor(WHITE);
  display.clearDisplay();
  display.setTextSize(1);
  display.println("SP Tech AQ Monitor");
  display.display();

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("WiFi connected!");
}

void loop() {
  int sensorValue = analogRead(MQ135_PIN);
  float voltage = sensorValue * (3.3 / 4095.0);
  float airQuality = map(sensorValue, 0, 4095, 0, 500); // Approx PPM

  display.clearDisplay();
  display.setCursor(0, 10);
  display.print("Air Quality: ");
  display.print(airQuality);
  display.println(" PPM");
  display.print("Voltage: ");
  display.print(voltage, 2);
  display.println(" V");
  display.display();

  if (WiFi.status() == WL_CONNECTED) {
    HTTPClient http;
    String url = server + "&field1=" + String(airQuality);
    http.begin(url);
    http.GET();
    http.end();
  }

  Serial.printf("Air Quality: %.1f PPM\n", airQuality);
  delay(15000);
}

Project Enhancements

  • Add Buzzer Alerts: Trigger a buzzer when air quality drops below safe limits.
  • Mobile Dashboard: View data on your phone using Blynk or MQTT.
  • Data Logging: Store readings on SD card for offline trend analysis.
  • Multiple Sensors: Combine MQ135 + MQ2 + DHT11 for a complete environmental monitor.

Calibration & Troubleshooting

  • Calibrate MQ sensors in clean air for accurate baseline readings.
  • If readings are unstable, add a delay and averaging filter in code.
  • Ensure proper power supply (some MQ sensors require β‰₯ 5V heating voltage).

Real-World Applications

  • Home air quality monitoring
  • Industrial pollution tracking
  • Smart city environmental sensing
  • IoT-based weather and health dashboards

Conclusion

The Smart Air Quality Monitor is a vital IoT project combining environmental awareness with electronics. With ESP32’s connectivity and the MQ sensors’ versatility, you can easily build a personalized air-quality dashboard that empowers you to breathe smarter and safer.

To get pre-tested modules, air quality kits, or complete IoT learning packages, visit SP Tech Solutions β€” where innovation meets sustainability.

SP Tech Solutions β€” Engineering Tomorrow’s Environment 🌍