MQ-135 Air Quality Sensor

Complete Tutorial: Indoor Air Quality & Pollution Monitoring

📖 12 min read 🔧 Intermediate 💻 Arduino / ESP32

1. Introduction

The MQ-135 is an air quality sensor designed for detecting harmful gases in the air. It's commonly used in indoor air quality monitors, pollution detection systems, and HVAC control applications.

📦 Gases Detected

  • CO2 (Carbon Dioxide)
  • NH3 (Ammonia)
  • NOx (Nitrogen Oxides)
  • Alcohol vapors
  • Benzene
  • Smoke

2. Technical Specifications

Parameter Specification
Operating Voltage 5V DC
Heater Current ~150mA
Load Resistance 20kΩ (adjustable)
Preheat Time 24+ hours for accurate calibration
Output Type Analog (AO) + Digital (DO)
Detection Range 10-1000 ppm (varies by gas)

How It Works

Like other MQ sensors, the MQ-135 uses a tin dioxide sensing element:

  1. Heater keeps the sensing element at optimal temperature
  2. In clean air, resistance is high (low voltage output)
  3. Pollutants reduce resistance (higher voltage output)
  4. Different gases have different sensitivity curves

⚠️ Important: Burn-in Period

For accurate readings, the sensor needs a 24-48 hour burn-in period when first used. Run it continuously in clean air to stabilize the baseline.

3. Wiring Guide

MQ-135 Pin Description Arduino ESP32
VCC Power (5V) 5V VIN/5V
GND Ground GND GND
AO Analog Output A0 GPIO 34
DO Digital Output Pin 2 GPIO 13
MQ-135 wiring

Figure 1: MQ-135 sensor wiring with Arduino

4. Project: Air Quality Monitor

Basic Air Quality Reading

const int sensorPin = A0;

void setup() {
    Serial.begin(115200);
    Serial.println("MQ-135 Air Quality Sensor");
    Serial.println("Warming up (2 minutes)...");
    delay(120000);  // 2 minute warm-up
    Serial.println("Ready!");
}

void loop() {
    int rawValue = analogRead(sensorPin);
    float voltage = rawValue * (5.0 / 1023.0);

    Serial.print("Raw: ");
    Serial.print(rawValue);
    Serial.print(" | Voltage: ");
    Serial.print(voltage, 2);
    Serial.print("V | Air Quality: ");

    if (rawValue < 150) {
        Serial.println("Excellent");
    } else if (rawValue < 300) {
        Serial.println("Good");
    } else if (rawValue < 500) {
        Serial.println("Moderate");
    } else if (rawValue < 700) {
        Serial.println("Poor");
    } else {
        Serial.println("Hazardous!");
    }

    delay(2000);
}

Air Quality Index (AQI) Approximation

const int sensorPin = A0;

// Baseline value in clean air (calibrate this!)
const int cleanAirValue = 120;

void setup() {
    Serial.begin(115200);
    Serial.println("MQ-135 AQI Monitor");
    Serial.println("Calibrating...");
    delay(60000);
}

void loop() {
    int rawValue = analogRead(sensorPin);
    
    // Calculate a relative pollution index
    float ratio = (float)rawValue / cleanAirValue;
    int aqi = (ratio - 1.0) * 100;
    if (aqi < 0) aqi = 0;
    if (aqi > 500) aqi = 500;

    Serial.print("Raw: ");
    Serial.print(rawValue);
    Serial.print(" | AQI: ");
    Serial.print(aqi);
    Serial.print(" | Category: ");

    if (aqi <= 50) {
        Serial.println("Good (Green)");
    } else if (aqi <= 100) {
        Serial.println("Moderate (Yellow)");
    } else if (aqi <= 150) {
        Serial.println("Unhealthy for Sensitive (Orange)");
    } else if (aqi <= 200) {
        Serial.println("Unhealthy (Red)");
    } else if (aqi <= 300) {
        Serial.println("Very Unhealthy (Purple)");
    } else {
        Serial.println("Hazardous (Maroon)");
    }

    delay(2000);
}

5. MQ-135 vs Other Air Quality Sensors

Sensor Best For Interface
MQ-135 General air quality, NH3, CO2 Analog
CCS811 eCO2 and TVOC (calibrated) I2C
BME680 Gas + Temp + Humidity + Pressure I2C
PMS5003 Particulate matter (PM2.5) UART

For precise CO2 measurements, consider dedicated CO2 sensors like MH-Z19 or SCD30.

6. Applications

  • Indoor air quality: Office and home monitoring
  • HVAC control: Ventilation based on air quality
  • Smart home: Trigger air purifier or alert
  • Industrial: Workshop fume detection
  • Education: Environmental science projects

7. Troubleshooting

High readings in fresh air

  • Allow longer burn-in time (24-48 hours)
  • Ensure good ventilation during calibration

Readings don't change

  • Check 5V power supply
  • Verify sensor is warm (heater working)

Very low readings

  • Check analog pin connection
  • Verify ADC is working with a known voltage

8. Summary

  • Detects CO2, ammonia, NOx, alcohol, benzene, smoke
  • Requires 5V and long burn-in period (24+ hours)
  • Analog output proportional to pollution level
  • Calibrate baseline in known clean air
  • Not a precision sensor—use for relative measurements