This circuit is designed to monitor air quality using gas sensors (MQ-7 and MQ-135), a temperature and humidity sensor (DHT11), and a PIR sensor. The data is displayed on a 16x2 I2C LCD, and visual/auditory alerts are provided using LEDs and a buzzer. The circuit is controlled by an Arduino UNO microcontroller.
LED: Two Pin (green)
Resistor (220 Ohms)
Arduino UNO
LED: Two Pin (red)
Buzzer
DHT11
MQ135
MQ-7 Breakout
16x2 I2C LCD
LED: Two Pin (blue)
PIR sensor
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the Serial Monitor.
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogReadSerial
*/
#include <DHT11.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16 ,2);
// Define sensor pins
int mq7Pin = A0; // MQ-7 analog sensor connected to A0
int mq135Pin = A1; // MQ-135 analog sensor connected to A1
// DHT11 sensor settings
DHT11 dht11(2); // Create an instance of the DHT sensorlcd.begin();
// Define other pins for LEDs and buzzer
int redLED = 3;
int greenLED = 4;
int buzzer = 8;
void setup() {
lcd.init(); // initialize the lcd
lcd.init();
lcd.backlight();
// Start serial communication
Serial.begin(9600);
delay(2000); // Wait for 2 seconds
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
pinMode(buzzer, OUTPUT);
}
void loop() {
// Read gas sensor values (analog)
int mq7Value = analogRead(mq7Pin);
int mq135Value = analogRead(mq135Pin);
// Read temperature and humidity from DHT11
int temperature = 0;
int humidity = 0; // Humidity in percentage
int result = dht11.readTemperatureHumidity(temperature, humidity);
if (result == 0) {
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C\tHumidity: ");
Serial.print(humidity);
Serial.println(" %");
} else {
// Print error message based on the error code.
Serial.println(DHT11::getErrorString(result));
}
// Print values to serial for ESP8266
// Simulate an alert if gas levels are too high (you can change these threshold values)
if (mq7Value > 400 || mq135Value > 400) {
digitalWrite(redLED, HIGH); // Turn on red LED
digitalWrite(greenLED, LOW); // Turn off green LED
digitalWrite(buzzer, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Dangerous gases");
lcd.setCursor(0, 1);
lcd.print("Detected!"); // Turn on buzzer
} else {
digitalWrite(redLED, LOW); // Turn off red LED
digitalWrite(greenLED, HIGH);// Turn on green LED
digitalWrite(buzzer, LOW);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Air is clean"); // Turn off buzzer
}
Serial.print("MQ7: ");
Serial.print(mq7Value);
Serial.print(" | MQ135: ");
Serial.println(mq135Value);
digitalWrite(greenLED, HIGH);
// int dangerousThreshold = 400; // Set a