You are on page 1of 6

LPG GAS leakage detector project using MQ9 gas

sensor

The MQ-2 Gas Sensor


The MQ-2 smoke sensor is the one in the following figure:

The MQ-2 smoke sensor is sensitive to smoke and to the following flammable gases:
 LPG
 Butane
 Propane
 Methane
 Alcohol
 Hydrogen
The resistance of the sensor is different depending on the type of the gas.
The smoke sensor has a built-in potentiometer that allows you to adjust the sensor
digital output (D0) threshold. This threshold sets the value above which the digital pin
will output a HIGH signal.
How does it work?
The voltage that the sensor outputs changes accordingly to the smoke/gas level that
exists in the atmosphere. The sensor outputs a voltage that is proportional to the
concentration of smoke/gas.
In other words, the relationship between voltage and gas concentration is the
following:
 The greater the gas concentration, the greater the output voltage
 The lower the gas concentration, the lower the output voltage

The output can be an analog signal (A0) that can be read with an analog input of the
Arduino or a digital output (D0) that can be read with a digital input of the Arduino.

Working procedure
Check the all component, display and sensor
Then properly connect the sensor and display in Arduino by using
circuit diagram
After connection then start to coding, for this programming use c
language
After coding upload the code in Arduino by using “Arduino idee”
After that check out the project we made

Code for this project


#include <Wire.h>
#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels

#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

int redLed = 12;

int greenLed = 11;

int buzzer = 10;

int smokeA0 = A2;

// Your threshold value

int sensorThres = 250;

void setup() {

if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64

Serial.println(F("SSD1306 allocation failed"));

for(;;);

delay(2000);

display.clearDisplay();

pinMode(redLed, OUTPUT);

pinMode(greenLed, OUTPUT);

pinMode(buzzer, OUTPUT);

pinMode(smokeA0, INPUT);

Serial.begin(9600);

void loop()

display.clearDisplay();
int analogSensor = analogRead(smokeA0);

Serial.print("Pin A0: ");

Serial.println(analogSensor);

display.setTextSize(1);

display.setTextColor(WHITE);

display.setCursor(20, 10);

// Display static text

display.println("Smoke Level");

display.setTextSize(2);

display.setTextColor(WHITE);

display.setCursor(32,30);

display.print(analogSensor);

display.display();

// Checks if it has reached the threshold value

if (analogSensor > sensorThres)

digitalWrite(redLed, HIGH);

digitalWrite(greenLed, LOW);

tone(buzzer, 800, 200);

else

digitalWrite(redLed, LOW);

digitalWrite(greenLed, HIGH);

noTone(buzzer);

delay(100);

}
Discussion:
The MQ-2 Gas sensor can detect or measure gasses like LPG, Alcohol,
Propane, Hydrogen, CO, and even methane. The module version of this
sensor comes with a Digital Pin which makes this sensor to operate even
without a microcontroller and that comes in handy when you are only
trying to detect one particular gas. We can use this project in power plant and
industry for security purpose, it can easily detect the leakage of gasses also
show the level of leakage gasses. So it is very useful and futuristic device for
industrial uses

You might also like