In this tutorial, we will learn how to create an LPG gas leakage detector using Arduino. I used the MQ-2 sensor module for this purpose. The sensor is sensitive to LPG, alcohol, propane, hydrogen, methane, and carbon monoxide. When the LPG gas level reaches or exceeds ten, the buzzer will emit a beeping sound. Additionally, the 1602 LCD display shows detailed information about the gas leak value.
You can watch the following video or read the written tutorial below.
Overview
The MQ2 Gas sensor is used to detect the LPG gas leak. The MQ-2 Sensor can detect not only LPG but also gases such as Alcohol, Propane, Hydrogen, Methane, and Carbon Monoxide. Therefore, it is suitable for detecting all these gases. When the LPG gas leakage reaches the danger level, the 5V buzzer emits a continuous beeping sound until it returns to a normal state, and the LPG gas level in the air in that station is shown on the LCD display.
Components Needed
Before we begin, make sure you have gathered all the necessary components. The purchase links are in the description of my YouTube video.
- MQ-2 Gas Sensor
- Arduino Uno
- I2C interface 16×2 LCD display module
- Two 18650 Li-ion Battery.
- Two cell 18650 Li-ion battery holder
- Active Buzzer (5V)
- Jumper wires
Understanding the MQ2 Gas Sensor
The MQ-2 gas sensor is a versatile and widely used sensor in various applications due to its ability to detect multiple gases. This sensor is particularly popular for detecting combustible gases, smoke, and various volatile organic compounds (VOCs). The MQ-2 operates on the principle of chemiresistive changes in its sensing material when it comes in contact with the target gases. It consists of a tin dioxide (SnO2) sensing layer, a heating element, and a ceramic substrate.
The MQ-2 sensor can detect a range of gases, including LPG, propane, methane, alcohol, smoke, and more. It is commonly utilized in gas leakage detectors, home automation systems, and air quality monitoring devices. The sensor’s heating element ensures that it operates optimally at a specific temperature.
The output of the MQ-2 sensor is an analog voltage signal that varies based on the concentration of the detected gas. The sensor has four pins: VCC (power supply), GND (ground), DOUT (digital output), and AOUT (analog output). The DOUT pin provides a digital signal (high or low) that indicates whether the gas concentration has crossed a set threshold. The AOUT pin delivers an analog voltage proportional to the gas concentration, allowing for more precise measurements.
In summary, the MQ-2 gas sensor is a valuable component for gas detection applications, offering both digital and analog outputs to suit various monitoring needs.
I2C interface 16×2 LCD display module
The I2C interface 16×2 LCD display module is a compact and efficient solution for incorporating visual output into electronics projects. This module integrates a 16×2 character LCD display with an I2C (Inter-Integrated Circuit) interface, simplifying the connection process and reducing the number of required pins. The 16×2 LCD display means it can show up to 32 characters in a 2-line format.
This LCD module is designed for ease of use, making it ideal for hobbyists, students, and professionals alike. Its I2C interface means it communicates using a two-wire serial interface, comprising a clock line (SCL) and a data line (SDA). This simplifies wiring and allows for efficient communication with microcontrollers or other devices.
The output pins of the I2C interface 16×2 LCD display module typically include VCC (power supply), GND (ground), SDA (data line), and SCL (clock line). The VCC and GND pins provide the necessary power for the module, while the SDA and SCL pins handle the serial data and clock signals, respectively.
This LCD module is commonly used in various applications, such as digital devices, IoT projects, and DIY electronics. Its compact size and I2C compatibility make it a convenient choice for projects where space and simplicity are crucial considerations. Overall, the I2C interface 16×2 LCD display module is a versatile display solution that combines functionality and ease of integration.
Circuit Diagram
The circuit diagram of this project is actually quite simple. As depicted in the circuit diagram, the procedure for connecting the module wires is further explained below. You can download this circuit diagram. For that, click on the image below and download it.
Connecting the MQ-2 Sensor to the Arduino UNO board
The output of the MQ-2 sensor is an analog voltage signal that varies based on the concentration of the detected gas. Only VCC, GND, and A0 of the MQ-02 sensor are connected to the Arduino board.
In this way connect the MQ2 sensor to the Arduino board,
- Connect the VCC (power) pin of the MQ2 sensor to the 5V pin on the Arduino.
- Connect the GND pin of the MQ2 sensor to the GND pin on the Arduino.
- Connect the analog signal (A0 pin) from the MQ2 sensor to an analog pin A0 on the Arduino.
Connecting the I2C interface 16×2 LCD display module to the Arduino UNO board
The output pins of the I2C interface 16×2 LCD display module typically include VCC (power supply), GND (ground), SDA (data line), and SCL (clock line). The VCC and GND pins provide the necessary power for the module, while the SDA and SCL pins handle the serial data and clock signals, respectively.
in this way connect the 1602 LCD Display to the Arduino board,
- Connect the VCC (power) pin of the LCD Display to the 5V pin on the Arduino.
- Connect the GND (power) pin of the LCD Display to the GND pin on the Arduino.
- Connect the SDA pin of the LCD Display to an analog pin A4 on the Arduino.
- Connect the SCA pin of the LCD Display to an analog pin A5 on the Arduino.
Connecting the Active Buzzer to the Arduino UNO board
An active buzzer, operating at 5V, is a commonly used electronic component that produces audible sounds or beeps when an electrical signal is applied. It consists of a piezoelectric element and an internal oscillator circuit. Unlike passive buzzers, active buzzers have an integrated oscillator, allowing them to produce sound without external oscillation.
in this way connect the 5V Active Buzzer to the Arduino board,
- Connect the 5V active buzzer (+) to the digital pin 13 of the Arduino board.
- Connect the 5V active buzzer (-) to the digital GND pin of the Arduino board.
Connecting the two 18650 li ion battery holder to the Arduino UNO board.
- Connect the Red wire (+) of the battery holder to the VCC pin of the Arduino board.
- Connect the Black wire (-) of the battery holder to the GND pin of the Arduino board.
Upload the Arduino Code
Before uploading the code, download the Liquid Crystal i2c Library and add it to the Arduino IDE. The Newping Library should be added to the Library of the Arduino IDE. Otherwise the code cannot be uploaded. Download from below.
The file type of the Liquid Crystal i2c Library you downloaded is a zip file. Follow the steps below and add the Zip file to the Arduino IDE.
In the Arduino IDE, navigate to Sketch > Include Library > Add . ZIP Library. At the top of the drop-down list, select the option to “Add . ZIP Library”.
After that, copy the following Arduino code and paste it into the new sketch in the Arduino IDE. Select the board and port and upload the code. If this is difficult to do, watch a tutorial video.
You can download the Arduino code and open it directly through the Arduino IDE. Click the Download button below to download the Arduino code
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int buzzer = 13;
int GASA0 = A0;
int gasvalue;
void setup() {
lcd.init();
lcd.init();
lcd.backlight();
Serial.begin(9600);
pinMode(buzzer, OUTPUT);
lcd.setCursor(3,0);
lcd.print("Welcome To");
lcd.setCursor(1,1);
lcd.print("ROBOTLK ARDUINO");
delay(5000);
}
void loop() {
int analogSensor = analogRead(GASA0);
int gasvalue=(analogSensor-50)/35;
lcd.setCursor(0,0);
lcd.print("GAS Level:");
lcd.setCursor(10,0);
lcd.print(gasvalue);
lcd.setCursor(12,0);
lcd.print("%");
if (gasvalue >= 10)
{
lcd.setCursor(0,1);
lcd.print("DANGER");
tone(buzzer, 1000, 100000);
}
else
{
lcd.setCursor(0,1);
lcd.print("NORMAL");
noTone(buzzer);
}
delay(500);
lcd.clear();
}
Code language: PHP (php)
Change the brightness of the LCD display characters by the variable resistor of the i2c module behind it.
Change the sensitivity of the MQ2 sensor using the variable resistor.
Check if it works properly
I use a propane lighter to check if this works properly. Place the propane lighter near the MQ-2 sensor and activate it. The buzzer then beeps when the gas level reaches ten or more. It only stops when the gas level drops below ten.
Conclusion
In conclusion, the LPG gas leakage detection system using the MQ-2 sensor, Arduino UNO board, I2C interface 16×2 LCD display module, and an active buzzer presents a comprehensive and effective solution for monitoring and alerting against potential gas leaks. The integration of these components, facilitated by careful wiring and proper library utilization, enables real-time visualization of gas concentration levels on the LCD display and triggers an audible alert through the buzzer when the gas level surpasses a predefined threshold. The flexibility of the system is enhanced by the inclusion of variable resistors for adjusting both LCD display brightness and MQ-2 sensor sensitivity, providing users with customization options. Through practical testing with a propane lighter, the system demonstrates its ability to respond promptly to elevated gas concentrations, showcasing its reliability in detecting LPG gas leaks. This project serves as a valuable example of combining sensor technology, microcontroller capabilities, and user-adjustable features to create a functional and responsive gas detection system.