Arduino UNO-Based Air Quality Monitoring System with OLED Display and Multi-Color LED Indicators
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor air quality by measuring temperature, humidity, gas concentration, and dust density. It uses an Arduino UNO microcontroller to process sensor data and display the results on an OLED screen. The circuit also includes LEDs and a buzzer to provide visual and auditory alerts based on the air quality index (AQI).
Component List
Arduino UNO
- Description: Microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
GP2Y1010AU0F
- Description: Optical dust sensor.
- Pins: VCC, Vout, S-GND, LED, LED-GND, V-LED
Resistor
- Description: 100 Ohms resistor.
- Pins: pin1, pin2
- Properties: Resistance = 100 Ohms
Electrolytic Capacitor
- Description: 47 µF capacitor.
- Pins: -, +
- Properties: Capacitance = 47 µF
LED: Two Pin (yellow)
- Description: Yellow LED.
- Pins: cathode, anode
LED: Two Pin (green)
- Description: Green LED.
- Pins: cathode, anode
LED: Two Pin (red)
- Description: Red LED.
- Pins: cathode, anode
OLED 1.3"
- Description: 1.3-inch OLED display.
- Pins: GND, VCC, SCL, SDA
DHT22
- Description: Temperature and humidity sensor.
- Pins: +, Out, -
MQ 135
- Description: Gas sensor.
- Pins: D OUT, A OUT, GND, VCC
Buzzer
- Description: Piezoelectric buzzer.
- Pins: PIN, GND
Wiring Details
Arduino UNO
- 5V: Connected to VCC of GP2Y1010AU0F, pin1 of Resistor, VCC of MQ 135, + of DHT22, VCC of OLED 1.3"
- GND: Connected to S-GND and LED-GND of GP2Y1010AU0F, GND of MQ 135, GND of Buzzer, - of DHT22, cathode of red LED, cathode of yellow LED, GND of OLED 1.3", cathode of green LED
- A0: Connected to A OUT of MQ 135
- A1: Connected to Vout of GP2Y1010AU0F
- A4: Connected to SDA of OLED 1.3"
- A5: Connected to SCL of OLED 1.3"
- D2: Connected to Out of DHT22
- D3: Connected to LED of GP2Y1010AU0F
- D6: Connected to anode of red LED, anode of yellow LED, anode of green LED
- D7: Connected to PIN of Buzzer
GP2Y1010AU0F
- VCC: Connected to 5V of Arduino UNO
- Vout: Connected to A1 of Arduino UNO
- S-GND: Connected to GND of Arduino UNO
- LED: Connected to D3 of Arduino UNO
- LED-GND: Connected to GND of Arduino UNO
- V-LED: Connected to pin2 of Resistor, - of Electrolytic Capacitor
Resistor
- pin1: Connected to 5V of Arduino UNO
- pin2: Connected to V-LED of GP2Y1010AU0F, - of Electrolytic Capacitor
Electrolytic Capacitor
- +: Connected to GND of Arduino UNO
- -: Connected to pin2 of Resistor, V-LED of GP2Y1010AU0F
LED: Two Pin (yellow)
- cathode: Connected to GND of Arduino UNO
- anode: Connected to D6 of Arduino UNO
LED: Two Pin (green)
- cathode: Connected to GND of Arduino UNO
- anode: Connected to D6 of Arduino UNO
LED: Two Pin (red)
- cathode: Connected to GND of Arduino UNO
- anode: Connected to D6 of Arduino UNO
OLED 1.3"
- GND: Connected to GND of Arduino UNO
- VCC: Connected to 5V of Arduino UNO
- SCL: Connected to A5 of Arduino UNO
- SDA: Connected to A4 of Arduino UNO
DHT22
- +: Connected to 5V of Arduino UNO
- Out: Connected to D2 of Arduino UNO
- -: Connected to GND of Arduino UNO
MQ 135
- D OUT: Not connected
- A OUT: Connected to A0 of Arduino UNO
- GND: Connected to GND of Arduino UNO
- VCC: Connected to 5V of Arduino UNO
Buzzer
- PIN: Connected to D7 of Arduino UNO
- GND: Connected to GND of Arduino UNO
Code Documentation
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "DHT.h"
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#define MQ135_PIN A0
#define DUST_SENSOR_LED 3
#define DUST_SENSOR_OUT A1
#define GREEN_LED 4
#define YELLOW_LED 5
#define RED_LED 6
#define BUZZER 7
void setup() {
Serial.begin(9600);
dht.begin();
if (!display.begin(0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.display();
delay(2000);
display.clearDisplay();
pinMode(DUST_SENSOR_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(YELLOW_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);
pinMode(BUZZER, OUTPUT);
digitalWrite(GREEN_LED, LOW);
digitalWrite(YELLOW_LED, LOW);
digitalWrite(RED_LED, LOW);
digitalWrite(BUZZER, LOW);
}
void loop() {
float humidity = dht.readHumidity();
float temperatureC = dht.readTemperature();
if (isnan(humidity) || isnan(temperatureC)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
int mq135_value = analogRead(MQ135_PIN);
float gasQuality = map(mq135_value, 0, 1023, 0, 500);
digitalWrite(DUST_SENSOR_LED, LOW);
delayMicroseconds(280);
int dustValue = analogRead(DUST_SENSOR_OUT);
digitalWrite(DUST_SENSOR_LED, HIGH);
delayMicroseconds(9680);
float dustDensity = (dustValue - 500) * 0.5;
float combinedAQI = (gasQuality + dustDensity) / 2;
Serial.print("Temp: "); Serial.print(temperatureC); Serial.print(" C, ");
Serial.print("Humidity: "); Serial.print(humidity); Serial.print(" %, ");
Serial.print("Gas AQI: "); Serial.print(gasQuality);
Serial.print(", Dust Density: "); Serial.print(dustDensity);
Serial.print(" ug/m3, Combined AQI: "); Serial.println(combinedAQI);
if (combinedAQI <= 50) {
digitalWrite(GREEN_LED, HIGH);
digitalWrite(YELLOW_LED, LOW);
digitalWrite(RED_LED, LOW);
digitalWrite(BUZZER, LOW);
} else if (combinedAQI > 50 && combinedAQI <= 150) {
digitalWrite(GREEN_LED, LOW);
digitalWrite(YELLOW_LED, HIGH);
digitalWrite(RED_LED, LOW);
digitalWrite(BUZZER, LOW);
} else {
digitalWrite(GREEN_LED, LOW);
digitalWrite(YELLOW_LED, LOW);
digitalWrite(RED_LED, HIGH);
digitalWrite(BUZZER, HIGH);
}
display.clearDisplay();
display.setTextSize