Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino-Based LPG Leakage Detection System with GSM Alerts and Servo-Controlled Gas Regulator

View and Edit Project In Cirkit DesignerImage of Arduino-Based LPG Leakage Detection System with GSM Alerts and Servo-Controlled Gas Regulator

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

  1. 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
  2. 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
  3. 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-
  4. Servo Motor

    • Description: A motor that can be controlled to rotate to a specific angle.
    • Pins: PWM, GND, VCC
  5. 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

MQ-2 Gas Sensor

SIM800L GSM Module

Servo Motor

1 Channel Relay 5V

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.