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

Arduino Nano Environmental Monitoring System with Air Quality and Temperature Sensors

Image of Arduino Nano Environmental Monitoring System with Air Quality and Temperature Sensors

Circuit Documentation

Summary

This circuit is designed around an Arduino Nano microcontroller and includes a variety of sensors and output devices. The sensors include a DHT11 temperature and humidity sensor, a GP2Y1010AU0F dust sensor, and an MQ135 gas sensor. Output devices include a buzzer and three LEDs (red, yellow, and green) for visual alerts. A 1.3" OLED display is used to show sensor readings and alert statuses. The circuit is intended to monitor environmental conditions and provide visual and audible alerts based on predefined threshold values for gas levels, dust density, and temperature.

Component List

Microcontroller

  • Arduino Nano: A compact microcontroller board based on the ATmega328P, featuring digital and analog I/O pins.

Sensors

  • DHT11: A basic, low-cost digital temperature and humidity sensor.
  • GP2Y1010AU0F: An optical air quality sensor designed to sense dust particles.
  • MQ135: A gas sensor for detecting a wide range of gases, including NH3, NOx, alcohol, benzene, smoke, and CO2.

Output Devices

  • Buzzer: An electronic buzzer for audible alerts.
  • LED: Two Pin (red): A red LED for indicating danger or high alert conditions.
  • LED: Two Pin (green): A green LED for indicating safe conditions.
  • LED: Two Pin (yellow): A yellow LED for indicating caution or medium alert conditions.

Display

  • OLED 1.3": A small OLED display for showing sensor data and status messages.

Passive Components

  • Resistor (220 Ohms): Three resistors used to limit current to the LEDs.

Wiring Details

Arduino Nano

  • GND: Connected to the ground pins of all components.
  • D2: Connected to the DATA pin of the DHT11 sensor.
  • D3: Connected to the LED pin of the GP2Y1010AU0F sensor.
  • D4, D5, D6: Connected to the second pins of the 220 Ohm resistors, which are connected to the anodes of the green, yellow, and red LEDs, respectively.
  • D7: Connected to the PIN of the buzzer.
  • 5V: Connected to the VCC pins of the GP2Y1010AU0F, DHT11, OLED display, and MQ135 sensor.
  • A5: Connected to the SCL pin of the OLED display.
  • A4: Connected to the SDA pin of the OLED display.
  • A1: Connected to the Vout pin of the GP2Y1010AU0F sensor.
  • A0: Connected to the A0 pin of the MQ135 sensor.

DHT11

  • DATA: Connected to D3 on the Arduino Nano.
  • GND: Connected to the common ground.
  • VCC: Connected to 5V on the Arduino Nano.

GP2Y1010AU0F

  • LED: Connected to D2 on the Arduino Nano.
  • Vout: Connected to A1 on the Arduino Nano.
  • S-GND, LED-GND: Connected to the common ground.
  • VCC, V-LED: Connected to 5V on the Arduino Nano.

MQ135

  • A0: Connected to A0 on the Arduino Nano.
  • GND: Connected to the common ground.
  • VCC: Connected to 5V on the Arduino Nano.

OLED 1.3"

  • SCL: Connected to A5 on the Arduino Nano.
  • SDA: Connected to A4 on the Arduino Nano.
  • GND: Connected to the common ground.
  • VCC: Connected to 5V on the Arduino Nano.

LEDs (Red, Green, Yellow)

  • Cathode: Connected to the common ground.
  • Anode: Connected to the second pin of the respective 220 Ohm resistor, which is connected to D4 (green), D5 (yellow), or D6 (red) on the Arduino Nano.

Buzzer

  • PIN: Connected to D7 on the Arduino Nano.
  • GND: Connected to the common ground.

Resistors (220 Ohms)

  • Pin1: Connected to the anode of the respective LED (red, green, or yellow).
  • Pin2: Connected to D4 (green), D5 (yellow), or D6 (red) on the Arduino Nano.

Documented Code

// Include necessary libraries
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Wire.h>
#include <DHT.h>

// Pin definitions
#define MQ135_PIN A0
#define DHT_PIN 2
#define BUZZER_PIN 7
#define GREEN_LED_PIN 4
#define YELLOW_LED_PIN 5
#define RED_LED_PIN 6
#define DUST_LED_PIN 3
#define DUST_SENSOR_PIN A1

// DHT sensor setup
#define DHT_TYPE DHT11
DHT dht(DHT_PIN, DHT_TYPE);

// OLED display setup
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1); // OLED display

// Threshold values for alarms
const int MQ135_THRESHOLD = 300;  // Example value for gas level
const int DUST_THRESHOLD = 150;   // Example value for dust density
const float TEMP_THRESHOLD = 30.0; // Example value for temperature in °C

void setup() {
  // Initialize Serial Monitor
  Serial.begin(9600);

  // Initialize pins
  pinMode(GREEN_LED_PIN, OUTPUT);
  pinMode(YELLOW_LED_PIN, OUTPUT);
  pinMode(RED_LED_PIN, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(DUST_LED_PIN, OUTPUT);

  // Initialize DHT sensor
  dht.begin();

  // Initialize OLED display
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;);
  }
  display.clearDisplay();

  // Start with LEDs and buzzer off
  digitalWrite(GREEN_LED_PIN, LOW);
  digitalWrite(YELLOW_LED_PIN, LOW);
  digitalWrite(RED_LED_PIN, LOW);
  digitalWrite(BUZZER_PIN, LOW);
}

void loop() {
  // Read gas level from MQ-135
  int mq135_value = analogRead(MQ135_PIN);
  Serial.print("Gas level: ");
  Serial.println(mq135_value);

  // Read dust density from GP2Y1010AU0F
  digitalWrite(DUST_LED_PIN, LOW); // Turn on IR LED for dust sensor
  delayMicroseconds(280);
  int dust_value = analogRead(DUST_SENSOR_PIN);
  delayMicroseconds(40);
  digitalWrite(DUST_LED_PIN, HIGH); // Turn off IR LED
  Serial.print("Dust density: ");
  Serial.println(dust_value);

  // Read temperature and humidity from DHT11
  float temperature = dht.readTemperature();
  float humidity = dht.readHumidity();
  Serial.print("Temperature: ");
  Serial.println(temperature);
  Serial.print("Humidity: ");
  Serial.println(humidity);

  // Display data on OLED
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.print("Gas Level: ");
  display.println(mq135_value);
  display.print("Dust: ");
  display.println(dust_value);
  display.print("Temp: ");
  display.print(temperature);
  display.println(" C");
  display.print("Humidity: ");
  display.print(humidity);
  display.println(" %");
  display.display();

  // LED and buzzer alerts based on thresholds
  if (mq135_value > MQ135_THRESHOLD || dust_value > DUST_THRESHOLD || temperature > TEMP_THRESHOLD) {
    digitalWrite(RED_LED_PIN, HIGH);  // Turn on red LED for danger
    digitalWrite(BUZZER_PIN, HIGH);   // Sound buzzer
  } else if (mq135_value > MQ135_THRESHOLD / 2 || dust_value > DUST_THRESHOLD / 2) {
    digitalWrite(YELLOW_LED_PIN, HIGH);  // Turn on yellow LED for caution
    digitalWrite(RED_LED_PIN, LOW);
    digitalWrite(BUZZER_PIN, LOW);
  } else {
    digitalWrite(GREEN_LED_PIN, HIGH);   // Turn on green LED for safe condition
    digitalWrite(YELLOW_LED_PIN, LOW);
    digitalWrite(RED_LED_PIN, LOW);
    digitalWrite(BUZZER_PIN, LOW);
  }

  // Small delay before next loop
  delay(2000);
}

This code is designed to read sensor data, display it on an OLED screen, and activate LEDs and a buzzer based on predefined threshold values. It includes initialization for the DHT11 sensor and the OLED display, as well as continuous monitoring and alerting in the main loop.