Lesson 10 Flammable Gas Detection

Share for us

Introduction

Gas Sensor MQ-2 is a sensor for flammable gas and smoke by detecting the concentration of combustible gas in the air. They are often used in gas detecting equipment for smoke and flammable gasses such as LPG, i-butane, propane, methane and alcohol in household, industry or automobile.

Components

– 1 * SunFounder Uno board

– 1 * USB data cable

– 1 * MQ-2 gas sensor module

– 1 * 4-Pin anti-reverse cable

Experimental Principle

MQ-2 gas sensor applies SnO2 (an oxygen-deficient n-type semiconductor) which has a lower conductivity in the clear air as a gas-sensing material. In an atmosphere where there may be inflammable gases, the conductivity of the gas sensor raises along with the inflammable gas concentration increases. MQ-2 performs a good detection to different inflammable gases such as natural gas, especially sensitive to liquefied gas, propane and hydrogen.

In this experiment, release some combustible gas around the sensor and the value at A0 increases. Once the concentration of the gas exceeds a limit, D0 outputs low level and the corresponding LED will light up. Please note that the sensor needs burn-in time so the readings can be more consistent and reliable.

Experimental Procedures

Step 1: Build the circuit

Step 2: Program (Please refer to the example code in LEARN -> Get Tutorial on our website)

Step 3: Compile

Step 4: Upload the sketch to SunFounder Uno board

Now, ignite a lighter. Then the sensor detects the gas emitted. Thus, the LED on the gas sensor and that attached to pin 13 on the SunFounder Uno board will light up. Also you can see the value at A0 and D0 printed on Serial Monitor.

Note: It is normal that the gas sensor generates heat. Actually, the higher the temperature is, the sensor is more sensitive. 

Code

/******************************************************
* name:Flammable Gas Detection
* function:ignite a lighter. Then the sensor detects the gas emitted. Thus, the LED on the gas sensor and that attached to pin 13 on the SunFounder Uno board will light up. Also you can see the value at A0 and D0 printed on Serial Monitor.
* connection:
* MQ-2 gas sensor Uno R3
* D0 7
* A0 A0
* GND GND
* VCC 5V
*******************************************************/
//Email:support@sunfounder.com
//Website:www.sunfounder.comconst int ledPin = 13;//the led attach to pin13
const int analogPin=A0; //the DO on the Module attach to Pin7 on the SunFounder
const int digitalPin=7; //the D0 attach to pin7
int Astate=0;
boolean Dstate=0;
void setup()
{
  //set the pins state
  pinMode (digitalPin,INPUT);
  pinMode(ledPin,OUTPUT);
  Serial.begin(9600);
}
void loop()
{
  Astate=analogRead(analogPin);//read the value of A0
  Serial.println(Astate); //peint
  Dstate=digitalRead(digitalPin);//read the value of D0
  Serial.println(Dstate);//print
  if( Dstate==HIGH ) //if the value of D0 is HIGH
  {
    digitalWrite(ledPin,LOW);//turn off led
  }
  if( Dstate==LOW)//else
  {
    digitalWrite(ledPin,HIGH);//turn on the led
  }
  delay(200);//delay 200ms
}