Search

How to use an MQ2 gas sensor with arduino

This sensor use a heater inside and a electrochemical sensor  from SnO2.  According to MQ2  datasheet it is used in gas leakage detecting equipments in family and industry applications, is suitable for detecting of LPG, i-butane, propane, methane, alcohol, hydrogen and smoke. The sensor’s conductivity is more higher along with the gas concentration rising. The datasheet is here.

Now  for this project I used an MQ2 shield like this:

MQ2 gas sensorMQ2 gas sensor

It has 4 pins:

Vcc-5V Arduino

Gnd-Gnd arduino

Dout-any digital pin

Aout-any analog pin

The potentiometer has the role in adjusting the sensitivity of the sensor.When you turn to the right like in the video the sensor has its highest sensibility. After that when you rotate to the left you decrease the sensibility(to eliminate false signals like cigar smoke in a room). To a better control you can use the serial monitor and when you reduce sensibility you can test the sensor with a lighter and see in the serial monitor the limit value.

The next program can display the analog value(from analog pin A0) in the serial monitor and through digital pin 2 it power on the led from the pin 13 when the gas it reach a particular value. The led can be replace with a buzzer alarm or anything you want.

 



 

The program is below or you can download from here.

const int gassensor = A0;// with the A0 pin we read the analog value of the sensor

void setup()

{

pinMode(2, INPUT);// for digital signals from the sensor

pinMode(13, OUTPUT);// the LED from pin 13 will be on when sensor detect gas

Serial.begin(9600); //start the comunication with serial port

}

void loop()

{

Serial.println(analogRead(gassensor));

delay(100); // Display value every 0.1 secundes.

if (digitalRead(2)==LOW){//when the sensor is detecting something put the digital output in LOW state

digitalWrite(13, HIGH);// power on the led on pin 13

}

else {

digitalWrite(13, LOW); // if the gas dissapear the led will be powered off

}

}

Please let us in the comment zone any suggestions that you think will improve the article!

If you like the article click the follow button from social media to stay in touch with us!

A video to see how its work is:

Facebooktwitterpinterest

Related posts

Leave a Comment

Show Buttons
Hide Buttons