Skip to Content

Gas Leakage Detection System

The Gas Leakage Detection Alarm is a vital safety system designed to detect the presence of harmful gases in the environment and alert users immediately when gas levels exceed a predefined threshold. At the core of this system is a gas sensor (such as the MQ-2 or MQ-135), which continuously monitors the air for specific gases like methane, carbon monoxide, or LPG. When the sensor detects gas concentrations above a safe limit, the system triggers an alarm using a buzzer and an LED, providing both audible and visual warnings to ensure prompt action.

The Arduino Uno, a efficient microcontroller, serves as the brain of the system. It processes the data from the gas sensor, compares it to the set threshold, and activates the alarm if dangerous levels are detected. This project is particularly useful in environments where gas leaks pose a significant risk, such as kitchens, industrial settings, or laboratories.

Beyond its practical application, the Gas Detection Alarm is an excellent project for learning about sensor integrationmicrocontroller programming, and real-time alert systems. It highlights how simple electronic components can be combined to create life-saving solutions, making it a valuable addition to any DIY electronics or home safety toolkit. Whether you're a beginner or an experienced maker, this project offers a hands-on way to explore the intersection of electronics and safety.

Components Required

  • Arduino Uno
  • MQ-2 Gas Sensor
  • Buzzer 
  • LED
  • Resistor (10KΩ)
  • Jumper wires
  • Power Supply 
  • Bread Board 

Circuit Diagram

1. Connect the Gas Sensor to Arduino:  

  • VCC → 5V on Arduino 
  • GND → GND on Arduino 
  • A0 (Analog Output) → A0 on Arduino 

2. Connect the Buzzer and LED:  

  • Buzzer 
    • Positive (+) → Digital Pin 8 on Arduino 
    • Negative (-) → GND  on Arduino 
  • LED 
    • Anode (+) → Digital Pin 9 via a 10kΩ Resistor
    • Cathode (-) → GND on Arduino 

3. Power the System:  

  • Use a 5V USB power bank or connect a 9V battery to the VIN pin on Arduino. 

4. Upload the Code  

  • Upload the following code to the Arduino Nano using the Arduino IDE: 


CODE

#define GAS_SENSOR A0  

#define BUZZER 8  

#define LED 9  

#define THRESHOLD 400 // Adjust based on sensor calibration 


void setup() {  

pinMode(BUZZER, OUTPUT);  

pinMode(LED, OUTPUT);  

Serial.begin(9600);  

}

void loop()  {  

​ int gasLevel = analogRead(GAS_SENSOR);  

​ Serial.print("Gas Level: ");  

​ Serial.println(gasLevel);  

​ 

​ if (gasLevel > THRESHOLD) {  

​digitalWrite(BUZZER, HIGH);  

​digitalWrite(LED, HIGH);  

​ Serial.println("Warning! Gas Detected!");  

​ }

​ else {  

​ digitalWrite(BUZZER, LOW);  

​ digitalWrite(LED, LOW);  

​ }  

​ delay(1000); // Update every second  

}  

CODE EXPLANATION

1. Define Pin Connections and Threshold

#define GAS_SENSOR A0 
#define BUZZER 8 
#define LED 9 
#define THRESHOLD 400 // Adjust based on sensor calibration

  • GAS_SENSOR A0: The gas sensor is connected to analog pin A0 on the Arduino. This pin reads the gas concentration level as an analog value.
  • BUZZER 8: The buzzer is connected to digital pin 8. It will sound an alarm when gas levels are too high.
  • LED 9: The LED is connected to digital pin 9. It will light up as a visual warning when gas is detected.
  • THRESHOLD 400: This is the gas concentration level at which the alarm will trigger. You can adjust this value based on your sensor's calibration and the type of gas being detected.

2. Setup Function

void setup() {  
  pinMode(BUZZER, OUTPUT); 
  pinMode(LED, OUTPUT); 
  Serial.begin(9600); 
}
  • pinMode(BUZZER, OUTPUT): Sets the buzzer pin (8) as an output pin, meaning the Arduino will send signals to control it.
  • pinMode(LED, OUTPUT): Sets the LED pin (9) as an output pin, allowing the Arduino to turn it on or off.
  • Serial.begin(9600): Initializes the serial communication at a baud rate of 9600. This allows the Arduino to send data to the Serial Monitor for debugging and monitoring.

3. Loop Function

void loop() {  
  int gasLevel = analogRead(GAS_SENSOR); 
  Serial.print("Gas Level: "); 
  Serial.println(gasLevel); 
  if (gasLevel > THRESHOLD) { 
    digitalWrite(BUZZER, HIGH); 
    digitalWrite(LED, HIGH); 
    Serial.println("Warning! Gas Detected!"); 
  } else { 
    digitalWrite(BUZZER, LOW); 
    digitalWrite(LED, LOW); 
  } 
  delay(1000); // Update every second 
}

The loop() function runs repeatedly, and here's what it does:

   1.​Read Gas Level:

int gasLevel = analogRead(GAS_SENSOR);​     
  • The Arduino reads the gas concentration level from the sensor connected to A0. The value is stored in the variable gasLevel.

     2. Print Gas Level to Serial Monitor:​

Serial.print("Gas Level: ");  
Serial.println(gasLevel);
  • This sends the gas level reading to the Serial Monitor so you can monitor the values in real-time.

      3. Check if Gas Level Exceeds Threshold:

if (gasLevel > THRESHOLD) {
  • The code checks if the gas level is greater than the predefined threshold (400 in this case).

     4. Trigge​r Alarm:

digitalWrite(BUZZER, HIGH);  
digitalWrite(LED, HIGH); 
Serial.println("Warning! Gas Detected!");
  • If the gas level exceeds the threshold:
    • The buzzer is turned on (HIGH).
    • The LED is turned on (HIGH).
    • A warning message ("Warning! Gas Detected!") is printed to the Serial Monitor.

   5. Turn Off Al​arm:

else {  
  digitalWrite(BUZZER, LOW); 
  digitalWrite(LED, LOW); 
}
  • If the gas level is below the threshold:
    • The buzzer is turned off (LOW).
    • The LED is turned off (LOW).

    6. Add a Delay:

delay(1000); // Update every second
  • The program waits for 1 second before repeating the loop. This ensures the system checks the gas level every second, preventing it from reacting too quickly to minor fluctuations.

How It All Works Together

  1. The gas sensor continuously monitors the environment and sends analog data to the Arduino.
  2. The Arduino reads this data and compares it to the threshold value.
  3. If the gas level exceeds the threshold, the buzzer and LED are activated to alert the user.
  4. The system updates every second, ensuring real-time monitoring and response.

OBSERVING FUNCTIONALITY 

  • Expose the sensor to gas (like LPG or alcohol fumes) to test the response. 
  • If gas levels exceed the threshold, the buzzer sounds and the LED lights up. 
  • When gas levels drop below the threshold, the alarm turns off. 

COMMON PROBLEMS AND SOLUTIONS

1. Sensor Not Detecting Gas 

  • Allow the MQ sensor to preheat for 1-2 minutes before testing.  
  • Check if the sensor's analog output (A0) is properly connected to the Arduino.  

2. False Alarms or Unstable Readings 

  • Place the sensor in a well-ventilated  area away from humidity and dust. 
  • Adjust the THRESHOLD value in the code for better sensitivity. 

3. Buzzer Not Sounding When Gas is Detected

  • Verify the buzzer connections to pin 8 and GND. 
  • Test the buzzer separately by applying 5V directly to check if it works.

Conclusion

The Gas Leakage Detection Alarm is a practical and life-saving project that demonstrates how simple electronics and programming can create effective safety systems. By integrating a gas sensor, buzzer, and LED with an Arduino Uno, this system provides real-time monitoring and immediate alerts when harmful gas levels exceed a safe threshold. Whether used in kitchens, laboratories, or industrial settings, this project highlights the importance of sensor integration and microcontroller programming in solving real-world problems. It’s an excellent learning tool for beginners and a valuable addition to any DIY electronics toolkit, showcasing how technology can enhance safety and prevent potential hazards.Happy tinkering!


Comments

SELF REGULATING FAN