MQ-135: Volatile Gasses Air Quality

icon picker
MQ-135 Setup Guide

Copy of Wiring / Connections
Arduino
Volatile Gas Sensor
5V
VCC
GND
GND
A0
AOUT
D2
DOUT
There are no rows in this table

Pinout

image.png

The MQ-135 sensor module consists of four pins namely VCC, GND, DO, and DO. The table below gives a brief description of them.

Table 1
Pin
Description
VCC
Positive power supply pin that powers up the sensor module.
GND
Reference potential pin.
AO
Analog output pin. It generates a signal proportional to the concentration of gas vapors coming in contact with the sensor.
DO
Digital Output pin. It also produces a digital signal whose limit can be set using the in-built potentiometer.
There are no rows in this table

Interfacing MQ-135 Gas Sensor with Arduino


The table below shows the connections you need to make between the MQ3 sensor module and Arduino using both the analog output and the digital output pins of the sensor.
Table 2
MQ-135 Module
Arduino
VCC
5V
GND
GND
AO
A0
DO
Pin 2
There are no rows in this table
Connect MQ-135 sensor’s VCC pin with 5V terminal of Arduino UNO. This will power up the sensor. Additionally, we will connect the analog pin AO with A0 and DO with Pin 2 of Arduino UNO. Both the devices will be commonly grounded.
Follow the connection diagram below, to connect your devices accordingly.
image.png
Arduino UNO with MQ-135 Module using both digital and analog outputs
MQ-135 Gas Detection Arduino Sketch
Open your Arduino IDE and go to File > New. Copy the code below in that file.
image.png
This sketch will read both the analog and digital outputs of the sensor. If the analog output is greater than 400 then an LED connected at Arduino pin 2 will turn ON. Otherwise, turn the LED OFF and print both the analog and digital output readings on the serial monitor.
int sensorValue;
int digitalValue;

void setup()
{
Serial.begin(9600); // sets the serial port to 9600
pinMode(13, OUTPUT);
pinMode(2, INPUT);
}

void loop()
{
sensorValue = analogRead(0); // read analog input pin 0
digitalValue = digitalRead(2);
if (sensorValue > 400)
{
digitalWrite(13, HIGH);
}
else
digitalWrite(13, LOW);
Serial.println(sensorValue, DEC); // prints the value read
Serial.println(digitalValue, DEC);
delay(1000); // wait 100ms for next reading
}

How the Code Works?

Create two int variables to hold the analog and digital output readings.
Advertisement
int sensorValue;
int digitalValue;
Inside the setup() function, we will open the serial communication at a baud rate of 9600. Then configure pin2 connected with the DO pin of the sensor as an input and pin13 connected with the LED’s anode pin as an output.
void setup()
{
Serial.begin(9600); // sets the serial port to 9600
pinMode(13, OUTPUT);
pinMode(2, INPUT);
}
In the infinite loop(), we will use analogRead() on the A0 pin and save the value in ‘sensorValue.’ Likewise, we will read the digital output on pin2 using digitalRead() and save the value in ‘digitalValue.’ Next, using an if-else statement we will check if the analog reading is greater than 400 or not. If it is then turn the LED ON. Otherwise, leave the LED OFF and display the current analog and digital readings in the serial monitor.
void loop()
{
sensorValue = analogRead(0); // read analog input pin 0
digitalValue = digitalRead(2);
if (sensorValue > 400)
{
digitalWrite(13, HIGH);
}
else
digitalWrite(13, LOW);
Serial.println(sensorValue, DEC); // prints the value read
Serial.println(digitalValue, DEC);
delay(1000); // wait 100ms for next reading
}

Demonstration

To see the demonstration of the above code, upload the code to Arduino. But, before uploading code, make sure to select the Arduino board from Tools > Board and also select the correct COM port to which the Arduino board is connected from Tools > Port.

select Arduino uno

On the serial monitor, you can see the values of the analog pin being detected. Currently, in my case, they are around about 150 which indicates normal air.
Normal air returns approximately 100-150
Alcohol returns approximately 700
Lighter gas returns approximately 750

Sources
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.