In this tutorial, we will learn how to make gas leakage detector. I used the MQ-2 sensor module for this. It is sensitive to LPG, alcohol, propane, hydrogen, methane, and carbon monoxide.
You can watch the following video or read the written tutorial below.
Overview
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. It is not mandatory to use Arduino to make LPG Leakage Detector like this. But it is a good opportunity to learn how to use a sensor and Arduino to code their input, output, and need. This indicates that if the amount of gas leakage is high, the red LED bulb will light up and indicate it to us. Otherwise, the green LED bulb will light up.
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.
- MQ2 Gas Sensor
- Arduino Uno
- LEDs (Red and Green)
- Breadboard and jumper wires
- The power source (USB cable or an external power supply for Arduino)
![gas sensor diagrame](https://robotlk.com/wp-content/uploads/2023/11/Sequence-01.00_00_18_14.Still002-1-1024x576.jpg)
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.
For our Gas Leakage Detector, we’ll focus on detecting LPG.
![gas sensor](https://robotlk.com/wp-content/uploads/2023/11/Sequence-01.00_00_25_05.Still003-1-1024x576.jpg)
Circuit Diagram
The next stage is connecting the electronics. 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 download button below and download it.
![gas sensor diagram](https://robotlk.com/wp-content/uploads/2023/11/Gas-sensor-2-1024x327.png)
Connecting the Components
Connect the MQ2 sensor to the Arduino Uno using jumper wires. Connect the LEDs to the Arduino Uno, ensuring the red LED is designated for high gas levels and the green LED for a safe environment. Here’s a simplified wiring guide.
Connect the MQ2 sensor’s VCC and GND pins to the 5V and GND on the Arduino Uno, respectively. Connect the sensor’s AOUT pin to the A0 analog input on the Arduino.
![gas sensor connecting arduino](https://robotlk.com/wp-content/uploads/2023/11/Sequence-01.00_02_47_05.Still005-1-1024x576.jpg)
Connect the Green LED’s anode to pin 3 on the Arduino and the cathode through the resistor to GND. Connect the Red LED’s anode (longer leg) to pin 4 on the Arduino and the cathode (shorter leg) through the resistor to GND.
![gas sensor connect Arduino](https://robotlk.com/wp-content/uploads/2023/11/Sequence-01.00_03_05_10.Still006-1-1024x576.jpg)
Upload the Arduino Code
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
//Robot Lk YouTube Channel
int sensorPin = A0; // choose the input pin (for GAS sensor)
int R_led = 3; // choose the pin for the Green LED
int G_led = 4; // choose the pin for the Red Led
int read_value; //
int set = 750; // SET THE VALUE ACCORDING TO YOU
void setup(){
pinMode(sensorPin, INPUT);
pinMode(R_led,OUTPUT);
pinMode(G_led,OUTPUT);
}
void loop(){
read_value = (analogRead(sensorPin));
read_value = read_value - 50;
if(read_value<0){read_value=0;}
if(read_value>set){
digitalWrite(R_led, HIGH); // Turn LED on.
digitalWrite(G_led, LOW); // Turn LED off.
delay(1000);
}
if(read_value<set){
digitalWrite(R_led, LOW); // Turn LED on.
digitalWrite(G_led, HIGH); // Turn LED on.
}
delay(100);
}
Adjusting Threshold and Testing
Adjust the threshold value in the code based on the readings you observe when the sensor is in a safe environment. Upload the code to the Arduino Uno and open the Serial Monitor to view gas concentration readings. Test the Gas Leakage Detector by introducing a small amount of gas near the sensor. The red LED should light up if the gas concentration exceeds the threshold.
![gas detecting](https://robotlk.com/wp-content/uploads/2023/11/Sequence-01.00_07_00_14.Still007-1024x576.jpg)
![gas detecting](https://robotlk.com/wp-content/uploads/2023/11/Sequence-01.00_07_32_00.Still008-1024x576.jpg)
Conclusion
In conclusion, this tutorial guides users through the creation of a gas leakage detector using the MQ2 sensor module and Arduino Uno. The MQ2 sensor’s sensitivity to various gases, including LPG, alcohol, propane, hydrogen, methane, and carbon monoxide, makes it a versatile choice for gas detection. The circuit assembly involves connecting the MQ2 sensor and two LEDs to the Arduino Uno, with the red LED signaling high gas levels and the green LED indicating a safe environment.