In this article, we are going to learn how to interface MQ2 Gas Sensor with Arduino. MQ2 is basically a general purpose gas sensor (similar to MQ5) which can sense a broad range of gases like LPG, Butane, Methane(CH4), Hydrogen and in addition to these gases MQ2 is sensitive to smoke as well.

MQ2_Gas_Sensor_Module

In a previous article, we have wrote a tutorial on Interfacing MQ5 Gas sensor to Arduino. Both MQ5 and MQ2 are basically gas sensors but their range of sensing different gas levels vary. For example, MQ5 can sense LPG in a broader range of 200 ppm to 10000 ppm, where as the range of MQ2 for LPG is short and is from 5000 ppm to 10000 ppm. Similarly MQ2 is sensitive to smoke where as MQ5 is not that sensitive to smoke. So we can not choose MQ5 gas sensor to design a smoke alarm or smoke involving applications. MQ2 can sense methane(CH4) upto 20000 ppm where as MQ5 can sense CH4 only upto 10000 ppm. The difference between MQ5 and MQ2 therefore lies in its range of values. We choose the right sensor based on the application requirement; say for example – We can not choose MQ2 for sensing low levels of LPG in the range of 700 ppm because MQ2 is insensitive low levels of LPG (its range begins at 5000 ppm and extends to 10000 ppm). So for applications to sense low levels of LPG, MQ5 is the ideal choice as it can sense values starting from 200 ppm.

I hope you got an idea how to choose sensors in designing practical applications. Lets come to our article subject – interfacing MQ2 to Arduino. The process of interfacing MQ2 to arduino is very very similar to that of interfacing MQ5 to arduino! There is no change in essentials of circuit diagram (except for replacing MQ5 module with MQ2 module) and the arduino program is same as well. We can read outputs either as digital value (using digital out) or as analog value (using analog out)

So here are our circuit diagrams!

Interfacing MQ2 to Arduino using Digital Out

Interface_MQ2_Digital_Out

The Program!
int sensor=7;
int gas_value;
void setup()
{

pinMode(sensor,INPUT);
Serial.begin(9600);

}

void loop()
{

gas_value=digitalRead(sensor);
Serial.println(gas_value);
}

 

Interfacing MQ2 to Arduino using Analog Out

Interface_MQ2_Analog_Out

 

The Program
float sensor=A0;
float gas_value;
void setup()
{

pinMode(sensor,INPUT);
Serial.begin(9600);

}

void loop()
{

gas_value=analogRead(sensor);
Serial.println(gas_value);
}

So that’s all about interfacing MQ2 gas sensor to Arduino! If you have any doubts regarding this article, feel free to ask in comments section!

We have created a Gas Leakage Detector Application using Arduino and MQ5 sensor – you can build that application if you are interested! You can also try your hand to build our Big List of Arduino Projects – which has a collection of 100+ cool arduino projects!

Author

4 Comments

  1. hi sir i really apritate for your guidance.but i confused one thing i want to design automatic alarm system using pic micro controller writen in micro c what i confused is the output of mq2 smoke sensor is only 0 or 5 that means digital but i want output analog what shal i do?thanks

  2. Rachit Thukral

    How to calculate ppm of the detected gas from the analog value?

    • jojo

      It involves some mathematical calculations. We shall come up with an article on the same very soon!

      • how calculete ppm from analog data from mq sensor?