Gas Leakage Detector using Arduino and
GSM Module with SMS Alert and Sound
Alarm.
We have published an LPG Sensor Project using Arduino and MQ5 sensor before – which senses LPG leak and produces a sound alarm. The project also has a relay system which turns ON or OFF a particular device upon gas leak (say we can turn the main electrical supply OFF upon gas leak to prevent fire).
So let’s come to our project!
Objectives of the Project
- Detect Gas Leakage (like LPG leak, Butane leak, Methane leak) or any such petroleum based gaseous substance that can be detected using MQ5 Sensor.
- Setup an SMS based Alert Mechanism and send 3 SMS (3 alert messages) to 2 specified mobile numbers (input inside the Arduino program)
- Produce a sound alarm upon a gas leak and stop the alarm once the gas leak is under control (gas presence in the atmosphere is under normal range)
- Display status in an LCD using a 16×2 LCD module.
Let's begin to build our project – Gas/LPG leakage detector with SMS Alert and Sound Alarm!.
I recommend you read the following tutorials before building this project!
1. Interfacing MQ5 Sensor to Arduino – teaches you how to interface the MQ5 LPG sensor to Arduino and read values using analog or digital out pins of the MQ5 module.
2. Interfacing GSM Module to Arduino – teaches you how to interface a GSM module to Arduino and send/receive text messages using AT Commands.
GSM Module – Buyers Guide – are you looking to buy a GSM module? There are a handful of product variants for GSM module – like SIM900, SIM300, SIM800 etc. We have created this buyers guide to help you select the right GSM module for your project needs.
Circuit Diagram – Gas Leakage Detector using Arduino with GSM Module
Circuit Diagram – Gas Leakage Detector using Arduino without GSM Module
Assemble the circuit as shown in diagram! Important connections are explained below.A photograph of the assembled circuit is shown below.
Note:- The speaker is not shown in this photograph. Anyway you can wire the speaker as shown in circuit diagram and connect it to pin 8 of arduino.
The Program/Code
#include <SoftwareSerial.h> #include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); SoftwareSerial mySerial(9, 10); int sensor=7; int speaker=8; int gas_value,Gas_alert_val, Gas_shut_val; int Gas_Leak_Status; int sms_count=0; void setup() { pinMode(sensor,INPUT); pinMode(speaker,OUTPUT); mySerial.begin(9600); Serial.begin(9600); lcd.begin(16,2); delay(500); } void loop() { CheckGas(); CheckShutDown(); } void CheckGas() { lcd.setCursor(0,0); lcd.print("Gas Scan - ON"); Gas_alert_val=ScanGasLevel(); if(Gas_alert_val==LOW) { SetAlert(); // Function to send SMS Alerts }} int ScanGasLevel() { gas_value=digitalRead(sensor); // reads the sensor output (Vout of LM35) return gas_value; // returns temperature value in degree celsius } void SetAlert() { digitalWrite(speaker,HIGH); while(sms_count<3) //Number of SMS Alerts to be sent { SendTextMessage(); // Function to send AT Commands to GSM module } Gas_Leak_Status=1; lcd.setCursor(0,1); lcd.print("Gas Alert! SMS Sent!"); } void CheckShutDown() { if(Gas_Leak_Status==1) { Gas_shut_val=ScanGasLevel(); if(Gas_shut_val==HIGH) { lcd.setCursor(0,1); lcd.print("No Gas Leaking"); digitalWrite(speaker,LOW); sms_count=0; Gas_Leak_Status=0; }}} void SendTextMessage() { mySerial.println("AT+CMGF=1"); //To send SMS in Text Mode delay(1000); mySerial.println("AT+CMGS=\"+919495xxxxxx\"\r"); // change to the phone number you using delay(1000); mySerial.println("Gas Leaking!");//the content of the message delay(200); mySerial.println((char)26);//the stopping character delay(1000); mySerial.println("AT+CMGS=\"+918113xxxxxx\"\r"); // change to the phone number you using delay(1000); mySerial.println("Gas Leaking!");//the content of the message delay(200); mySerial.println((char)26);//the message stopping character delay(1000); sms_count++; }
Applying ‘gas leak’ using a cigarette lighter – refer photograph
Important Aspects about the Program
When we develop critical systems like Gas Leakage Detector or similar systems like Fire Alarm System, we need to monitor the sensor parameters continuously(24×7). So our system must monitor “gas leak” continuously.This is achieved by scanning the sensor output (digital out of MQ5) continuously inside the ScanGasLevel()subroutine. If you look into the program, the main function loop() has only two subroutines – CheckGas() and CheckShutDown() – which are called repeatedly. CheckGas() – is a subroutine which scans sensor output continuously and take actions if there occurs a ‘gas leak’ at any point of time. CheckShutDown() – is a subroutine to monitor the shut down process and check if status of room is back to normal conditions (no gas leaking).
CheckGas() – is the function which monitors occurrence of a gas leak 24×7. This function fetches the gas level measured by MQ35 (by reading digital out of MQ35 using digitalRead() command) and stores it to the variable Gas_alert_val for comparison. If there is no ‘gas leak’ – the sensor out will be HIGH. If there occurs a ‘gas leak’ at any point of time, the sensor out will immediately change to LOWstatus. The statement if(Gas_alert_val==LOW) checks this and if a gas leak occurs, then an inner subroutine SetAlert() will be invoked.
SetAlert() is the function that controls number of SMS alerts sent to each mobile number loaded in the program. The number of SMS alerts sent can be altered by changing the stopping condition of while loop. The stopping conditionsms_count<3 – means 3 SMS alerts will be sent to each mobile number. If you want to send 5 alerts, just change the stopping condition to sms_count<5 – you got it ? The function to send SMS (using AT Commands) – SendTextMessage() will be called 3 times if SMS alert count is 3. This function SendTextMessage() will be invoked as many times as the number SMS alerts set in the program. In addition to sending SMS alerts, this subroutine also controls the sound alarm. The alarm is invoked using command digitalWrite(speaker,HIGH) – which will activate the speaker connected at pin 8 of arduino.
Note:- We have limited the number of SMS alerts using the stopping condition. Once a gas leak occurs and the set number of SMS alerts has been sent, the system will not send any more SMS! The system assumes that its job is over by sending SMS. Humans has to come and shut down the gas leak problem. After sending alerts, the system will start monitoring Shut Down process. Once the gas leak has been eliminated, system will automatically reactivate its SMS alert settings byresetting the sms_count variable back to zero.
The output after applying ‘gas leak’ is shown in photograph! without GSM Module
The output after applying ‘gas leak’ is shown in photograph!
did i use MQ2 SENSOR EXCEPT MQ5 SENSOR
ReplyDeleteGreat Blog! This post gives a better idea about gas detector. Thanks for the useful information. Please keep sharing!
ReplyDeleteThere are lots of methods to obtain a plumbing professional. You need to employ specialist workers to get the desired support you desire. You can take a look at the jpplumber for much better services. Gas line installation near me
ReplyDeleteNice! your blog is very informative and great. If your are looking for these best Gas Leak Detection London services. Our company provides the best services in United Kingdom.
ReplyDeleteWho else is impressed with how far gas detection systems have come? The LPG Leakage Detector UAE caught my eye – definitely adding it to my home safety wishlist
ReplyDelete