Project 16: Is there gas leakage

1.Introduction

This lesson is very much the same as the above one. The only difference is that we use a different gas sensor. The experiment principle can also be directly applied to factories in detecting harmful gases.

2.Hardware required

  • EASY plug controller Board x1

  • USB cable x1

  • EASY plug cable x2

  • Lighter x1 (not included)

  • EASY plug Piranha LED Module x1

  • EASY plug Analog Gas Sensor x1

Below is a brief introduction of this analog gas sensor.

This analog gas sensor - MQ2 is used in gas leakage detecting equipment in consumer electronics and industrial markets. This sensor is suitable for detecting LPG, I-butane, propane, methane, alcohol, Hydrogen and smoke. It has high sensitivity and quick response. In addition, the sensitivity can be adjusted by the potentiometer. Below are its specifications:

  • Power supply: 5V

  • Interface type: Analog

  • Wide detecting scope

  • Quick response and High sensitivity

  • Simple drive circuit

  • Stable and long lifespan

  • Size: 56*20mm

  • Weight: 8g

3.Connection Diagram

Now, connect the LED module to the D10 port of the controller board, and gas sensor to IIC port using the EASY plug cables.

4.Sample Code

Connect the board to your PC using the USB cable; copy below code into Arduino IDE, and click upload to upload it to your board.

int gas_din=18;
int gas_ain=A5;
int led=10;
int ad_value;

void setup()
{
  pinMode(led,OUTPUT);
  pinMode(gas_din,INPUT);
  pinMode(gas_ain,INPUT);
  Serial.begin(9600);
}

void loop()
{ 
  ad_value=analogRead(gas_ain);
  if(digitalRead(gas_din)==LOW)
  { 
    digitalWrite(led,HIGH);
    Serial.println("Gas leakage");
    Serial.println(ad_value);
  }
  else
  {
    digitalWrite(led,LOW);
    Serial.println("Gas not leak");
  }
  delay(500);
}

5.Result

After all the above are done, you can see the power LED1 on the module is on, for LED2 on the module, you need to use a screw driver to adjust the knob for LED2 to be in a “off” state when it’s about to be turned on. Now, the piranha LED is off and open serial monitor, you can see it displays “Gas not leak”; then, turn on the lighter and turn off after a little while, place the lighter mouth into the sensor sensing area, you can see LED2 on the module and piranha LED are both on, and serial monitor displays “Gas leakage”.