Interfacing of MQ135 Gas Sensor with Arduino : In today’s world, we encounter different scenario where we see different gasses being emitted in atmosphere such as home appliances like air conditioner and industrial chimneys. Monitoring of these gasses is very important with safety point of view. Gas Sensors are very helpful in accomplishing this task. Small nose like sensor spontaneously respond to the alteration of gas concentration and keep our systems updated for special tasks.
In this tutorial we will learn how to interface MQ-135 Gas Sensor with Arduino Board? We will explore what is Gas Sensor? How it works? What is its pin configuration and how to interface it with Arduino? Our today’s tutorial consists of following sections:
- What is MQ-135 and how does it work?
- Pin Configuration.
- Required Components.
- Wiring Connections.
- Testing the Circuit.
- Code for Arduino.
What is MQ-135 gas sensor and how does it work?
The gas sensor module consists of a steel exoskeleton under which a sensing element is housed. This sensing element is subjected to current through connecting leads. This current is known as heating current through it, the gases coming close to the sensing element get ionized and are absorbed by the sensing element. This changes the resistance of the sensing element which alters the value of the current going out of it.
Pin Configuration MQ-135 gas sensor
From left to right first pins are as follows:
A0 Analog output
D0 Digital output
GND Ground
Specifications of MQ-135 gas sensor
- Wide detecting scope
- Fast response and High sensitivity
- Stable and long life Simple drive circuit
- Used in air quality control equipment for buildings/offices, is suitable for detecting
of NH3, NOx, alcohol, Benzene, smoke, CO2, etc. - Size: 35mm x 22mm x 23mm (length x width x height)
- Working voltage: DC 5 V
- Signal output instruction.
- Dual signal output (analog output, and high/low digital output)
- 0 ~ 4.2V analog output voltage, the higher the concentration the higher the voltage.
Required Components:
Following Components are required for this project:
- Arduino UNO
- Breadboard
- MQ-2 Gas sensor module
interfacing of MQ-135 gas sensor with Arduino
Wire the circuit as follows:
Arunio A0 pin with Sensor A0
Aruino D0 pin with Sensor D0
Arduino 5Vpin with Sensor Vcc
Arduino GND pin with Sensor GND
When no gas digital output is 1 and analog output gives 1023 max value. When gas is present digital output is 0 and analogue output is much less than 1023. Using potentiometer on chip we can control the turning OFF point of digital pin at some value of analog pin. The sensor needs a load-resistor at the output to ground. Its value could be from 2kOhm to 47kOhm. The lower the value, the less sensitive is the sensor. The higher the value, the less accurate is sensor for higher concentrations of gas. If only one specific gas is measured, the load-resistor can be calibrated by applying a known concentration of that gas. If the sensor is used to measure any gas (like in a air quality detector) the load-resistor could be set for a value of about 1V output with clean air. Choosing a good value for the load-resistor is only valid after the burn-in time
NOTE: Don’t touch the sensor, it will be very hot.
Testing the Circuit:
- After hardware connection, insert the sample sketch into the Arduino IDE.
- Using a USB cable, connect the ports from the Arduino to the computer.
- Upload the program.
- See the results in the serial monitor.
Code for interfacing of MQ-135 gas sensor with Arduino
int sensorValue; int digitalValue; void setup() { Serial.begin(9600); // sets the serial port to 9600 pinMode(13, OUTPUT); pinMode( 3, 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 }
Result:
On serial monitor you can see values of analog pin being detected. Currently in my case they are around about 150 which indicate normal air.
- Normal air returns approximately 100-150
- Alcohol returns approximately 700
- Lighter gas returns approximately 750
How to calibrate MQ 135 Gas Sensor?
Is it necessary to calibrate the gas sensor?
What is dec
DEC is to print the number in decimal
How is the data sent by sensor over the lines, using UART protocol or voltage level ?
Please clarify.
It’s an analog value (resistance, charges depending on the gas concentration)
Voltage level
how u know this statement ” Normal air returns approximately 100-150
Alcohol returns approximately 700
Lighter gas returns approximately 750 ” ? any source or else ?
Hi Richi,
You’ll need to calculate the PPM (parts per million). There’s a graph of this sensor from the manufacturer which shows logarithmic decay of each substance.
There are some videos online that derive this formula. Just search for calculate CO2 ppm MQ135
It will convert the arbitrary adc number to a PPM for one of the gasses it can measure.
can I used this sensor just for detecting Co2?
No you can sense a few different gasses (look up the specs)
can I used this sensor just for detecting Co2? please gv me the answer by email
Hi, why is my reading so low ~ 20+ only??
in my case, as i was using a microcontroller without 5v output, i had the sensor connected to A0 and to an external battery…. and was not connecting the ground to the board… once i did that numbers went up… (since i had to modify the connections it got messed up all became loose, and since i probably won’t be using the sensor for anything… i put it away in its bag…)
i must add that i thought it would read 2 different values, one for CO2 and another set for CHx (hydrocarbides? hidrocarburs in my language)
Your schematic does not show the load-resister. Is this an omission or is the resistor not necessary? Thanks for the tutorial!
Can i use this sensor with 3.3V ?
Hi,
Thanks for code and descriptions. Can you tell me what is the output value will come for detection of amonia gas?
If we are using this sensor to detect many gases,then how we will know their percentage level seperately
How do I enter ammonia values
Sir
But you are not described about the digital pin
Plz tell me about how to use digital pin
digital pin only provide high signal and low signal on detection of gas and you can simply use digitalpin mode function to read this high and low signal. it is very easy
how could i differentiate multiple gas level from the same input A0?
I interfaced aurdino with mq135 sensor, I got the output displaying in serial monitor.I Want to push these values to p10 led board using Arduino throw hub12 port How is it possible…?