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

Arduino-Based Gas Leakage Detector with MQ-2 Sensor and SIM900A GSM Module

View and Edit Project In Cirkit DesignerImage of Arduino-Based Gas Leakage Detector with MQ-2 Sensor and SIM900A GSM Module

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

  1. 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
  2. MQ-2

    • Description: Gas sensor for detecting LPG, i-butane, propane, methane, alcohol, hydrogen, and smoke.
    • Pins: GND, VCC, ANALOG, Digital
  3. 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
  4. Micro servo 9G

    • Description: Small servo motor for precise control.
    • Pins: GND, +5V, PWM
  5. Piezo Buzzer

    • Description: Sound-producing device.
    • Pins: pin 1, pin 2
  6. Fan

    • Description: Cooling fan.
    • Pins: GND, 5V
  7. 12v power supply

    • Description: Power supply unit.
    • Pins: +, -

Wiring Details

Arduino UNO

MQ-2

SIM900A

Micro servo 9G

Piezo Buzzer

Fan

12v power supply

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.