Arduino-Based Gas Leakage Detector with MQ-2 Sensor and SIM900A GSM Module
View and Edit Project In Cirkit Designer
Gas Leakage Detector Circuit Documentation
Summary
This circuit is designed to detect gas leakage using an MQ-2 gas sensor. When the gas level exceeds a predefined threshold, the system triggers a series of actions: it activates a piezo buzzer, turns on a cooling fan, opens a valve using a servo motor, and sends an SMS alert via a SIM900A GSM module. Additionally, it makes a call to a predefined number to alert the user.
Component List
Arduino UNO
- Description: Microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
MQ-2
- Description: Gas sensor for detecting LPG, i-butane, propane, methane, alcohol, hydrogen, and smoke.
- Pins: GND, VCC, ANALOG, Digital
SIM900A
- Description: GSM/GPRS module for communication.
- Pins: GND, DB9-3 (RXD), DB9-2 (TXD), 5V, 3VR, 5VR, 3VT, 5VT, VCC, Ring, RESTART, RESET, STATUS
Micro servo 9G
- Description: Small servo motor for precise control.
- Pins: GND, +5V, PWM
Piezo Buzzer
- Description: Sound-producing device.
- Pins: pin 1, pin 2
Fan
- Description: Cooling fan.
- Pins: GND, 5V
12v power supply
- Description: Power supply unit.
- Pins: +, -
Wiring Details
Arduino UNO
5V connected to:
- VCC of MQ-2
- +5V of Micro servo 9G
GND connected to:
- GND of MQ-2
- GND of Fan
- GND of SIM900A
- GND of Micro servo 9G
- pin 2 of Piezo Buzzer
- - of 12v power supply
A0 connected to:
- ANALOG of MQ-2
D9 connected to:
- PWM of Micro servo 9G
D8 connected to:
- pin 1 of Piezo Buzzer
D7 connected to:
- 5V of Fan
D1 connected to:
- DB9-3 (RXD) of SIM900A
D0 connected to:
- DB9-2 (TXD) of SIM900A
MQ-2
VCC connected to:
- 5V of Arduino UNO
GND connected to:
- GND of Arduino UNO
ANALOG connected to:
- A0 of Arduino UNO
SIM900A
GND connected to:
- GND of Arduino UNO
DB9-3 (RXD) connected to:
- D1 of Arduino UNO
DB9-2 (TXD) connected to:
- D0 of Arduino UNO
VCC connected to:
- + of 12v power supply
Micro servo 9G
+5V connected to:
- 5V of Arduino UNO
GND connected to:
- GND of Arduino UNO
PWM connected to:
- D9 of Arduino UNO
Piezo Buzzer
pin 1 connected to:
- D8 of Arduino UNO
pin 2 connected to:
- GND of Arduino UNO
Fan
5V connected to:
- D7 of Arduino UNO
GND connected to:
- GND of Arduino UNO
12v power supply
+ connected to:
- VCC of SIM900A
- connected to:
- GND of Arduino UNO
Code Documentation
/*
* Gas Leakage Detector
* This Arduino sketch monitors gas levels using an MQ-2 sensor. If the gas level
* exceeds a predefined threshold, it triggers a buzzer, turns on a cooling fan,
* opens a valve using a servo motor, and sends an SMS alert via a SIM900A GSM
* module. It also makes a call to a predefined number to alert the user.
*/
#include <Servo.h>
#include <SoftwareSerial.h>
// Define pin connections
const int gasSensor = A0; // MQ-2 sensor analog output connected to A0
const int buzzer = 8; // Buzzer connected to digital pin 8
const int fan = 7; // Cooling fan connected to digital pin 7
Servo servo; // Create Servo object for valve control
SoftwareSerial GSM(0, 1); // RX, TX for GSM module (SIM900A)
// Threshold for gas detection
const int gasThreshold = 400; // Adjust based on calibration
void setup() {
// Initialize pins
pinMode(gasSensor, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(fan, OUTPUT);
// Attach servo to pin 9
servo.attach(9);
servo.write(0); // Valve closed by default
// Initialize serial communication
GSM.begin(9600); // GSM module communication
Serial.begin(9600); // For monitoring in Serial Monitor
// Initialize GSM module
GSM.println("AT");
delay(1000);
}
void loop() {
// Read gas level from MQ-2 sensor
int gasLevel = analogRead(gasSensor);
Serial.print("Gas Level: ");
Serial.println(gasLevel);
// Check if gas level exceeds the threshold
if (gasLevel > gasThreshold) {
// Trigger alert mechanisms
digitalWrite(buzzer, HIGH); // Turn on buzzer
digitalWrite(fan, HIGH); // Turn on cooling fan
servo.write(90); // Open valve
// Send SMS alert
GSM.println("AT+CMGF=1"); // Set SMS mode
delay(100);
GSM.println("AT+CMGS=\"+918928578900\""); // Replace with your phone number
delay(100);
GSM.print("Warning! Gas Leakage Detected! Gas Level: ");
GSM.print(gasLevel);
GSM.println(" ppm. Take immediate action.");
delay(100);
GSM.write(26); // End SMS
delay(5000); // Delay to avoid spamming
// Make a call
GSM.println("ATD+918928578900;"); // Replace with your phone number
delay(10000); // Wait for the call to ring
GSM.println("ATH"); // Hang up the call
} else {
// Reset all mechanisms
digitalWrite(buzzer, LOW);
digitalWrite(fan, LOW);
servo.write(0); // Close valve
}
// Small delay for stability
delay(1000);
}
This code initializes the necessary components and continuously monitors the gas level. If the gas level exceeds the threshold, it triggers the alert mechanisms and sends notifications. If the gas level is below the threshold, it resets the alert mechanisms.