This project demonstrates how to design and build an intelligent gas leakage detection and automatic exhaust fan system using an Arduino Uno and an MQ-2 gas sensor. The system detects potentially dangerous concentrations of combustible gases, activates a buzzer alarm and automatically switches on an exhaust fan to improve ventilation.
1. Introduction
Gas leakage is a major safety concern in homes, restaurants, laboratories and industries where LPG, methane and other combustible gases are used.
A leaking gas cylinder or damaged gas pipe can allow gas to accumulate in an enclosed space. If the gas reaches a dangerous concentration, a spark or flame may cause a fire or explosion.
This project introduces an Arduino-based gas leakage detection system that uses the MQ-2 gas sensor to monitor the surrounding air.
When the sensor detects gas above a programmed threshold, the Arduino automatically:
- Activates a buzzer to warn occupants.
- Switches on an exhaust fan through a relay module.
- Continues monitoring the gas concentration.
- Switches off the alarm and fan when the detected level falls below the reset threshold.
Project objective: To develop an affordable electronic system that detects gas leakage and automatically activates an exhaust fan and warning alarm.
2. How the System Works
The MQ-2 sensor detects combustible gases and produces an electrical signal corresponding to the detected gas concentration.
The Arduino Uno reads the sensor’s analogue output through its analogue input pin A0.
When the reading exceeds the programmed threshold, the Arduino activates the buzzer and relay module. The relay switches on the exhaust fan.
When the gas concentration decreases below the reset threshold, the system switches off the alarm and fan.
3. Materials and Components Required
The following components are required to construct the project.
| Component | Quantity | Function |
|---|---|---|
| Arduino Uno | 1 | Main control unit |
| MQ-2 gas sensor module | 1 | Detects combustible gases |
| 5V relay module | 1 | Controls the exhaust fan |
| DC exhaust fan (12V) | 1 | Provides ventilation |
| Active buzzer (5V) | 1 | Produces an audible warning |
| Red LED | 1 | Indicates gas leakage |
| Green LED | 1 | Indicates normal conditions |
| 220Ω resistors | 2 | Limit LED current |
| Breadboard | 1 | Circuit assembly |
| Jumper wires | Several | Electrical connections |
| 12V DC power supply | 1 | Powers the exhaust fan |
| USB cable | 1 | Programs and powers Arduino |
4. Circuit Connections and Wiring
The MQ-2 sensor has four commonly available module pins: VCC, GND, AO and DO. This project uses the analogue output (AO) to monitor changes in gas concentration.
Arduino wiring table
| Component | Component pin | Arduino connection |
|---|---|---|
| MQ-2 sensor | VCC | 5V |
| MQ-2 sensor | GND | GND |
| MQ-2 sensor | AO | A0 |
| Relay module | VCC | 5V |
| Relay module | GND | GND |
| Relay module | IN | D8 |
| Buzzer | Positive | D9 |
| Buzzer | Negative | GND |
| Red LED | Anode | D6 through 220Ω |
| Green LED | Anode | D7 through 220Ω |
| LEDs | Cathodes | GND |
Exhaust fan connections
The exhaust fan is powered by a separate 12V DC supply.
- Connect the positive terminal of the 12V supply to the relay COM terminal.
- Connect the relay NO terminal to the positive terminal of the exhaust fan.
- Connect the negative terminal of the fan to the negative terminal of the 12V supply.
When the relay activates, COM connects to NO, allowing the fan to operate.
Important: The fan supply must be appropriate for the fan’s voltage and current rating. Do not connect a 12V fan directly to an Arduino output pin.
5. Arduino Source Code
The following program monitors the MQ-2 sensor and controls the alarm, indicator LEDs and exhaust fan.
// GAS LEAKAGE DETECTION AND AUTOMATIC EXHAUST SYSTEM
// Arduino Uno + MQ-2 Sensor
const int gasSensor = A0;
const int relayPin = 8;
const int buzzer = 9;
const int redLED = 6;
const int greenLED = 7;
// Adjust these values after testing
const int gasThreshold = 400;
const int resetThreshold = 350;
// Most relay modules are active LOW.
// Change these values if your module is active HIGH.
const int RELAY_ON = LOW;
const int RELAY_OFF = HIGH;
bool gasDetected = false;
void setup() {
Serial.begin(9600);
pinMode(relayPin, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
digitalWrite(relayPin, RELAY_OFF);
digitalWrite(buzzer, LOW);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
Serial.println("Gas Detection System Ready");
}
void loop() {
int gasValue = analogRead(gasSensor);
Serial.print("Gas Sensor Reading: ");
Serial.println(gasValue);
// Detect gas leakage
if (gasValue >= gasThreshold) {
gasDetected = true;
}
// Reset after the reading falls sufficiently
if (gasValue <= resetThreshold) {
gasDetected = false;
}
if (gasDetected) {
digitalWrite(relayPin, RELAY_ON);
digitalWrite(buzzer, HIGH);
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW);
Serial.println("WARNING! GAS DETECTED");
Serial.println("EXHAUST FAN ACTIVATED");
} else {
digitalWrite(relayPin, RELAY_OFF);
digitalWrite(buzzer, LOW);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
Serial.println("NORMAL AIR CONDITION");
}
delay(500);
}
Understanding the program
analogRead(gasSensor)reads the analogue signal from the MQ-2 sensor.gasThresholdspecifies the reading at which the alarm is activated.resetThresholdprevents rapid switching when readings fluctuate around the activation threshold.digitalWrite(relayPin, RELAY_ON)activates the relay and exhaust fan.digitalWrite(buzzer, HIGH)activates the audible alarm.- The red LED indicates a detected gas condition.
- The green LED indicates normal operation.
Note: The values 400 and 350 are illustrative analogue readings, not universal gas concentration limits. Calibrate the system using suitable reference equipment. MQ-2 readings are affected by sensor warm-up, temperature, humidity and gas type.
6. How to Assemble the Project
Follow these steps:
- Mount the Arduino Uno on a suitable project board.
- Connect the MQ-2 sensor VCC and GND to the Arduino power terminals.
- Connect the sensor analogue output to Arduino pin A0.
- Connect the relay module input to digital pin D8.
- Connect the buzzer to pin D9.
- Connect the red and green LEDs to pins D6 and D7 through appropriate resistors.
- Connect the 12V exhaust fan through the relay’s COM and NO terminals.
- Upload the Arduino program.
- Open the Serial Monitor and observe the sensor readings.
- Test the response using a safe, controlled testing method.
7. Expected Project Operation
| Condition | Red LED | Green LED | Buzzer | Exhaust fan |
|---|---|---|---|---|
| Normal condition | OFF | ON | OFF | OFF |
| Gas above threshold | ON | OFF | ON | ON |
| Gas level decreases below reset | OFF | ON | OFF | OFF |
The project provides both visual and audible warnings while automatically controlling ventilation.
8. Applications of the Project
The gas leakage detection and automatic exhaust system can be adapted for use in:
- Domestic kitchens.
- School science laboratories.
- Restaurants and hotels.
- LPG storage areas.
- Small industrial workshops.
- Gas cylinder storage facilities.
- Research and STEM demonstration projects.
9. Advantages of the Project
- Automatic operation: Detects gas and activates ventilation without requiring manual intervention.
- Low-cost construction: Uses affordable and readily available electronic components.
- Early warning: Provides audible and visual alerts when sensor readings exceed the set threshold.
- Expandable design: Additional features such as an LCD display, GSM module or Wi-Fi monitoring can be incorporated.
- Educational value: Demonstrates programming, electronic sensing, automation and control systems.
10. Possible Project Improvements
The basic system can be upgraded to make it more advanced.
| Upgrade | Function |
|---|---|
| 16×2 LCD display | Displays sensor readings and system status |
| ESP32 Wi-Fi module | Sends gas alerts to a connected dashboard |
| GSM SIM800L | Sends SMS notifications |
| IoT dashboard | Allows remote monitoring |
| Temperature sensor | Monitors environmental temperature |
| Battery backup | Provides backup power during outages |
11. Project Testing and Evaluation
The project should be evaluated by observing how the system responds to different sensor readings.
| Test | Expected observation |
|---|---|
| Power on the Arduino | Green LED turns ON |
| Normal air conditions | Fan and buzzer remain OFF |
| Sensor reading exceeds threshold | Red LED and buzzer turn ON |
| Gas reading falls below reset threshold | Alarm and fan turn OFF |
| Disconnect the sensor | System fault should be identified during further development |
Record the sensor readings under different controlled conditions and compare the system’s response.
12. Safety Precautions and Limitations
The MQ-2 is a low-cost semiconductor gas sensor suitable for educational demonstrations and experimental monitoring. It is not a certified life-safety gas detector.
- Do not use this prototype as the sole protection against gas leakage.
- Do not deliberately release LPG or methane in an enclosed room to test the system.
- Use approved calibration methods and controlled testing equipment.
- The MQ-2 requires an appropriate preheating period and calibration.
- Keep the sensor away from water, excessive heat and direct flames.
- Use a properly rated DC relay and fan.
- Do not operate ordinary electrical switching equipment in a potentially explosive atmosphere. A relay or fan can itself produce sparks. Professional hazardous-area-rated equipment and installation are required for real gas installations.
- Do not assume that switching on an ordinary exhaust fan makes a leaking gas installation safe. Follow emergency procedures, avoid operating electrical switches, leave the area and contact emergency services or a qualified gas technician.
13. Conclusion
The Gas Leakage Detection and Automatic Exhaust Fan System using Arduino and the MQ-2 sensor is an excellent STEM and electronics project that demonstrates how sensors, microcontrollers and actuators can work together to address a real-world problem.
By combining gas detection, automatic ventilation control and an audible warning system, learners can explore practical applications of embedded systems, programming and automation.
The project can also serve as a foundation for developing more advanced IoT-based gas monitoring systems using ESP32, GSM communication and real-time monitoring dashboards.







