Introduction:

MQ 2 or MQ6 is Gas leakage sensor which consists of 4 pins.
This module is used to detect the gases like butane, propane and LPG.

VCC – 5v DC
GND – ground
D0 – Digital out
A0 – Analog out

Requirements:

Arduino UNO – 1
MQ2/MQ6 – 1
Jumper Wires

Working:

If no gas is sensed then the module give the HIGH pulse on D0 pin. If any gas is detected it produce the LOW pulse on D0 pin. Digital output is more effective then A0(Analog out).
We can use analog also in that case A0 pin (MQ 2) is should be connected to analog pin of arduino. Analog value is used to calculate the ppm of gas sensed if needed to know how much gas is leaking.

Below is the sample program to read the MQ sensor value:

  1. #define Gas 8
  2. void setup()
  3. {
  4.     Serial.begin(9600);
  5.     pinMode(Gas,INPUT);
  6. }
  7. void loop()
  8. {
  9.     if(digitalRead(Gas))
  10.     Serial.println(“No Gas Detected”);
  11.     else
  12.     Serial.println(“Gas Detected”);
  13.     delay(1000);
  14. }

Firstly declared Gas macro with the digital pin number.

In setup() function configured the serial monitor with 9600 baud rate and initialized the gas pin as input.

In loop() function sensor value is read by digitalRead() function, it will return 1 when gas is not detected if condition goes to true and printing on the console as No gas detected and it will return 0 on gas detected if condition goes false and printing on the console as Gas detected. This function is an iteration function and it will be continuously read from sensor with delay of 1 second.

Leave a Reply

Your email address will not be published. Required fields are marked *