### LPG sensor using arduino with alarm and cutoff.

A simple LPG sensor using arduino is shown in this article. This circuit indicates the amount of LPG in the air. The circuit  sounds an alarm and trips a relay  when the concentration is above a predetermined level. MQ2 is the gas sensor used in this project. MQ2 is an SnO2 based gas sensor which can sense gases like methane, propane, butane, alcohol, smoke, hydrogen etc. Since LPG primarily contains propane and butane, MQ2 sensor can be used for sensing LPG. The figure below shows the schematic and arrangement of an MQ2 gas sensor.

MQ2 sensor senses the flammable gases by the increase in temperature when they are oxidized by the heating element. Consider the figure given above. If there is any flammable gas present in the sample , the oxidization of the same gas results in increased temperature and the resistance of the sensor resistor will drop. That means more current will flow through the load resistor and so the voltage across it will shoot up.

At normal conditions(no LPG in the air), the sensor resistor will be very high around 850K . So the voltage drop Vout across the load resistor will be around zero. When the sensor is fully exposed to LPG the sensor resistance drops to around 800 ohms and the voltage drop across the load resistance will be around 4.62 volts.  After conversion by the ADC, the digital equivalent of  4.62 volt will be 948 and it is stored in the variable “d” (refer the program ). Figure below shows a graph plotted from the observed parameters.

Actually the graph may not be a straight line. But  here we have to assume it to be a straight line because it is not possible to simulate LPG concentrations other than 0% and 100% with our limited lab facilities. For accurate calibration of the sensor, we need some means to know the precise concentration of the gas in the given environment. Anyway what we have is somewhat enough for our purpose.

The concentration percentage for a given digital output of the ADC can be determined using the following equation. p=d/9.48 where d is the digital output of the ADC and p is the percentage. The equation is obtained by finding the equation of the above graph in the general form y=mx+c. Where m is the slope and c is the y intercept. The full circuit diagram of the LPG sensor using arduino is shown below.

#### Circuit diagram.

Output of the gas sensor is connected to the analog input pin A0 of the arduino. Digital pin 10 of the arduino is used for controlling the buzzer and digital pin 13 used for controlling the relay. The relay used here is a SPDT relay and so it can be used for switching ON or OFF the target device when there is a gas leak. Here the TRIP threshold is set to be 30%. You can set your threshold point in the program. While selecting the threshold point, temperature and humidity effects have to be also considered because MQ2 sensor has good dependence on both. Refer the datasheet of MQ2 gas sensor for more idea.  The complete program of the LPG sensor using arduino is shown below.

#### Program.

```#include<LiquidCrystal.h>
int mq2=A0;
int rel=13;
int buz=10;
int d;
float p;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
pinMode(rel,OUTPUT);
pinMode(buz,OUTPUT);
digitalWrite(rel,LOW);
digitalWrite(buz,LOW);
lcd.begin(16,2);
}
void loop()
{
lcd.setCursor(0,0);
lcd.print("LPG SENSOR");

if(d<60)
{
p=0;
}
else
{
p=(d-60)/9.64;
}
lcd.setCursor(0,1);
lcd.print(p);
lcd.setCursor(5,1);
lcd.print("%");
if(p>=30)
{
digitalWrite(rel,LOW);
digitalWrite(buz,HIGH);
lcd.setCursor(9,1);
lcd.print("TRIP");
}
else
{
digitalWrite(rel,HIGH);
digitalWrite(buz,LOW);
}
delay(500);
lcd.clear();
}
```

#### Notes.

• MQ2 sensor requires a 24 hour preheat for stable operation.
•  The heating coil of the MQ2consumes around150mA and so it is wise to power the coil from a separate source.
• 5V required at other parts of the circuit can be tapped from the arduino board.
• The arduino board can be powered through the 9V power supply jack.

1. what is the use of 60 in the program,moreover in program you have used 9.64 instead of 9.48 why is it so?

2. can you please explain the calculations done in the program.
if(d=30)
{
digitalWrite(rel,LOW);
digitalWrite(buz,HIGH);
lcd.setCursor(9,1);
lcd.print(“TRIP”);

3. Hi thx for the much needed project
can we use MQ-6 or Mq-5 instead of MQ-2