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

Arduino-Controlled Air Quality Monitor with RGB LED Indicator and Fan

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Air Quality Monitor with RGB LED Indicator and Fan

Circuit Documentation

Summary

This circuit is designed to monitor air quality using an MQ-2 gas sensor and to provide a visual indication of the air quality through an RGB LED strip. Additionally, it can activate a fan to ventilate the area if poor air quality is detected. The core of the circuit is an Arduino UNO microcontroller, which controls the LED strip and the fan through an L298N DC motor driver. The circuit is powered by a 12V 7Ah battery, which also supplies power to the motor driver.

Component List

12v 7ah Battery

Arduino UNO

L298N DC Motor Driver

WS2812 RGB LED Strip

MQ-2 Gas Sensor

Fan

Resistor (470 Ohms)

Wiring Details

12v 7ah Battery

Arduino UNO

L298N DC Motor Driver

WS2812 RGB LED Strip

MQ-2 Gas Sensor

Fan

Resistor (470 Ohms)

Documented Code

// Pin definitions
const int MQ2_PIN = A0;         // MQ-2 sensor pin
const int FAN_PIN1 = 3;         // L293D IN1
const int FAN_PIN2 = 5;         // L293D IN2
const int LED_STRIP_PIN = 6;    // LED strip data pin

// Threshold for MQ-2 sensor (adjust based on your environment)
const int THRESHOLD = 300;

void setup() {
  // Initialize pins
  pinMode(MQ2_PIN, INPUT);
  pinMode(FAN_PIN1, OUTPUT);
  pinMode(FAN_PIN2, OUTPUT);
  pinMode(LED_STRIP_PIN, OUTPUT);

  // Start with fan off and LED strip green
  digitalWrite(FAN_PIN1, LOW);
  digitalWrite(FAN_PIN2, LOW);
  setLEDColor(0, 255, 0); // Green color
}

void loop() {
  int mq2Value = analogRead(MQ2_PIN);

  if (mq2Value > THRESHOLD) {
    // Air quality is poor, turn on the fan and change LED strip to red
    digitalWrite(FAN_PIN1, HIGH);
    digitalWrite(FAN_PIN2, LOW);
    setLEDColor(255, 0, 0); // Red color
  } else {
    // Air quality is good, turn off the fan and set LED strip to green
    digitalWrite(FAN_PIN1, LOW);
    digitalWrite(FAN_PIN2, LOW);
    setLEDColor(0, 255, 0); // Green color
  }

  delay(1000); // Delay for stability
}

// Function to set LED strip color
void setLEDColor(int red, int green, int blue) {
  analogWrite(LED_STRIP_PIN, red);   // Red component
  analogWrite(LED_STRIP_PIN + 1, green); // Green component
  analogWrite(LED_STRIP_PIN + 2, blue);  // Blue component
}

This code is designed to run on the Arduino UNO microcontroller. It reads the analog value from the MQ-2 gas sensor and compares it to a predefined threshold. If the value exceeds the threshold, indicating poor air quality, it activates the fan and changes the color of the LED strip to red. Otherwise, it turns off the fan and sets the LED strip to green. The setLEDColor function is used to control the color of the LED strip.