Arduino UNO reads gas sensor MQ-2 with analog output data. If there is a leaking gas, the alarm will sound.
Hardware Requirement
- MQ-2 Gas Sensor Module
- Relay Module
- Alarm Sound Motor AC
- Power supply +5 Volt
- Jumper
Block Diagram
Schematic
Arduino - MQ2 Module Wiring
Arduino - Relay - LED Indikator Wiring
Source Code/Sketch
float vinSensor;
int adc;
byte kedip;
void setup(){
// Serial.begin(9600);
pinMode(8,OUTPUT);
digitalWrite(8,LOW);
pinMode(9,OUTPUT);
digitalWrite(9,LOW);
do{
adc=(analogRead(A0));
vinSensor = adc * (5.0 / 1023.0);
digitalWrite(9,LOW);
delay(100);
digitalWrite(9,HIGH);
delay(100);
}
while(vinSensor > 1.50);
digitalWrite(9,LOW);
}
void loop(){
adc=(analogRead(A0));
vinSensor = adc * (5.0 / 1023.0);
// Serial.println(vinSensor);
// untuk menampilkan hasil pembacaan sensor hilangkan
// tanda komentar pada serial
// kepekaan pembacaan sensor dapat di sesuaikan dengan
// merubah nilai perbandingan 1.5V
if (vinSensor > 1.5){
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(1000);
do{
adc=(analogRead(A0));
vinSensor = adc * (5.0 / 1023.0);
}
while(vinSensor > 1.00);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
}
if (kedip<20){
digitalWrite(9,HIGH);
}
else if(kedip<200){
digitalWrite(9,LOW);
}
else{
kedip=0;
}
kedip++;
delay(10);
}
int adc;
byte kedip;
void setup(){
// Serial.begin(9600);
pinMode(8,OUTPUT);
digitalWrite(8,LOW);
pinMode(9,OUTPUT);
digitalWrite(9,LOW);
do{
adc=(analogRead(A0));
vinSensor = adc * (5.0 / 1023.0);
digitalWrite(9,LOW);
delay(100);
digitalWrite(9,HIGH);
delay(100);
}
while(vinSensor > 1.50);
digitalWrite(9,LOW);
}
void loop(){
adc=(analogRead(A0));
vinSensor = adc * (5.0 / 1023.0);
// Serial.println(vinSensor);
// untuk menampilkan hasil pembacaan sensor hilangkan
// tanda komentar pada serial
// kepekaan pembacaan sensor dapat di sesuaikan dengan
// merubah nilai perbandingan 1.5V
if (vinSensor > 1.5){
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
delay(1000);
do{
adc=(analogRead(A0));
vinSensor = adc * (5.0 / 1023.0);
}
while(vinSensor > 1.00);
digitalWrite(8,LOW);
digitalWrite(9,LOW);
}
if (kedip<20){
digitalWrite(9,HIGH);
}
else if(kedip<200){
digitalWrite(9,LOW);
}
else{
kedip=0;
}
kedip++;
delay(10);
}
How it Works
1. Connect the Arduino with Peripherals needed
2. Plug in the Power Source on the device
3. Compile and upload the script program above to your arduino
4. First wait until the MQ-2 sensor is ready, the LED blinks on and off with a 100 ms of delay.
5. If the sensor is ready then the LED indicator goes off longer than when LED is on.
6. If you want to try you can give gas on the sensor surface using Gas lighters.
Video for Project V - 18. Gas Leakage Alarm using MQ-2 Sensor (Arduino Based)
Required File
I've never personally used an LPG detector, but from what I've learned from my programming and research, it seems like a crucial device for homes that use LPG gas. I can imagine it providing a sense of security and peace of mind, knowing that potential gas leaks will be detected and alerted to promptly.
ReplyDelete