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

Arduino UNO-Based Fire and Gas Leak Detection System with GSM Alert

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Fire and Gas Leak Detection System with GSM Alert

Circuit Documentation

Summary

This circuit is designed to detect gas leaks and fire, and then trigger an alarm and send an SMS notification using an Arduino UNO microcontroller. The circuit includes a gas sensor (MQ-2), a flame sensor, a SIM800L GSM module, a buzzer, and a 12V single-channel relay.

Component List

Arduino UNO

Flame Sensor

MQ-2 Gas Sensor

SIM800L GSM Module

Buzzer

12V Single Channel Relay

Wiring Details

Arduino UNO

Flame Sensor

MQ-2 Gas Sensor

SIM800L GSM Module

Buzzer

12V Single Channel Relay

Code Documentation

#include <SoftwareSerial.h>

// Define pins
const int gasSensorPin = A0; 
const int flameSensorPin = 2; 
const int buzzerPin = 3; 
const int relayPin = 4;

// Define GSM module pins
SoftwareSerial sim800l(7, 8); // RX, TX

// Threshold values (adjust as needed)
const int gasThreshold = 500; // Example value
const int flameThreshold = HIGH; 

void setup() {
  Serial.begin(9600);
  sim800l.begin(9600); 
  pinMode(flameSensorPin, INPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(relayPin, OUTPUT);
}

void loop() {
  // Read gas sensor value
  int gasValue = analogRead(gasSensorPin);

  // Read flame sensor value
  int flameValue = digitalRead(flameSensorPin);

  // Check for gas leak
  if (gasValue > gasThreshold) {
    Serial.println("Gas leak detected!");
    triggerAlarm();
    sendSMS("Gas leak detected!");
  }

  // Check for fire
  if (flameValue == flameThreshold) {
    Serial.println("Fire detected!");
    triggerAlarm();
    sendSMS("Fire detected!");
  }

  delay(1000); // Check every second
}

void triggerAlarm() {
  digitalWrite(buzzerPin, HIGH); 
  digitalWrite(relayPin, HIGH); // Activate relay (e.g., turn on fan)
  delay(1000);
  digitalWrite(buzzerPin, LOW); 
  digitalWrite(relayPin, LOW); 
  delay(1000); 
}

void sendSMS(String message) {
  // Send SMS using SIM800L module
  sim800l.println("AT+CMGF=1"); 
  delay(1000);
  sim800l.println("AT+CMGS=\"+[Phone Number]\"\r"); 
  delay(1000);
  sim800l.print(message);
  delay(1000);
  sim800l.println((char)26); 
  delay(5000);
}

This code initializes the sensors and the GSM module, reads the sensor values, and triggers an alarm and sends an SMS if gas or fire is detected. The triggerAlarm function activates the buzzer and the relay, while the sendSMS function sends an SMS using the SIM800L module.