top of page

Interfacing of MQ2 (gas) sensor with Arduino Uno.


What is a MQ2 (gas) Sensor?


The Gas Sensor (MQ2) module is useful for gas leakage detection (home and industry). It is suitable for detecting H2, LPG, CH4, CO, Alcohol, Smoke or Propane. Due to its high sensitivity and fast response time, measurement can be taken as soon as possible. The sensitivity of the sensor can be adjusted by potentiometer.


Material Required:


Material Quantity

Arduino Uno 1

MQ2 (gas) Sensor 1

Jumper cables 6

LED 1



Pinout Diagram:



Circuit Diagram:


Connect the pulse sensor with Arduino as follows:


GND pin of MQ2 (gas) sensor to GND of Arduino

VCC of MQ2 (gas) sensor to 5V of Arduino

A0 of MQ2 (gas) sensor to A0 of Arduino

D0 of MQ2 (gas) sensor to D2 of Arduino. If needed.


After that, connect the LED to pin 13 and GND of Arduino as shown in the figure below. The LED will blink according to the MQ2 (gas) sensor.




Tested Programming Code:


Const int gaspin = A0;

float sensorValue; //variable to store sensor value


void setup()

{

pinMode(gaspin,INPUT);


Serial.begin(9600); // sets the serial port to 9600 Serial.println("Gas sensor warming up!"); delay(20000); // allow the MQ-6 to warm up


}

void loop()

{

sensorValue = analogRead(gaspin); // read analog input pin 0

Serial.print("Sensor Value: ");

Serial.print(sensorValue);


if(sensorValue > 300)

{

Serial.print(" | Smoke detected!");

}

Serial.println("");

delay(2000); // wait 2s for next reading

}


Precautions:



1. Double check the connections before powering on the circuit.

2. Don’t use loose jumper cables.

3. Check whether proper board is selected from Arduino IDE.

4. Ensure proper placement of MQ2 (gas) Sensor for correct working.

5. Don’t lose hope if Sensor does not run properly for the first time, try again.


Conclusion:


Once your sketch is running, you have to open your serial monitor. There you can see the value of gas present in air by the sensor.





GET IN TOUCH

We'd love to hear from you

bottom of page