Arduino UNO-Based Fire Detection and Gas Leak Alert System with Bluetooth Notification
View and Edit Project In Cirkit Designer
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
- Microcontroller board based on the ATmega328P
- Used as the main processing unit for the circuit
Servo
- A motor capable of precise position control
- Used to actuate or move an object when a certain condition is met
LCD I2C Display
- A 16x2 character LCD display with an I2C interface
- Used to display status messages and alerts
Buzzer
- An electronic component that produces sound
- Used to provide an auditory alert
LEDs (Red, Yellow, Green)
- Light Emitting Diodes of different colors
- Used as visual indicators for various states of the circuit
HC-05 Bluetooth Module
- A wireless communication module
- Used to send alerts and data to a Bluetooth-enabled device
KF-301 Relay
- An electrically operated switch
- Used to control the 12V fan
Flame Sensor
- A sensor that detects the presence of a flame
- Used to trigger an alert when a flame is detected
40mm 12V Fan
- A fan that operates at 12V
- Used to dissipate gas when activated by the relay
MQ6 Gas Sensor
- A sensor for detecting LPG, butane, propane, methane, alcohol, hydrogen, and smoke
- Used to detect gas leaks
9V Battery
- A power source for the circuit
- Used to provide power to the 12V fan through the relay
Wiring Details
Arduino UNO
- 5V and GND pins provide power to the Flame Sensor, HC-05, MQ6, LCD I2C Display, and Servo
- A0 pin connected to MQ6 DO pin
- A4 (SDA) and A5 (SCL) pins connected to LCD I2C Display
- D2 and D3 pins connected to HC-05 TXD and RXD pins, respectively
- D4 pin connected to Flame Sensor D0 pin
- D5, D6, and D7 pins connected to Green, Yellow, and Red LED anodes, respectively
- D8 pin connected to Buzzer PIN
- D9 pin connected to Servo pulse pin
- D10 pin connected to KF-301 Relay signal pin
Servo
- Controlled by the D9 pin on the Arduino UNO
LCD I2C Display
- SDA and SCL pins connected to A4 and A5 on the Arduino UNO
Buzzer
- PIN connected to D8 on the Arduino UNO
LEDs (Red, Yellow, Green)
- Anodes connected to D7, D6, and D5 on the Arduino UNO, respectively
- Cathodes connected to GND
HC-05 Bluetooth Module
- VCC and GND pins powered by the Arduino UNO
- TXD and RXD pins connected to D2 and D3 on the Arduino UNO
KF-301 Relay
- Signal pin controlled by D10 on the Arduino UNO
- Power pin connected to 5V on the Arduino UNO
- Ground pin connected to GND on the Arduino UNO
- Common (C) pin connected to the negative terminal of the 9V Battery
- Normally Open (NO) pin connected to the negative terminal of the 12V Fan
Flame Sensor
- VCC and GND pins powered by the Arduino UNO
- D0 pin connected to D4 on the Arduino UNO
40mm 12V Fan
- Negative terminal connected to the NO pin on the KF-301 Relay
- Positive terminal connected to the positive terminal of the 9V Battery
MQ6 Gas Sensor
- VCC and GND pins powered by the Arduino UNO
- DO pin connected to A0 on the Arduino UNO
9V Battery
- Positive terminal connected to the positive terminal of the 12V Fan
- Negative terminal connected to the Common (C) pin on the KF-301 Relay
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