Arduino Gas leakage detection and SMS alert MQ-2 sensor
Table of Contents
Description:
This project is based on Gas leakage detection or smoke detection using the MQ-2 gas/smoke sensor, Arduino Uno, and GSM sim900A module. This project is used for the Gas/Smoke detection, once the Gas/Smoke is detected a message is sent to the owner. This Project can be installed in kitchens, Rooms, etc.
In my previous project, I used the same sensor with the Solenoid valve. So whenever there was a gas leakage the solenoid valve would close automatically. If you want to control the gas flow using a solenoid valve then you should definitely watch my tutorial. Which provides the best protection.
The Gsm sim900A and MQ-2 sensor interfacing with Arduino Uno or Mega is really simple which i will explain in a minute.
In this tutorial, I will show you have to make your own Smoke/ gas leakage detection and SMS alert system. This is an automatic system, a message will be sent automatically whenever the gas or smoke is detected.
Amazon Links:
Arduino Nano USB-C Type (Recommended)
*Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
GSM SIM900A Module:
The GSM SIM900A module is already explained in my previous tutorials. You can check out these two projects.
RFID and GSM based students attendance system with SMS alert:
MQ-2 Sensor:
The MQ-2 sensor is capable of detecting a wide range of gases including carbon monoxide, alcohol, methane, hydrogen, isobutene, liquefied petroleum gas, propane, and smoke. For the easy interfacing, the MQ-2 sensor Module is provided with 4 male headers so that it can be easily interfaced with the Arduino Uno or Mega using male to female type jumper wires.
MQ-2 Sensor Pinouts:
As you can see The 4 male header pins are labeled with
A0…
D0…
Gnd…
and Vcc…
A0 pin is the Analog output of the MQ-2 sensor module, and this pin should be connected with the analog pin of the Arduino Uno or Mega.
D0 is the digital output in the form of 5v or GND. This sensor module also has a variable resistor which can be used to change the detection level.
The MQ-2 Sensor Module GND pin should be connected with the Arduino Uno or Mega ground.
While Vcc of the MQ-2 sensor module will be connected with the 5v pin of the Arduino Uno or Mega.
MQ-2 Sensor Applications:
They are used in gas leakage detecting equipment in family and industry, are suitable for detecting of LPG, i-butane, propane, methane, alcohol, Hydrogen and smoke.
Arduino GAS Leakage Detection Circuit Diagram:
This schematic is designed in cadesoft eagle, if you want to learn how to make schematics and PCB, then you can watch my tutorial “Click Here link 3”. The MQ-2 Sensor Module and gsm sim900A or Sim900D modules interfacing with Arduino /Mega is very simple.
As you know my friends GSM sim900A module communicates with Arduino using Serial communication so that’s why we have to define pins for the tx and Rx pins of the GSM module. Well, you also know that Arduino has a serial port which is on pin number0 and pin number1.
If you have watched my previous tutorials on YouTube, you will know, I always say never use the Arduino’s default serial port for the communication with other devices, you can define another serial port on any digital pins. Now the question is if we will not use the Arduino’s default serial port then how we will connect the gsm module? well no worries at all, we can define multiple serial ports using the SoftwareSerial library which I will explain in the programming.
As you can see in the circuit diagram above the tx pin of the sim900A is connected with pin7 of the Arduino, the rx Pin of the sim900A is connected with pin8 of Arduino and GND is connected with the GND of Arduino. a power supply is connected with sim900A ideal voltage is 4.7v to 5v.
The MQ-2 sensor module VCC pin will be connected with the Arduino’s 5v, its Ground pin will be connected with the Arduino’s Ground and its A0 pin will be connected with the Arduino’s A1.
Gas leakage detection Arduino Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
#include <SoftwareSerial.h> SoftwareSerial SIM900(7, 8); // gsm module connected here String textForSMS; int smokeS = A1; // smoke / gas sensor connected with analog pin A1 of the arduino / mega. int data = 0; void setup() { randomSeed(analogRead(0)); Serial.begin(9600); SIM900.begin(9600); // for sim900D 19200. while enter 9600 for sim900A pinMode(smokeS, INPUT); } void loop() { data = analogRead(smokeS); Serial.print("Smoke: "); Serial.println(data); if ( data > 230) // { textForSMS = "\nGas Or Smoke Detected"; sendSMS(textForSMS); Serial.println(textForSMS); Serial.println("message sent."); delay(5000); while(1) { } } } void sendSMS(String message) { SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message delay(1000); SIM900.println("AT + CMGS = \"+923171956677\""); // recipient's mobile number, in international format delay(1000); SIM900.println(message); // message to send delay(1000); SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26 delay(1000); SIM900.println(); delay(100); // give module time to send SMS // SIM900power(); // turn off module } |
How i can stop continue sms
check whether your PIR sensor gives 0 or 1 as the output. then accordingly adjust the if condition.
Sir could you provide the complete program code
Sir can you please provide me with the program code and complete circuit diagram of lpg gas detector sms alert with GSM