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

Arduino UNO Based Air Quality and Fire Detection System with RGB Indicator and Alarm

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Air Quality and Fire Detection System with RGB Indicator and Alarm

Circuit Documentation

Summary

This circuit is designed to monitor environmental parameters such as CO2 levels and the presence of flames, and to provide visual feedback through an LCD display and an RGB LED. It includes sensors for detecting CO2 (MQ135) and flames (KY-026 Flame Sensor), a buzzer for audible alerts, and a 16x2 LCD for displaying status messages. The Arduino UNO serves as the central microcontroller, interfacing with the various components to process sensor data and control outputs.

Component List

Arduino UNO

Qwiic Cable - Breadboard Jumper (4-pin)

MQ135

16X2 LCD

Potentiometer

Resistor (220 Ohms)

Buzzer

KY-026 Flame Sensor

RGB Led module

Wiring Details

Arduino UNO

MQ135

16X2 LCD

Potentiometer

Resistor (220 Ohms)

Buzzer

KY-026 Flame Sensor

RGB Led module

Documented Code

#include <LiquidCrystal.h>

// Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(2, 3, 6, 7, 8, 13); // LCD Pins: RS, E, D4, D5, D6, D7

const int CO2_PIN = A0;
const int FLAME_ANALOG_PIN = A1;
const int FLAME_DIGITAL_PIN = 4; // Updated Digital Pin for KY-026
const int BUZZER_PIN = 12;       // Updated Digital Pin for Buzzer
const int RED_PIN = 9;           // Updated Red Pin for RGB LED
const int GREEN_PIN = 10;        // Updated Green Pin for RGB LED
const int BLUE_PIN = 11;         // Updated Blue Pin for RGB LED
const int SAFE_CO2_LEVEL = 1000; // Example threshold value
const int RGB_SCALE = 4;         // Scaling factor for RGB

void setup() {
  lcd.begin(16, 2);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(FLAME_DIGITAL_PIN, INPUT);
  pinMode(RED_PIN, OUTPUT);
  pinMode(GREEN_PIN, OUTPUT);
  pinMode(BLUE_PIN, OUTPUT);

  lcd.print("Setup Complete");
  delay(2000);
  lcd.clear();
}

void loop() {
  int co2Value = analogRead(CO2_PIN);
  int flameDigitalValue = digitalRead(FLAME_DIGITAL_PIN);

  // Clear LCD before updating
  lcd.clear();

  // Display CO2 levels
  lcd.setCursor(0, 0);
  lcd.print("CO2: ");
  lcd.print(co2Value);
  lcd.print(" PPM");

  // Check CO2 levels and activate buzzer if necessary
  if (co2Value > SAFE_CO2_LEVEL) {
    digitalWrite(BUZZER_PIN, HIGH);
  } else {
    digitalWrite(BUZZER_PIN, LOW);
  }

  // Check for fire and display warning
  lcd.setCursor(0, 1);
  if (flameDigitalValue == LOW) { // Assuming LOW indicates flame detected
    lcd.print("Fire Detected! ");
    digitalWrite(BUZZER_PIN, HIGH); // Sound buzzer if fire is detected
  } else {
    lcd.print("No Fire       ");
  }

  // Control RGB LED based on CO2 levels
  analogWrite(RED_PIN, co2Value / RGB_SCALE);       // Scale to 0-255
  analogWrite(GREEN_PIN, 255 - (co2Value / RGB_SCALE));
  analogWrite(BLUE_PIN, (co2Value / RGB_SCALE) / 2);

  delay(1000); // Update every second
}

This code is designed to run on the Arduino UNO and controls the LCD, buzzer, and RGB LED based on readings from the MQ135 CO2 sensor and the KY-026 Flame Sensor. It provides visual and audible alerts when CO2 levels exceed a predefined threshold or when flames are detected.