Component guide · Beginner · 3 min read
MQ-135 air quality sensor

Pinout, Wiring and Code
By Geekobot Learning Team · Updated 29 Oct 2026
On this page
The MQ-135 is a heated gas sensor that responds to ammonia, benzene, alcohol, smoke and other pollutants, so its analog output works as a general indoor air quality indicator. It needs 5 V, about 150 mA and a warm-up period. It is not a real CO2 sensor: for accurate CO2 use an NDIR sensor such as the MH-Z19 or SCD40.
Key specs at a glance
- Detects
- NH3, NOx, alcohol, benzene, smoke, CO2 (weak response)
- Range
- About 10 to 1000 ppm for ammonia and benzene (needs calibration)
- Heater
- 5 V, about 150 mA
- Outputs
- AO analog, DO digital with trimmer threshold
- Warm-up
- Minutes for use, 24 to 48 hours burn-in for new sensors
- Supply
- 5 V
Models in this guide
These are alternatives. Pick the one that fits your project; you only need one.
Option 1MQ-135 Air Quality & Gas Detector Sensor Module for Arduino – Analog & TTL Output₹114
Option 2MQ-135 Air Quality Sensor Harmful Gas Detection Module – Analog & Digital Output₹114
Option 3Waveshare MQ-135 Air Quality Gas Sensor Module – Analog/Digital Output₹459
Option 4Winsen MQ135 Semiconductor Air Quality Sensor – SnO2 Gas Detection Module₹239
What the MQ-135 air quality sensor is
Like the MQ-2, the MQ-135 is a heated tin dioxide sensor whose resistance drops in the presence of certain gases. Its material is tuned toward air pollutants, which makes it a popular cheap air quality indicator for classrooms and kitchens.
Many tutorials print a CO2 ppm number from it. That number is an estimate based on assumptions; the sensor reacts much more strongly to other gases, so use it as an index, not a measurement.
MQ-135 air quality sensor pinout
The pins on the MQ-135 air quality sensor and what each one does.
| Pin | Function |
|---|---|
| VCC | 5 V |
| GND | Ground |
| AO | Analog output, higher = more pollutants |
| DO | Digital alarm output (trimmer threshold) |
- VCC
- 5 V
- GND
- Ground
- AO
- Analog output, higher = more pollutants
- DO
- Digital alarm output (trimmer threshold)
Wiring the MQ-135 air quality sensor
Scale AO with a divider before an ESP32 pin. Keep the sensor away from the board's regulator so its heat does not affect other sensors.
| MQ-135 air quality sensor pin | Arduino Uno | ESP32 |
|---|---|---|
| VCC | 5V | 5V (VIN) |
| GND | GND | GND |
| AO | A0 | GPIO 34 via 10k/20k divider |
| DO | D2 | GPIO 27 |
- VCC
- Arduino Uno:
- 5V
- ESP32:
- 5V (VIN)
- GND
- Arduino Uno:
- GND
- ESP32:
- GND
- AO
- Arduino Uno:
- A0
- ESP32:
- GPIO 34 via 10k/20k divider
- DO
- Arduino Uno:
- D2
- ESP32:
- GPIO 27
Example code
The thresholds are examples. Record values in fresh outdoor air and in your room to set your own levels.
const int AO_PIN = A0;
float avg = 0;
void setup() {
Serial.begin(9600);
delay(120000); // 2 minute warm-up
avg = analogRead(AO_PIN);
}
void loop() {
avg = avg * 0.9 + analogRead(AO_PIN) * 0.1; // smooth the reading
const char* level = avg < 200 ? "good" : avg < 350 ? "moderate" : "poor";
Serial.print((int)avg); Serial.print(" "); Serial.println(level);
delay(1000);
}Setup and tuning
after burn-in, note the reading outdoors or by an open window. Compare indoor values against it.
change the reading; pair it with an AHT20 if you want to compensate.
(MQ135 library) use a reference resistance R0 that you must calibrate; without it the numbers are not meaningful.
a rising trend over an hour is a good trigger to open a window.
What you need
Shop this list6 of 6 found in our store · ₹1,454
MQ-135 air quality and gas detector module: the common moduleMQ-135 Air Quality & Gas Detector Sensor Module for Arduino – Analog & TTL Output₹114
MQ-135 harmful gas detection module: alternative boardMQ-135 Air Quality Sensor Harmful Gas Detection Module – Analog & Digital Output₹114
Waveshare MQ-135 air quality gas sensor: Waveshare boardWaveshare MQ-135 Air Quality Gas Sensor Module – Analog/Digital Output₹459
Winsen MQ135 air quality sensor: the original maker's sensorWinsen MQ135 Semiconductor Air Quality Sensor – SnO2 Gas Detection Module₹239
ESP32-WROOM-32 38-pin development board: for Wi-Fi logging and dashboardsESP32-WROOM-32 38-Pin Development Board₹389
0.96 inch OLED display 128x64: to show readings without a computer0.96" OLED Display 128x64₹139Closest match, check the specs
Alternatives and when to choose them
- CO2 NDIR sensors: MH-Z19, SCD40 for real CO2 ppm.
- VOC sensors: SGP30, ENS160 with digital output.
- PM2.5 dust sensors: for smoke and dust particles.
Try it: Voltage divider calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Treating its output as accurate CO2 ppm.
- Reading before warm-up.
- Powering the heater from a 3.3 V pin.
- Mounting it inside a closed box with the controller.
Frequently asked questions
Can the MQ-135 measure CO2?
Only roughly. It responds more strongly to other gases; use an NDIR sensor for real CO2 values.
What does a higher reading mean?
More pollutants such as ammonia, alcohol, smoke or benzene in the air.
How long is the warm-up?
A few minutes for use; a new sensor needs 24 to 48 hours of burn-in.
Does it work with ESP32?
Yes, powered from 5 V with the analog output scaled to 3.3 V.
MQ-135 or MQ-2?
MQ-135 for air quality, MQ-2 for flammable gas and smoke.
Why does the reading drift?
Temperature, humidity and sensor ageing. Re-check the clean-air baseline regularly.
Parts for this guide
Calculators
Terms in this guide
Projects that use it
Put this into practice: 48 step-by-step builds in our project library use parts from this guide.
Keep learning
Sources
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.
