Arduino-Based LPG Leakage Detection System with GSM Alerts and Servo-Controlled Gas Regulator
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed for LPG leakage detection and safety measures. It utilizes an Arduino UNO microcontroller to read gas levels from an MQ-2 gas sensor, control a servo motor to cut off the gas supply, and activate a relay to turn off electrical appliances. Additionally, a SIM800L GSM module is used to send SMS alerts and make phone calls in case of gas leakage detection.
Component List
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: SDA, AREF, GND, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, A5, A4, A3, A2, A1, A0, Vin, 5V, 3.3V, RESET, IOREF, SCL
MQ-2 Gas Sensor
- Description: A gas sensor module capable of detecting LPG, smoke, alcohol, propane, hydrogen, methane, and carbon monoxide.
- Pins: GND, VCC, ANALOG, Digital
SIM800L GSM Module
- Description: A GSM/GPRS module that allows for SMS, voice, and data communication.
- Pins: NET, VCC, RST, RXD, TXD, GND, RING, DTR, MIC+, MIC-, SPK+, SPK-
Servo Motor
- Description: A motor that can be controlled to rotate to a specific angle.
- Pins: PWM, GND, VCC
1 Channel Relay 5V
- Description: A relay module that can be used to control high voltage appliances.
- Pins: VCC, GND, IN, NC, COM, NO
Wiring Details
Arduino UNO
- GND: Connected to GND of MQ-2, Servo Motor, and 1 Channel Relay 5V.
- 5V: Connected to VCC of MQ-2 and 1 Channel Relay 5V.
- 3.3V: Connected to VCC of Servo Motor.
- A0: Connected to ANALOG of MQ-2.
- 7: Connected to IN of 1 Channel Relay 5V.
- 9: Connected to PWM of Servo Motor.
- 10: Connected to RXD of SIM800L.
- 11: Connected to TXD of SIM800L.
MQ-2 Gas Sensor
- GND: Connected to GND of Arduino UNO.
- VCC: Connected to 5V of Arduino UNO.
- ANALOG: Connected to A0 of Arduino UNO.
SIM800L GSM Module
- TXD: Connected to 11 of Arduino UNO.
- RXD: Connected to 10 of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
Servo Motor
- PWM: Connected to 9 of Arduino UNO.
- GND: Connected to GND of Arduino UNO.
- VCC: Connected to 3.3V of Arduino UNO.
1 Channel Relay 5V
- GND: Connected to GND of Arduino UNO.
- VCC: Connected to 5V of Arduino UNO.
- IN: Connected to 7 of Arduino UNO.
Documented Code
// Include necessary libraries
#include <Servo.h>
#include <SoftwareSerial.h>
// Define pins for MQ2 Gas Sensor, GSM module, Servo Motor, and Relay
#define MQ2_PIN A0 // Analog pin connected to MQ2 gas sensor
#define RELAY_PIN 7 // Digital pin connected to the relay module
#define SERVO_PIN 9 // Digital pin connected to the servo motor
// Define threshold for gas detection
#define GAS_THRESHOLD 400
// GSM module configuration
SoftwareSerial gsm(10, 11); // RX (10), TX (11) for GSM module
Servo gasRegulator;
void setup() {
// Initialize Serial communication
Serial.begin(9600);
gsm.begin(9600);
// Initialize servo and set it to default position
gasRegulator.attach(SERVO_PIN);
gasRegulator.write(0); // Default position (open)
// Set relay pin as output and turn it off initially
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW);
// Wait for GSM module to initialize
delay(10000);
sendSMS("System initialized. LPG leakage detection is active.");
}
void loop() {
// Read gas sensor value
int gasValue = analogRead(MQ2_PIN);
Serial.print("Gas Sensor Value: ");
Serial.println(gasValue);
// Check if gas value exceeds the threshold
if (gasValue > GAS_THRESHOLD) {
Serial.println("Gas leakage detected!");
// Send SMS and make a call
sendSMS("Alert! LPG leakage detected. Taking safety measures.");
makeCall();
// Cut off the gas regulator
gasRegulator.write(90); // Rotate servo to close gas regulator
// Turn off electricity using the relay
digitalWrite(RELAY_PIN, HIGH);
// Wait for some time to avoid repeated alerts
delay(60000); // 1 minute delay
}
delay(1000); // Sampling delay
}
void sendSMS(String message) {
gsm.print("AT+CMGF=1\r"); // Set SMS mode to text
delay(100);
gsm.print("AT+CMGS=\"+1234567890\"\r"); // Replace with your phone number
delay(100);
gsm.print(message);
delay(100);
gsm.write(26); // ASCII code of CTRL+Z to send SMS
delay(5000);
}
void makeCall() {
gsm.print("ATD+1234567890;\r"); // Replace with your phone number
delay(10000); // Wait for the call to connect
gsm.print("ATH\r"); // Hang up the call
delay(1000);
}
This code initializes the necessary components and continuously monitors the gas levels. If the gas level exceeds the defined threshold, it sends an SMS alert, makes a phone call, closes the gas regulator using the servo motor, and turns off electrical appliances using the relay.