Professional Documents
Culture Documents
Code:: LPG Sensor Using Arduino + Code
Code:: LPG Sensor Using Arduino + Code
"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;
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();
}