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

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

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

Circuit Documentation

Summary

This circuit is designed to monitor environmental conditions, specifically detecting the presence of gas leaks and flames. It utilizes an Arduino UNO as the central microcontroller to process sensor data and control various peripherals, including a servo motor, an LCD display, a buzzer, and multiple LEDs. The circuit is capable of providing visual, auditory, and remote alerts through a Bluetooth module when a gas leak or flame is detected. A relay is also included to control a 12V fan as a potential means to clear detected gas.

Component List

Arduino UNO

Servo

LCD I2C Display

Buzzer

LEDs (Red, Yellow, Green)

HC-05 Bluetooth Module

KF-301 Relay

Flame Sensor

40mm 12V Fan

MQ6 Gas Sensor

9V Battery

Wiring Details

Arduino UNO

Servo

LCD I2C Display

Buzzer

LEDs (Red, Yellow, Green)

HC-05 Bluetooth Module

KF-301 Relay

Flame Sensor

40mm 12V Fan

MQ6 Gas Sensor

9V Battery

Documented Code

#include <Servo.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>  // Include the LiquidCrystal_I2C library

// Define sensor and control pins
const int mq2Pin = A0;        // MQ-2 sensor connected to analog pin A0
const int flameSensorPin = 4; // Flame sensor connected to digital pin 4
const int led1Pin = 5;        // First LED connected to digital pin 5 (SAFE indicator)
const int led2Pin = 6;        // Second LED connected to digital pin 6
const int led3Pin = 7;        // Third LED connected to digital pin 7
const int buzzerPin = 8;      // Buzzer connected to digital pin 8
const int servoPin = 9;       // Servo connected to digital pin 9
const int relayPin = 10;      // Relay module connected to digital pin 10
const int threshold = 300;    // Threshold for gas concentration

// Create Servo, SoftwareSerial, and LCD objects
Servo myServo;
SoftwareSerial hc05(2, 3);  // RX, TX
LiquidCrystal_I2C lcd(0x27, 16, 2); // LCD address 0x27, 16 columns, 2 rows

void setup() {
  // Set sensor and control pin modes
  pinMode(mq2Pin, INPUT);
  pinMode(flameSensorPin, INPUT);
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(led3Pin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  pinMode(relayPin, OUTPUT);

  // Initialize the servo
  myServo.attach(servoPin);
  myServo.write(0);  // Set the servo to initial position

  // Start with relay, LEDs, and buzzer off
  digitalWrite(relayPin, LOW);      // Relay off initially
  digitalWrite(led1Pin, HIGH);      // LED1 on to indicate SAFE state
  digitalWrite(led2Pin, LOW);       // LED2 off
  digitalWrite(led3Pin, LOW);       // LED3 off
  digitalWrite(buzzerPin, LOW);     // Buzzer off

  // Initialize serial communication for debugging and Bluetooth
  Serial.begin(9600);
  hc05.begin(9600); // Initialize HC-05 Bluetooth communication

  // Initialize LCD
  lcd.begin(16,2);  // Initialize the LCD
  lcd.backlight();  // Turn on the LCD backlight

  // Display initial message
  lcd.setCursor(0, 0);
  lcd.print("--TECH_TITANS--");
  lcd.setCursor(0, 1);
  lcd.print("----WELCOME----");
  delay(2000);  // Wait for sensor to warm up
  lcd.clear();  // Clear the screen
}

void loop() {
  // Read the analog value from the MQ-2 sensor
  int gasSensorValue = analogRead(mq2Pin);
  
  // Read the digital value from the flame sensor
  bool flameDetected = digitalRead(flameSensorPin) == LOW;  // LOW means flame detected for most flame sensors

  // Print the gas sensor value to the Serial Monitor (optional)
  Serial.print("Gas Sensor Value: ");
  Serial.println(gasSensorValue);

  // Determine the state and update components accordingly
  bool gasLeak = gasSensorValue > threshold;
  bool danger = gasLeak || flameDetected;
  bool safe = !danger;

  // Update outputs based on sensor readings
  digitalWrite(relayPin, danger ? LOW : HIGH);
  digitalWrite(led1Pin, safe ? HIGH : LOW); // LED1 on when safe
  
  // Turn on all LEDs when both gas leak and flame are detected
  if (gasLeak && flameDetected) {
    digitalWrite(led2Pin, HIGH);  // LED2 on
    digitalWrite(led3Pin, HIGH);  // LED3 on
    digitalWrite(led1Pin, HIGH);
  } else {
    digitalWrite(led2Pin, flameDetected ? HIGH : LOW);
    digitalWrite(led3Pin, gasLeak ? HIGH : LOW); // LED3 on when gas leak is detected
  }
  
  digitalWrite(buzzerPin, danger ? HIGH : LOW);

  // Increase the servo angle when danger is detected
  myServo.write(danger ? 180 : 0); // Move to 180 degrees when danger is detected

  // Update the LCD display
  lcd.setCursor(0, 0);
  lcd.print("--TECH  TITANS--");

  if (gasLeak && flameDetected) {
    lcd.setCursor(0, 1);
    lcd.print("DANGER: Gas+Fire");
    hc05.print("VERY DANGER: Gas and Flame Detected