This circuit is designed to monitor environmental conditions such as gas levels, dust density, temperature, and humidity. It uses an Arduino Nano microcontroller to read data from various sensors and display the information on an OLED screen. The circuit also includes LEDs and a buzzer to provide visual and auditory alerts based on predefined threshold values.
Arduino Nano
DHT11
Buzzer
LED: Two Pin (red)
LED: Two Pin (green)
LED: Two Pin (yellow)
Resistor (220 Ohms)
GP2Y1010AU0F
MQ135
OLED 1.3"
// 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 (