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

Arduino UNO-Based Gas and Flame Detection System with LCD Display and Bluetooth Alert

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Gas and Flame Detection System with LCD Display and Bluetooth Alert

Circuit Documentation

Summary

The circuit in question is designed to monitor environmental conditions, specifically gas presence and flames, and to respond accordingly. It utilizes an Arduino UNO as the central microcontroller to interface with various sensors and output devices, including an MQ6 gas sensor, a flame sensor, an LCD I2C display, a buzzer, LEDs, a relay, and a Bluetooth module (HC-05). The circuit is powered by a 9V battery and includes a 4x4 membrane matrix keypad for user input. The system is designed to alert users to dangerous conditions by activating visual and auditory signals and to communicate alerts via Bluetooth.

Component List

Wiring Details

Arduino UNO

LCD I2C Display

Buzzer

LED (Red)

HC-05

KF-301 Relay

MQ6

9V Battery

4x4 Membrane Matrix Keypad

Magnetic Contactor

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