Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

LPG sensor using arduino + Code

Author: Electronics Lovers | 13:26 | No Comments |

"To Indicate the amount of Lpg in the Air it will Trip a Relay + Alarm sound to save your
Lives and Environment "
This Sensor is Called MQ2 it can Sense any type of Flammable gases in the Environment
whenever it sense the flammable gas like methane, propane, butane, alcohol, smoke,
hydrogen the Temperature of the sensor will increase and the Resistance of the Sensor
will Drop down from 860k to 800 ohm so the More Current will flow through Load Resistor
and the Arduino A0 pin Will sense the Change and will turn On the Relay to Turn On and Off
the Connected Load .

CODE:
#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()
{
d=analogRead(mq2);
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();
}

You might also like