Home ArduinoArduino Code Arduino MQ-2 Gas Sensor example

Arduino MQ-2 Gas Sensor example

The MQ-2 is a fairly low cost sensor that can detect  LPG, i-butane, propane, methane ,alcohol, Hydrogen, smoke. There are a wide variety of shields and modules that can be bought and connected to your Arduino

You can see the sensor in the image below

VCC – 5V
GND – GND
AOUT – Analog pin 0

gas sensor

gas sensor

 

Code

 

[codesyntax lang=”cpp”]

const int analogInPin = 0;
 
int sensorValue = 0;
int count1;
 
void setup() 
{
  Serial.begin(9600); 
}
 
void loop() 
{
 
  count1++;
  // read the analog in value:
  sensorValue = analogRead(analogInPin);            
 
  if(count1==3000)
  {
    count1=0;
 
   Serial.println(sensorValue, DEC);  // prints the value read
  }
}

[/codesyntax]

When this run, open up the serial monitor and you should see something like the following

mq2 output

mq2 output

Link

You can pick up one of these modules from between $3 to $5

KEYES DIY 3 pin MQ2 Smoke Gas Sensor Module for Arduino with Connection Cable Red

SainSmart MQ2 Gas Sensor Module For LPG Propane Hydrogen Arduino Compatible

You may also like