MQ-135 Air Quality and Hazardous Gas Sensor For Arduino Review and Code

This post talks about using the MQ-135 Air Quality and Hazardous Gas sensor with an Arduino.

MQ-135 Air Quality and Hazardous Gas Sensor

The MQ-135 air quality and hazadous gas sensor is a small unit that reports the relative quality of the air.

This specific variant works particularly well with detecting carbon dioxide,
benzene, alcohol, and smoke in the air.

These gasses are typically used as a measure of air quality. This is why this sensor is typically sold as a “Air quality and hazardous gas sensor”.

The analogue pin will output a relative value according to the amount of particulates in the air.

Without calibration it is not possible to relate this to a specific concentration (in parts per million) but works well as a relative measure.

When using this in an area you will be able to detect if the air quality is getting better or worse by the trend in values reported.

Wiring it up to an Arduino

This MQ-135 sensor has two pins which can be used to read the value of the sensor. The first is a basic analogue pin which will return a value between 0 and 5 volts.

This voltage represents a relative range of high to low gas concentration. The lower the voltage the lower the amount of gas detected.

On the underside of the sensor a potentiometer allows configuring of the digital pin. The digital pin will be brought high once a specific level of gas is detected. This level is set by the potentiometer on the back.

The VCC pin must be connected to the 5 volt pin on the Arduino. The GND pin must similarly be connected to the Ground pin on the Arduino.

Programming the Arduino with the
MQ-135 Air Quality and Hazardous Gas Sensor

In this post I am using the analogue pin to read the relatively value of the sensor.

#define ANALOG_IN_PIN 0
int sensorVal = 0;

void setup() {

void loop() {
  sensorVal = analogRead(ANALOG_IN_PIN);

Here the serial out is initialized in the setup. In the loop method the sensor is continually read from ANALOG_IN_PIN, and sent on the serial line.

Final Review

This is a simple air quality sensor which can be used to calculate the quality of the air. It is typically used to compare the relatively air quality in an area over time.

With some work it can be calibrated to give a more specific value in parts per million but this was not done here.

Providing both an analogue and digital pin to read the output gives various options to its use. This is especially useful in smaller IoT projects where pins are at a premium.

Since this is a small and useful sensor I would definitely look at using this in a project again.

Would buy again!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.