Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

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

Image 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

  • Description: A 12-volt 7-ampere-hour rechargeable battery.
  • Pins: 12v +, 12v -

Arduino UNO

  • Description: A microcontroller board based on the ATmega328P.
  • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13

L298N DC Motor Driver

  • Description: A dual H-bridge motor driver that can drive two DC motors.
  • Pins: OUT1, OUT2, 12V, GND, 5V, OUT3, OUT4, 5V-ENA-JMP-I, 5V-ENA-JMP-O, +5V-J1, +5V-J2, ENA, IN1, IN2, IN3, IN4, ENB

WS2812 RGB LED Strip

  • Description: An addressable LED strip with WS2812 RGB LEDs.
  • Pins: DIN, 5V, GND, DO

MQ-2 Gas Sensor

  • Description: A gas sensor for detecting LPG, propane, hydrogen, and other combustible gases.
  • Pins: Vcc, GND, DO, AO

Fan

  • Description: A small DC fan for air circulation.
  • Pins: GND, 5V

Resistor (470 Ohms)

  • Description: A resistor with a resistance of 470 Ohms.
  • Pins: pin1, pin2

Wiring Details

12v 7ah Battery

  • 12v +: Connected to the 12V pin of the L298N DC motor driver.
  • 12v -: Connected to the GND pin of the Arduino UNO and the GND pin of the L298N DC motor driver.

Arduino UNO

  • D6: Connected to the DIN pin of the WS2812 RGB LED strip through a 470 Ohm resistor.
  • GND: Common ground connected to the GND pins of the WS2812 RGB LED strip, MQ-2 gas sensor, and L298N DC motor driver.
  • 5V: Connected to the 5V pin of the WS2812 RGB LED strip and the Vcc pin of the MQ-2 gas sensor.
  • Vin: Connected to the 5V pin of the L298N DC motor driver.
  • A0: Connected to the AO pin of the MQ-2 gas sensor.
  • D5: Connected to the IN2 pin of the L298N DC motor driver.
  • D3: Connected to the IN1 pin of the L298N DC motor driver.

L298N DC Motor Driver

  • OUT1, OUT2: Connected to the 5V and GND pins of the fan, respectively.
  • 5V-ENA-JMP-I, 5V-ENA-JMP-O: Jumpered together to enable the motor driver.
  • +5V-J1, ENA: Jumpered together to enable output 1.
  • +5V-J2, ENB: Jumpered together to enable output 2.

WS2812 RGB LED Strip

  • DIN: Connected to the D6 pin of the Arduino UNO through a 470 Ohm resistor.
  • 5V: Connected to the 5V pin of the Arduino UNO.
  • GND: Connected to the GND pin of the Arduino UNO.

MQ-2 Gas Sensor

  • Vcc: Connected to the 5V pin of the Arduino UNO.
  • GND: Connected to the GND pin of the Arduino UNO.
  • AO: Connected to the A0 pin of the Arduino UNO.

Fan

  • 5V: Connected to the OUT1 pin of the L298N DC motor driver.
  • GND: Connected to the OUT2 pin of the L298N DC motor driver.

Resistor (470 Ohms)

  • pin1: Connected to the DIN pin of the WS2812 RGB LED strip.
  • pin2: Connected to the D6 pin of the Arduino UNO.

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.