The MQ135 is a cheap air-quality sensor that can detect gases like ammonia, benzene, smoke, and CO₂ in the air. It is commonly used in Arduino, IoT, and simple DIY projects. This guide will help you understand how the MQ135 air quality sensor works, its pins, how to connect it, and how to use it with Arduino. You will also learn how to calibrate it, make an air-quality monitor. Also, in this guide, we will see the difference between the MQ135 and MQ2 sensors.

What is MQ135 Air Quality Sensor?

The MQ135 air quality sensor is a gas sensor that can detect many harmful gases in the air, like ammonia, smoke, and other pollution gases. Because it senses many types of gases, people use it as a general air-quality sensor.

It usually comes as a module with the sensor, a resistor, a small amplifier, and a knob (potentiometer) to set the limit. The module gives two outputs:

  • Analog output: shows the air quality level
  • Digital output: becomes HIGH or LOW when the air quality crosses the limit you set

MQ135 Pinout and Features

A normal MQ135 air quality sensor module has four pins:
VCC, GND, AO (analog output), and DO (digital output).

Its important features are:

  • Works on 5V power.
  • It is highly sensitive to gases like ammonia, benzene, smoke, and other air pollutants.
  • Gives two types of output:
    • Analog output that changes with gas concentration
    • Digital output that turns HIGH/LOW based on the level you set
  • It needs a pre-heating time (a few seconds to minutes) to give proper readings.

Because of these features, the MQ135 is good for simple Arduino air-quality projects, where you only need to see changes in air quality rather than exact ppm values.

MQ135 Air Quality Sensor Working Principle

The MQ135 air quality sensor works using a special material called tin dioxide (SnO₂). Its resistance changes when it touches polluted gases.

  • In clean air, the resistance is high.
  • When harmful gases are present, the resistance becomes low, and the output voltage changes.

Inside the sensor, a small heater keeps the material hot so it can react quickly with gases.
When gas levels go up, the sensor’s resistance drops, and the analog voltage increases, which the Arduino reads to check the air quality.

Pre-heating and Stabilization

Before using the MQ135 sensor, it’s important to let its internal heater warm up the sensing part. Many guides suggest giving a new sensor a “burn-in” period of a few hours when you first turn it on. This helps the sensor produce more consistent readings over time.

Once you power it up, you should wait about 20 to 30 seconds for the sensor to warm up and stabilize before taking any measurements, if you want more precise results. In fact, some people recommend letting it warm up even longer in clean air to establish a reference point for accurate readings.

MQ135 Specifications at a Glance

The MQ135 air quality sensor has some common datasheet details:

  • It works on 5V power.
  • The heater inside uses about 150–800 mW.
  • It can detect many gases like ammonia, NOx, benzene, smoke, and CO₂.
  • It gives an analog output (around 0–4V) and a digital output with an adjustable limit.

In fact, these values can change depending on the module brand. So, it is best to check the datasheet of the specific sensor you have.

Creating an Arduino-Based Air Quality Monitor

Making an Arduino Air Quality Monitor with the MQ135 is simple. You connect the MQ135 sensor to the Arduino and write a small program to read the air quality. The MQ135 can detect many gases like CO₂, ammonia, benzene, and smoke. It sends an analog signal that changes based on how much gas is in the air.

Components Needed

  • Arduino board (like Arduino Uno)
  • MQ135 sensor
  • Optional: DHT11 for temperature and humidity
  • Optional: LCD or OLED display
  • Breadboard and jumper wires

How Does It Work?

The MQ135 air quality sensor is connected to the Arduino’s analog pin (usually A0). The Arduino reads the voltage from the sensor, which increases or decreases depending on the air quality. You can use this raw value directly or convert it to approximate PPM with calibration.

Basic Features:

  • Shows real-time air quality readings
  • Displays data on Serial Monitor or a screen
  • Optional temperature and humidity reading
  • Alerts when levels cross a set limit
  • Calibration to improve accuracy

Sample Code:

int mq135Pin = A0;

void setup() {

  Serial.begin(9600);

}

void loop() {

  int airQualityValue = analogRead(mq135Pin);

  Serial.print("Air Quality Sensor Value: ");

  Serial.println(airQualityValue);

  delay(1000);

}

This code reads the sensor value every second and prints it on the Serial Monitor. You can later add more sensors, convert values into air quality levels, or send the data to the internet using IoT modules.

Extra Notes:

  • Calibration helps make the readings more accurate.
  • You can add WiFi modules like ESP8266 for sending data online.
  • You can use LEDs or buzzers to warn when the air becomes unsafe.

This makes a simple and low-cost DIY air quality monitor that gives real-time information and is great for learning.

Connecting the MQ135 Air Quality Sensor with Arduino

Connecting the MQ135 to an Arduino is very simple using the analog output.

Basic wiring:

  • VCC → Arduino 5V
  • GND → Arduino GND
  • AO → Arduino A0
  • DO (optional) → any digital pin if you want a HIGH/LOW air-quality alarm

If you are using an ESP8266/ESP32, their analog pins work at 3.3V, so you should use a voltage divider on the AO pin.
For a normal Arduino, you can connect the AO pin directly because it supports 5V.

MQ135 Air Quality Sensor Arduino Code (Basic)

Here is a basic Arduino code example for interfacing the MQ135 sensor to read analog air quality values and print them on the Serial Monitor:

int mq135Pin = A0;  // MQ135 sensor analog output connected to Arduino analog pin A0

int sensorValue = 0;

void setup() {

Serial.begin(9600);  // Initialize serial communication at 9600 baud rate

pinMode(mq135Pin, INPUT);  // Set sensor pin as input

}

void loop() {

 sensorValue = analogRead(mq135Pin);  // Read analog value from sensor

Serial.print("Air Quality Sensor Value: ");

 Serial.println(sensorValue);  // Print sensor value to Serial Monitor

 delay(1000);  // Wait 1 second before next reading

}

This code reads the MQ135 sensor value from pin A0 again and again and shows the number on the Serial Monitor every second. The value changes based on how much gas is in the air. This is the simplest setup to check air quality. More advanced projects can calibrate the sensor to convert the raw value into PPM for gases like CO₂.

How to Calibrate MQ135 Air Quality Sensor?

Calibrating the MQ135 sensor helps you get accurate and meaningful air-quality readings. To do this, keep the sensor in clean air, let it warm up, and note its resistance (this becomes R₀). Then you compare the current resistance (Rs) with R₀ and use the sensor’s graph to estimate gas levels in ppm. Most tutorials calculate Rs using the ADC value and a fixed load resistor (RLOAD). Arduino examples also show how to calculate RZERO, which is the sensor’s reference value for CO₂ or VOC measurements.

Practical Calibration Tips

In hobby projects, it’s hard to perfectly calibrate the MQ135 air quality sensor because it reacts to many gases and changes in the environment. So, it’s better to watch how the readings change over time instead of trying to get exact ppm values. Use calibration mainly to set a baseline and simple alert levels for your room or lab.

For better results:

  • Always let the sensor warm up for the same amount of time before taking readings.
  • Calibrate once in clean fresh air and save the R₀ value in your code or EEPROM.
  • Keep the sensor away from heat, high humidity, or strong airflow.

Difference Between MQ2 and MQ135

MQ2 and MQ135 air quality sensor are both gas sensors, but they are designed for different jobs.

Main differences:

  • Target gases:
    • MQ2 detects LPG, propane, hydrogen, methane, and smoke. It is mainly used for gas leak and fire detection.
    • MQ135 detects ammonia, benzene, smoke, and other VOC gases. It is mainly used for air quality monitoring.
  • Use cases:
    • Use MQ2 when you want to detect flammable gas leaks or smoke for safety.
    • Can use MQ135 when you want to check overall indoor air quality or pollution levels.
  • Output:
    Both sensors give analog output, but their sensitivity and calibration curves are different.

In short, use MQ135 for air quality monitoring and MQ2 for LPG or flammable gas leak detection.

Limitations of MQ135 in Real Projects

The MQ135 air quality sensor is cheap and popular, but it has some limitations. It is not a certified air-quality device, and its readings can change over time, differ from one sensor to another, and be affected by temperature and humidity. Since it reacts to many gases at the same time. You cannot know which exact gas caused the change, only that the air became better or worse. For professional use, you need more accurate sensors. But for learning, hobby projects, and simple IoT prototypes, the MQ135 works well.

Typical Applications of MQ135 Sensor

The MQ135 sensor is commonly used in simple and low-cost air quality projects. It is used for checking indoor air in homes, schools, and offices. People also use it for IoT pollution monitoring with ESP8266/ESP32 and cloud dashboards. It helps in smart city and environmental monitoring experiments. Students use it in projects to learn about gas sensing and sensor calibration. Because it works easily with Arduino, it is popular in beginner and intermediate IoT courses.

Conclusion

The MQ135 air quality sensor is a cheap sensor that works well for DIY and Arduino projects. It cannot give very accurate ppm values, but it is good for checking basic air quality and detecting harmful gases. With simple wiring and code, anyone can make an air-quality monitor. Even though it is not as accurate as professional sensors, it is still popular among students and beginners. Overall, the MQ135 is a good choice for learning, experiments, and low-cost air-quality projects.

Frequently Asked Questions (FAQs)
Q. MQ135 Sensor Price.

Ans. The MQ135 sensor usually costs ₹90 to ₹200 in India. Its price varies by seller, with ElectroPi offering it for ₹92, Robobazar for ₹109, and QBM India for ₹179.