How to make Gas Leakage Detection and Automatic Exhaust Fan System Using Arduino and MQ-2 Sensor.

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.

Figure 3 - from Smoke Detection Design Using MQ-2 Sensor and
- YouTube
LPG gas leakage detection and protection system | PPTX

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.

ComponentQuantityFunction
Arduino Uno1Main control unit
MQ-2 gas sensor module1Detects combustible gases
5V relay module1Controls the exhaust fan
DC exhaust fan (12V)1Provides ventilation
Active buzzer (5V)1Produces an audible warning
Red LED1Indicates gas leakage
Green LED1Indicates normal conditions
220Ω resistors2Limit LED current
Breadboard1Circuit assembly
Jumper wiresSeveralElectrical connections
12V DC power supply1Powers the exhaust fan
USB cable1Programs 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

ComponentComponent pinArduino connection
MQ-2 sensorVCC5V
MQ-2 sensorGNDGND
MQ-2 sensorAOA0
Relay moduleVCC5V
Relay moduleGNDGND
Relay moduleIND8
BuzzerPositiveD9
BuzzerNegativeGND
Red LEDAnodeD6 through 220Ω
Green LEDAnodeD7 through 220Ω
LEDsCathodesGND

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.

Projek Elektronik Arduino4u.com: 51.Gas leakage with automatic ventilation system

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.
  • gasThreshold specifies the reading at which the alarm is activated.
  • resetThreshold prevents 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

Interfacing Gas Sensor With Arduino : 4 Steps - Instructables
Arduino Uno Fan Control : 3 Steps (with Pictures) - Instructables
Circuit design MQ2 gas sensor - Tinkercad
MQ-2 Gas Sensor Arduino - Hackster.io
Relay modules
Humidity Sensor-Controlled Bathroom Exhaust Fan - Hackster.io
ArDewpoint: Dew Point Based Ventilation Controller : 10 Steps - Instructables
Circuit design MQ2 gas sensor - Tinkercad

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

ConditionRed LEDGreen LEDBuzzerExhaust fan
Normal conditionOFFONOFFOFF
Gas above thresholdONOFFONON
Gas level decreases below resetOFFONOFFOFF

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.

UpgradeFunction
16×2 LCD displayDisplays sensor readings and system status
ESP32 Wi-Fi moduleSends gas alerts to a connected dashboard
GSM SIM800LSends SMS notifications
IoT dashboardAllows remote monitoring
Temperature sensorMonitors environmental temperature
Battery backupProvides backup power during outages
Gas Leak Detector Arduino at Annabelle Focken blog

11. Project Testing and Evaluation

The project should be evaluated by observing how the system responds to different sensor readings.

TestExpected observation
Power on the ArduinoGreen LED turns ON
Normal air conditionsFan and buzzer remain OFF
Sensor reading exceeds thresholdRed LED and buzzer turn ON
Gas reading falls below reset thresholdAlarm and fan turn OFF
Disconnect the sensorSystem 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.

  • mbeva

    Dominic Mbeva is a science teacher, experienced researcher, innovator, and creative technologist with expertise in STEM education, digital media, and scientific research. As a Kenya Science and Engineering Fair (KSEF) advisor and projects manager, he mentors young scientists, guiding them in developing award-winning innovations. He is also an IC Technorat, leading advancements in science and technology. Beyond education, Dominic is a skilled photographer and video editor, using visual storytelling to make science more engaging. His philosophy, “If you take care of minutes, hours will take care of themselves,” reflects his belief in consistent effort, strategic thinking, and innovation to drive success in both research and creativity.

    Related Posts

    How to Make a Smart River Water Level and Pollution Monitoring Boat / Buoy Using ESP32 and GPS

    Meta Description: Learn how to build a smart river water level and pollution monitoring boat using ESP32, GPS and water quality sensors. Includes components, circuit connections, Arduino code and IoT…

    Read more

    How to build an automatic street light controller using Arduino and an LDR sensor.

    Meta Description: Learn how to build an automatic street light controller using Arduino and an LDR sensor. Explore circuit connections, components, Arduino code and how the system works. 1. Introduction…

    Read more

    Leave a Reply

    Your email address will not be published. Required fields are marked *