Gas Leakage Detection &
Safety Alert System
Build a smart home/industrial gas monitoring system using Arduino Uno, MQ-2 sensor, relay module, and buzzer — with full circuit diagram, code, and simulation.
🧰 Components Required
🔌 Circuit Diagram
Circuit diagram showing Arduino Uno connected to MQ-2 gas sensor, IR sensor, relay module, buzzer, and load bulb.
📋 Pin Connections / Wiring Guide
| Component | Component Pin | Arduino Pin | Wire Color |
|---|---|---|---|
| MQ-2 Gas Sensor | AO (Analog Out) | A0 | 🟡 Yellow |
| MQ-2 Gas Sensor | VCC | 5V | 🔴 Red |
| MQ-2 Gas Sensor | GND | GND | ⚫ Black |
| IR Sensor | OUT | D2 | 🔵 Blue |
| IR Sensor | VCC | 5V | 🔴 Red |
| IR Sensor | GND | GND | ⚫ Black |
| Relay Module | IN (Signal) | D3 | 🟠 Orange |
| Relay Module | VCC | 5V | 🔴 Red |
| Relay Module | GND | GND | ⚫ Black |
| Buzzer (+) | Positive | D5 | 🟣 Purple |
| Buzzer (-) | Negative | GND | ⚫ Black |
| 9V Battery | + | VIN | 🔴 Red |
| 9V Battery | - | GND | ⚫ Black |
🛠️ Step-by-Step Build Instructions
Gather all components
Collect Arduino Uno, MQ-2 gas sensor, IR sensor module, 5V relay module, active buzzer, 9V battery, jumper wires, and a breadboard. Ensure all modules are in working condition.
Place components on the breadboard
Lay out the MQ-2 sensor, IR sensor, relay, and buzzer on or near the breadboard. Leave enough space for clean wiring. The relay module can be mounted off-board if controlling AC loads.
Connect power rails
Connect Arduino 5V to the breadboard positive rail and GND to the negative rail. All VCC pins of the MQ-2, IR sensor, and relay connect to this 5V rail. All GND pins connect to the GND rail.
Wire the MQ-2 Gas Sensor
Connect the MQ-2 AO (analog output) pin to Arduino A0. The DO (digital output) pin is optional for this project. Ensure VCC → 5V and GND → GND are connected.
Wire the IR Sensor
Connect IR Sensor OUT pin to Arduino digital pin D2. Connect VCC to 5V and GND to GND. Adjust the potentiometer on the IR module if needed for sensitivity.
Connect the Relay Module
Connect relay IN pin to Arduino D3. The relay's NO (Normally Open) and COM terminals are wired in series with your load (bulb). VCC → 5V, GND → GND. If using AC loads, exercise extreme caution or use an optoisolated relay.
Connect the Buzzer
Connect the buzzer positive (+) lead to Arduino D5. Connect negative (–) to GND. For an active buzzer, no extra components are needed — it will buzz when D5 goes HIGH.
Power the Arduino
Connect a 9V battery to the Arduino via the barrel jack (VIN + GND) or use a USB cable from a PC/charger for testing. The Arduino regulates the voltage to 5V for the components.
Upload the code
Open the Arduino IDE, paste the code from the section below, select Board: Arduino Uno and the correct COM port, then click Upload. Open Serial Monitor at 9600 baud to view gas level readings.
Test the system
Bring a lighter (unlit, gas only) near the MQ-2 sensor. The Serial Monitor should show rising gas levels. When the value exceeds 300, the buzzer should sound and the relay should click/activate. Adjust the threshold in the code as needed for your environment.
⚙️ How It Works
💻 Arduino Code
300 based on your MQ-2 sensor's baseline readings in clean air./* Arduino Gas Leakage Detection and Safety Alert System Using MQ-2 Gas Sensor — MakeMindz.com Connections: - MQ-2 Gas Sensor AO pin → Arduino A0 - IR Sensor OUT pin → Arduino D2 - Relay IN pin → Arduino D3 - Sound Sensor OUT pin → Arduino D4 - Buzzer PIN → Arduino D5 */ const int gasSensorPin = A0; // Analog pin for MQ-2 sensor const int irSensorPin = 2; // Digital pin for IR sensor const int relayPin = 3; // Digital pin for Relay const int soundSensorPin = 4; // Digital pin for Sound sensor const int buzzerPin = 5; // Digital pin for Buzzer void setup() { pinMode(gasSensorPin, INPUT); pinMode(irSensorPin, INPUT); pinMode(relayPin, OUTPUT); pinMode(soundSensorPin,INPUT); pinMode(buzzerPin, OUTPUT); Serial.begin(9600); } void loop() { int gasLevel = analogRead(gasSensorPin); int irState = digitalRead(irSensorPin); int soundState = digitalRead(soundSensorPin); Serial.print("Gas Level: "); Serial.println(gasLevel); if (gasLevel > 300) { // Threshold for gas detection digitalWrite(relayPin, HIGH); // Activate relay digitalWrite(buzzerPin, HIGH); // Activate buzzer Serial.println("Gas Detected! Alarm Activated."); } else { digitalWrite(relayPin, LOW); // Deactivate relay digitalWrite(buzzerPin, LOW); // Deactivate buzzer } if (irState == HIGH) { Serial.println("IR Sensor Triggered!"); } if (soundState == HIGH) { Serial.println("Sound Detected!"); } delay(1000); // Delay for stability }
🗂️ Diagram.json CirkitDesigner
{
"version": 1,
"author": "MakeMindz",
"title": "Arduino Gas Leakage Detection and Safety Alert System",
"description": "MQ-2 gas sensor with relay, buzzer, and IR sensor for gas leak detection",
"components": [
{
"id": "arduino_uno_1",
"type": "arduino-uno",
"name": "Arduino Uno",
"position": { "x": 300, "y": 200 }
},
{
"id": "mq2_1",
"type": "mq2-gas-sensor",
"name": "MQ-2 Gas Sensor",
"position": { "x": 80, "y": 100 }
},
{
"id": "ir_sensor_1",
"type": "ir-sensor",
"name": "IR Sensor Module",
"position": { "x": 80, "y": 280 }
},
{
"id": "relay_1",
"type": "relay-5v",
"name": "5V Relay Module",
"position": { "x": 560, "y": 100 }
},
{
"id": "buzzer_1",
"type": "buzzer-active",
"name": "Active Buzzer",
"position": { "x": 560, "y": 280 }
},
{
"id": "bulb_1",
"type": "light-bulb",
"name": "Bulb (Demo Load)",
"position": { "x": 560, "y": 420 }
},
{
"id": "battery_1",
"type": "battery-9v",
"name": "9V Battery",
"position": { "x": 300, "y": 420 }
}
],
"wires": [
{ "from": "mq2_1.AO", "to": "arduino_uno_1.A0", "color": "yellow" },
{ "from": "mq2_1.VCC", "to": "arduino_uno_1.5V", "color": "red" },
{ "from": "mq2_1.GND", "to": "arduino_uno_1.GND", "color": "black" },
{ "from": "ir_sensor_1.OUT", "to": "arduino_uno_1.D2", "color": "blue" },
{ "from": "ir_sensor_1.VCC", "to": "arduino_uno_1.5V", "color": "red" },
{ "from": "ir_sensor_1.GND", "to": "arduino_uno_1.GND", "color": "black" },
{ "from": "relay_1.IN", "to": "arduino_uno_1.D3", "color": "orange" },
{ "from": "relay_1.VCC", "to": "arduino_uno_1.5V", "color": "red" },
{ "from": "relay_1.GND", "to": "arduino_uno_1.GND", "color": "black" },
{ "from": "relay_1.NO", "to": "bulb_1.positive", "color": "yellow" },
{ "from": "buzzer_1.positive","to": "arduino_uno_1.D5", "color": "purple" },
{ "from": "buzzer_1.negative","to": "arduino_uno_1.GND", "color": "black" },
{ "from": "battery_1.positive","to": "arduino_uno_1.VIN", "color": "red" },
{ "from": "battery_1.negative","to": "arduino_uno_1.GND", "color": "black" }
],
"code": {
"file": "gas_leakage_detection.ino",
"target": "arduino_uno_1"
}
}
▶️ Try the Simulation
Open the live circuit simulation on CirkitDesigner — run the sketch virtually without any hardware.
Import the diagram.json above into CirkitDesigner, or use the Tinkercad link to build manually.
Key Features & Applications
Real-time Detection
Continuously monitors gas levels every second with instant response when threshold is exceeded.
Audible Alarm
Active buzzer provides immediate audible alert so people in the vicinity are warned.
Appliance Control
Relay module can switch off appliances or trigger external safety systems automatically.
Battery Powered
9V battery operation for portable deployment — no wall outlet required for monitoring.
Low Cost
All components are inexpensive and widely available. Full build cost under ₹500 / $7.
Expandable
Easily extended with GSM, ESP8266/ESP32 WiFi, or LoRa for remote alerts and IoT monitoring.
Comments
Post a Comment