Contact Sales & After-Sales Service

Contact & Quotation

  • Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.
  • Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.
Drag & Drop Files, Choose Files to Upload You can upload up to 3 files.

Notes:
For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.

MQ-135 Air Quality Sensor Arduino: Complete Guide to Indoor Monitoring

Indoor air quality has become a serious concern, especially with more people spending extended time indoors. After integrating dozens of environmental sensors into PCB designs over the years, I can confidently say the MQ-135 air quality sensor Arduino combination offers the best entry point for anyone wanting to monitor their indoor environment without breaking the bank.

The MQ-135 detects multiple harmful gases simultaneously, including ammonia, benzene, alcohol, smoke, and carbon dioxide. When paired with an Arduino microcontroller, you get a functional air quality monitoring system that can alert you when ventilation is needed or pollutant levels become concerning.

Let me walk you through everything I’ve learned deploying these sensors in real-world applications.

What is the MQ-135 Air Quality Sensor?

The MQ-135 belongs to the MQ series of metal oxide semiconductor (MOS) gas sensors manufactured by companies like Winsen and Hanwei Electronics. At its core sits a tin dioxide (SnO2) sensing element that changes electrical resistance when exposed to various air pollutants.

What makes the MQ-135 particularly valuable for indoor monitoring is its sensitivity to gases commonly found in enclosed spaces. Unlike specialized sensors that target single gases, this sensor responds to a broad spectrum of air quality indicators, making it ideal for general indoor air quality assessment.

The sensor uses a heated element that must reach operating temperature before providing accurate readings. This heating requirement is something many beginners overlook, leading to inconsistent results during initial testing.

MQ-135 Sensor Technical Specifications

Before designing any monitoring circuit, understanding the electrical characteristics prevents frustrating debugging sessions. Here are the key specifications from the datasheet:

ParameterValue
Operating Voltage5V DC
Heater Power Consumption~800mW
Load Resistance Range10kΩ – 47kΩ
Heater Resistance33Ω ±5%
Detection Range10-1000 ppm
Preheat Time24-48 hours (initial)
Operating Temperature-20°C to 50°C
Operating Humidity< 95% RH

The 800mW heater power draw is significant. When laying out your PCB, ensure adequate copper pour for heat dissipation and consider the thermal effects on nearby temperature-sensitive components.

Gases Detected by MQ-135 Sensor

The MQ-135 responds to multiple target gases with varying sensitivity levels. Understanding which gases trigger stronger responses helps interpret your readings:

GasSensitivityCommon Indoor Source
Ammonia (NH3)HighCleaning products, pets
Benzene (C6H6)HighPaints, adhesives, furniture
AlcoholMedium-HighSanitizers, cleaners
SmokeMediumCooking, burning materials
Carbon Dioxide (CO2)MediumHuman respiration
Nitrogen Oxides (NOx)MediumCombustion appliances
Sulfur CompoundsMediumSewer gas, industrial

One important caveat from my experience: the MQ-135 cannot differentiate between these gases. When readings spike, you know air quality has degraded, but determining the specific culprit requires additional context or dedicated sensors.

MQ-135 Module Pinout Configuration

Most MQ-135 modules available today come with four pins. Understanding each connection saves troubleshooting time:

PinNameFunction
VCCPower SupplyConnect to 5V DC
GNDGroundCommon ground reference
AOUTAnalog OutputVoltage proportional to gas concentration
DOUTDigital OutputHIGH/LOW based on threshold setting

The module includes an onboard potentiometer that adjusts the threshold for the digital output. When gas concentration exceeds the set level, the DOUT pin goes LOW and an LED indicator lights up. This feature allows basic detection without any microcontroller, but for serious monitoring, the analog output provides much more useful data.

How the MQ-135 Sensor Works

Understanding the detection mechanism helps troubleshoot issues when readings don’t behave as expected.

The tin dioxide sensing element operates at elevated temperatures, typically 200-300°C, maintained by an internal heater coil. In clean air, oxygen molecules adsorb onto the heated SnO2 surface, capturing free electrons and creating a high-resistance depletion region.

When target gases enter the sensor chamber, they react with the adsorbed oxygen molecules. This chemical reaction releases electrons back into the semiconductor material, decreasing resistance. The resistance change creates a measurable voltage difference across the load resistor that your Arduino reads through the analog pin.

The relationship between gas concentration and resistance follows a logarithmic curve documented in the sensor’s datasheet. Each target gas has its own characteristic curve, which is why PPM calculations require gas-specific coefficients.

Wiring MQ-135 Air Quality Sensor to Arduino

The hardware connections are straightforward. Here’s my standard configuration:

MQ-135 PinArduino Connection
VCC5V
GNDGND
AOUTA0
DOUTD8 (optional)

A word of caution from countless prototype iterations: avoid powering the MQ-135 from the Arduino’s onboard 5V regulator when other power-hungry components are connected. The sensor’s heater draws approximately 150-180mA continuously. Use an external regulated 5V supply for reliable operation.

For ESP8266 or ESP32 projects operating at 3.3V logic, implement a voltage divider on the analog output. A 170kΩ and 330kΩ resistor combination scales the 5V maximum output to safe 3.3V input levels.

Basic Arduino Code for MQ-135 Air Quality Monitoring

Here’s a tested starting point that gets your MQ-135 air quality sensor Arduino project running:

#define MQ135_PIN A0

#define BUZZER_PIN 9

#define LED_PIN 13

#define THRESHOLD 400

int sensorValue;

void setup() {

  Serial.begin(9600);

  pinMode(BUZZER_PIN, OUTPUT);

  pinMode(LED_PIN, OUTPUT);

  Serial.println(“MQ-135 Air Quality Monitor”);

  Serial.println(“Warming up sensor…”);

  delay(30000); // 30 second minimum warm-up

  Serial.println(“Sensor ready for readings”);

}

void loop() {

  sensorValue = analogRead(MQ135_PIN);

  Serial.print(“Air Quality Value: “);

  Serial.println(sensorValue);

  if (sensorValue > THRESHOLD) {

    digitalWrite(LED_PIN, HIGH);

    digitalWrite(BUZZER_PIN, HIGH);

    Serial.println(“WARNING: Poor air quality detected!”);

  } else {

    digitalWrite(LED_PIN, LOW);

    digitalWrite(BUZZER_PIN, LOW);

  }

  delay(2000);

}

The 30-second warm-up delay is a minimum. For accurate readings, especially with a new sensor, extend this significantly or implement the full calibration procedure.

Calibrating Your MQ-135 Sensor

Proper calibration separates a hobby project from a useful monitoring system. The calibration process establishes your baseline resistance value (Ro) in clean outdoor air.

Determining the Ro Value

The Ro value represents sensor resistance at a known clean air condition, typically outdoor air with approximately 400 ppm CO2. Use this calibration routine:

#include “MQ135.h”

#define MQ135_PIN A0

void setup() {

  Serial.begin(9600);

  Serial.println(“MQ-135 Calibration Mode”);

  Serial.println(“Place sensor in clean outdoor air”);

  Serial.println(“Waiting for sensor warm-up…”);

  delay(180000); // 3 minute warm-up for calibration

}

void loop() {

  MQ135 gasSensor = MQ135(MQ135_PIN);

  float rzero = gasSensor.getRZero();

  Serial.print(“RZERO: “);

  Serial.println(rzero);

  delay(1000);

}

Run this code outdoors for several hours until the RZERO value stabilizes. Record this value and update the MQ135.h library file:

#define RLOAD 22.0     // Your measured load resistance in kOhms

#define RZERO 76.63    // Your calibrated RZERO value

The Load Resistor Problem

Many budget MQ-135 modules ship with a 1kΩ load resistor instead of the datasheet-recommended 20-22kΩ. This significantly affects accuracy. Measure your module’s load resistor between the A0 and GND pins. If it reads around 1kΩ, either replace it with a 22kΩ resistor or adjust the RLOAD value in your code accordingly.

Calculating Gas Concentration in PPM

Converting raw analog readings to meaningful PPM values requires understanding the sensor’s characteristic curves.

The exponential regression coefficients for MQ-135 target gases are:

GasCoefficient aCoefficient b
CO605.18-3.937
Alcohol77.255-3.18
CO2110.47-2.862
Toluene44.947-3.445
NH4102.2-2.473
Acetone34.668-3.369

The PPM calculation follows:

PPM = a × (Rs/Ro)^b

Where Rs is current sensor resistance and Ro is your calibrated clean air resistance.

Advanced PPM Measurement Code

Here’s a more complete implementation using the MQSensorsLib library:

#include <MQUnifiedsensor.h>

#define Board “Arduino UNO”

#define Pin A0

#define Type “MQ-135”

#define Voltage_Resolution 5

#define ADC_Bit_Resolution 10

#define RatioMQ135CleanAir 3.6

MQUnifiedsensor MQ135(Board, Voltage_Resolution, ADC_Bit_Resolution, Pin, Type);

void setup() {

  Serial.begin(9600);

  MQ135.setRegressionMethod(1);

  MQ135.init();

  Serial.println(“Calibrating MQ-135…”);

  float calcR0 = 0;

  for(int i = 1; i <= 10; i++) {

    MQ135.update();

    calcR0 += MQ135.calibrate(RatioMQ135CleanAir);

  }

  MQ135.setR0(calcR0 / 10);

  Serial.print(“R0 = “);

  Serial.println(calcR0 / 10);

  Serial.println(“Calibration complete”);

}

void loop() {

  MQ135.update();

  MQ135.setA(110.47);

  MQ135.setB(-2.862);

  float CO2 = MQ135.readSensor();

  MQ135.setA(102.2);

  MQ135.setB(-2.473);

  float NH4 = MQ135.readSensor();

  MQ135.setA(605.18);

  MQ135.setB(-3.937);

  float CO = MQ135.readSensor();

  Serial.print(“CO2: “);

  Serial.print(CO2 + 400); // Add atmospheric baseline

  Serial.print(” ppm | NH4: “);

  Serial.print(NH4);

  Serial.print(” ppm | CO: “);

  Serial.print(CO);

  Serial.println(” ppm”);

  delay(2000);

}

Note the CO2 baseline addition. The sensor measures CO2 deviation from atmospheric levels (approximately 400 ppm), so adding this baseline gives absolute readings.

Building an Indoor Air Quality Monitor

For a complete indoor monitoring station, combine the MQ-135 with additional sensors:

Component List

ComponentFunctionArduino Pin
MQ-135Air quality detectionA0
DHT22Temperature/HumidityD2
OLED DisplayData visualizationI2C (SDA/SCL)
BuzzerAudio alertsD9
RGB LEDVisual status indicatorD10, D11, D12

Air Quality Index Thresholds

Based on my monitoring deployments, these threshold ranges work well for indoor environments:

Sensor ReadingAir Quality LevelAction Required
0-200GoodNormal ventilation
200-400ModerateConsider opening windows
400-600UnhealthyIncrease ventilation immediately
600-800Very UnhealthyEvacuate and ventilate
>800HazardousEmergency ventilation required

These values correspond to the raw analog reading when using proper calibration. Your specific thresholds may vary based on sensor calibration and load resistor values.

Practical Applications for MQ-135 Air Quality Sensor Arduino Projects

Over the years, I’ve integrated MQ-135 sensors into various monitoring solutions:

Home Air Quality Monitoring

The most common application. Place sensors in living areas, bedrooms, and kitchens to track air quality throughout the day. Network multiple sensors with ESP8266 modules for whole-home monitoring.

Office Ventilation Control

In commercial settings, MQ-135 readings can trigger HVAC adjustments when CO2 levels indicate poor ventilation. This directly impacts occupant productivity and comfort.

Workshop Safety Systems

Detect solvent vapors, paint fumes, and combustion byproducts in workshops or garages. Automatic exhaust fan activation when readings exceed safe levels.

Smart Classroom Monitoring

Schools benefit from monitoring CO2 levels, which directly correlate with student alertness. High CO2 indicates insufficient fresh air circulation.

Kitchen Smoke Detection

Early detection of cooking smoke before it triggers fire alarms. Useful for smart home integration where exhaust fans activate automatically.

MQ-135 Arduino Libraries

Several libraries simplify working with the MQ-135:

LibraryDeveloperKey Features
MQ135GeorgKSimple PPM calculations, temperature compensation
MQSensorsLibMiguel5612Multi-gas support, calibration tools
MQUnifiedsensorMiguel CalifaUnified interface for all MQ sensors
AmanSCoder MQ135AmanSEnhanced temperature/humidity correction

I recommend MQSensorsLib for projects requiring accurate PPM calculations across multiple gas types. For simple threshold detection, the basic MQ135 library works fine.

Troubleshooting Common MQ-135 Issues

From debugging numerous MQ-135 installations, these problems appear most frequently:

Readings Always High or Erratic: Insufficient preheat time is the most common cause. New sensors require 24-48 hours of continuous power before providing stable readings. Even used sensors need 3-5 minutes to warm up after power cycling.

PPM Values Seem Wrong: Check your load resistor value. Many modules ship with 1kΩ instead of the recommended 20-22kΩ. Either replace the resistor or adjust the RLOAD parameter in your library configuration.

No Response to Gas Exposure: Verify the heater is drawing current. Measure between VCC and GND; you should see approximately 150-180mA at 5V. No current draw indicates a failed heater element.

Readings Drift Over Time: Environmental factors like temperature and humidity affect sensor response. Consider adding a DHT22 sensor and implementing the temperature/humidity correction factors in your code.

Sensor Degradation: MQ-135 sensors have a typical lifespan of 2-3 years depending on exposure conditions. Exposure to high concentrations of corrosive gases (H2S, chlorine, HCl) accelerates degradation.

Important Limitations and Safety Considerations

Let me be direct about something critical: the MQ-135 is not a certified safety device. Do not rely on it as your sole protection against toxic gas exposure.

The sensor has real limitations that affect practical use. Cross-sensitivity means it cannot identify specific gases, only detect their cumulative presence. Temperature and humidity significantly affect readings without proper compensation. The sensor requires significant power and generates heat, making battery operation challenging.

For life-safety applications, use certified commercial detectors that meet UL, CE, or equivalent standards. The MQ-135 excels as an early warning system, comfort monitoring tool, and educational platform, but it’s not a substitute for proper safety equipment.

Useful Resources and Downloads

Here are the resources I reference when working with MQ-135 sensors:

Datasheets and Technical Documentation

  • Winsen MQ-135 Official Datasheet: Complete electrical specifications and sensitivity curves
  • Hanwei MQ-135 Technical Reference: Alternative documentation with application circuits

Arduino Libraries

  • MQSensorsLib GitHub Repository: Comprehensive library with calibration examples
  • GeorgK MQ135 Library: Lightweight library for basic PPM calculations
  • AmanSCoder Modified MQ135: Temperature and humidity compensation support

Calibration Tools

  • CO2.Earth Website: Current atmospheric CO2 baseline for calibration reference
  • Online Rs/Ro Calculator: Web-based PPM conversion utilities

Community Resources

  • Arduino Project Hub MQ-135 Examples: Community-contributed project code
  • Instructables Air Quality Projects: Step-by-step build guides

Frequently Asked Questions

How long should I preheat the MQ-135 sensor before taking readings?

For a brand new sensor, the manufacturer recommends 24-48 hours of continuous operation before the readings stabilize. This initial burn-in period allows the sensing element to reach consistent operating characteristics. After the initial burn-in, the sensor needs 3-5 minutes of warm-up time each time power is applied before readings become reliable.

Can the MQ-135 accurately measure CO2 levels for indoor monitoring?

The MQ-135 can detect CO2 changes relative to atmospheric baseline levels, but it’s not designed as a precision CO2 meter. It works reasonably well for general indoor air quality trending where you want to know when ventilation is needed. For accurate CO2 measurement in PPM, dedicated NDIR (Non-Dispersive Infrared) sensors like the MH-Z19 provide better accuracy and specificity.

What is the difference between analog and digital output on MQ-135 modules?

The analog output (AOUT) provides a continuous voltage between 0-5V proportional to detected gas concentration, enabling precise monitoring and PPM calculations. The digital output (DOUT) provides a simple HIGH/LOW signal based on a threshold set by the onboard potentiometer, useful for basic alarm triggers without complex microcontroller programming.

Why do my MQ-135 readings vary so much between different sensors?

Manufacturing tolerances cause significant variation in the base resistance (Ro) between individual MQ-135 sensors. Each sensor requires individual calibration in clean air to establish its specific Ro value. Additionally, variations in the load resistor value on different module batches affect readings. Always measure your specific module’s load resistance and update your code accordingly.

Can I use the MQ-135 with 3.3V microcontrollers like ESP8266 or ESP32?

The MQ-135 heater requires 5V to reach proper operating temperature, so the sensor module needs 5V power. However, the analog output can exceed 3.3V under high gas concentrations, which can damage 3.3V ADC inputs. Implement a voltage divider (such as 170kΩ and 330kΩ resistors) on the analog output to scale it to safe 3.3V levels before connecting to your ESP8266 or ESP32 analog input.

Final Thoughts

The MQ-135 air quality sensor Arduino combination provides an accessible platform for understanding indoor air quality monitoring. While it won’t replace laboratory-grade instruments, it offers genuine utility for detecting air quality trends, triggering ventilation systems, and raising awareness about indoor air pollution.

Start with the basic code examples to understand sensor behavior, invest time in proper calibration, and don’t skip the extended preheat period. The effort pays off in reliable readings that actually mean something.

Remember that air quality monitoring is about trends and thresholds rather than precise measurements. The MQ-135 excels at answering questions like “Is air quality getting worse?” and “Should I open a window?” rather than “What is the exact CO2 concentration?” Approach it with appropriate expectations, and you’ll find it a valuable addition to your smart home or environmental monitoring projects.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Sales & After-Sales Service

Contact & Quotation

  • Inquire: Call 0086-755-23203480, or reach out via the form below/your sales contact to discuss our design, manufacturing, and assembly capabilities.

  • Quote: Email your PCB files to Sales@pcbsync.com (Preferred for large files) or submit online. We will contact you promptly. Please ensure your email is correct.

Drag & Drop Files, Choose Files to Upload You can upload up to 3 files.

Notes:
For PCB fabrication, we require PCB design file in Gerber RS-274X format (most preferred), *.PCB/DDB (Protel, inform your program version) format or *.BRD (Eagle) format. For PCB assembly, we require PCB design file in above mentioned format, drilling file and BOM. Click to download BOM template To avoid file missing, please include all files into one folder and compress it into .zip or .rar format.