Interfacing of MQ135 Gas Sensor with Arduino

MQ135 gas sensor interfacing with Arduino Uno

Interfacing of MQ135 Gas Sensor with ArduinoIn 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

Vcc      Supply (5V)

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

Interfacing of MQ-135 Gas Sensor with Arduino

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:

  1. After hardware connection, insert the sample sketch into the Arduino IDE.
  2. Using a USB cable, connect the ports from the Arduino to the computer.
  3. Upload the program.
  4. 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); 
digitalWrite(13, HIGH);
digitalWrite(13, LOW);
Serial.println(sensorValue, DEC); // prints the value read
Serial.println(digitalValue, DEC);

delay(1000); // wait 100ms for next reading



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

26 thoughts on “Interfacing of MQ135 Gas Sensor with Arduino”

  1. 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.

  2. 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…)

  3. 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)

  4. Your schematic does not show the load-resister. Is this an omission or is the resistor not necessary? Thanks for the tutorial!

  5. Hi,
    Thanks for code and descriptions. Can you tell me what is the output value will come for detection of amonia gas?

    • 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

  6. 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…?


Leave a Comment