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

ESP8266-Based Air Quality Monitoring System with LCD Display and Wi-Fi Connectivity

Image of ESP8266-Based Air Quality Monitoring System with LCD Display and Wi-Fi Connectivity

Air Quality Monitoring System

Summary

This document provides a detailed overview of an Air Quality Monitoring System circuit. The system utilizes various sensors and components to monitor air quality, temperature, humidity, and pressure. The data is displayed on an LCD and can be monitored remotely using the Blynk platform. The system also includes a buzzer that triggers an alert when air quality or temperature exceeds predefined thresholds.

Component List

  1. LED: Two Pin (red)

    • Pins: Cathode, Anode
    • Description: A red LED used for visual indication.
    • Purpose: Provides visual feedback in the circuit.
  2. 16x2 I2C LCD

    • Pins: GND, VCC, SDA, SCL
    • Description: A 16x2 character LCD with I2C interface.
    • Purpose: Displays sensor data.
  3. Buzzer

    • Pins: GND, IN
    • Description: A piezoelectric buzzer.
    • Purpose: Provides audible alerts.
  4. MQ 135

    • Pins: D OUT, A OUT, GND, VCC
    • Description: Air quality sensor.
    • Purpose: Measures air quality.
  5. ESP8266 NodeMCU

    • Pins: D0, D1, D2, D3, D4, 3V3, GND, D5, D6, D7, D8, RX, TX, A0, RSV, SD3, SD2, SD1, CMD, SD0, CLK, EN, RST, VIN
    • Description: WiFi-enabled microcontroller.
    • Purpose: Central control unit for the system.
  6. BMP280

    • Pins: SDO, CSB, SDA, SCL, GND, VCC
    • Description: Barometric pressure sensor.
    • Purpose: Measures atmospheric pressure and altitude.
  7. KY-015 DHT11 Temperature-Humidity Sensor Module

    • Pins: VCC, GND, DOUT
    • Description: Temperature and humidity sensor.
    • Purpose: Measures temperature and humidity.

Wiring Details

LED: Two Pin (red)

  • Cathode: Connected to GND (shared with Buzzer and BMP280)
  • Anode: Connected to D6 on ESP8266 NodeMCU (shared with Buzzer)

16x2 I2C LCD

  • GND: Connected to GND on ESP8266 NodeMCU
  • VCC: Connected to 3V3 on ESP8266 NodeMCU
  • SDA: Connected to D2 on ESP8266 NodeMCU (shared with BMP280)
  • SCL: Connected to D1 on ESP8266 NodeMCU (shared with BMP280)

Buzzer

  • GND: Connected to GND (shared with LED and BMP280)
  • IN: Connected to D6 on ESP8266 NodeMCU (shared with LED)

MQ 135

  • A OUT: Connected to A0 on ESP8266 NodeMCU
  • GND: Connected to GND on ESP8266 NodeMCU
  • VCC: Connected to VIN on ESP8266 NodeMCU

ESP8266 NodeMCU

  • GND: Connected to GND of various components (16x2 I2C LCD, Buzzer, LED, BMP280, MQ 135, KY-015 DHT11)
  • 3V3: Connected to VCC of various components (16x2 I2C LCD, KY-015 DHT11, BMP280)
  • D2: Connected to SDA of 16x2 I2C LCD and BMP280
  • D1: Connected to SCL of 16x2 I2C LCD and BMP280
  • D6: Connected to Anode of LED and IN of Buzzer
  • A0: Connected to A OUT of MQ 135
  • VIN: Connected to VCC of MQ 135
  • D4: Connected to DOUT of KY-015 DHT11

BMP280

  • SDA: Connected to D2 on ESP8266 NodeMCU (shared with 16x2 I2C LCD)
  • SCL: Connected to D1 on ESP8266 NodeMCU (shared with 16x2 I2C LCD)
  • GND: Connected to GND (shared with LED and Buzzer)
  • VCC: Connected to 3V3 on ESP8266 NodeMCU

KY-015 DHT11 Temperature-Humidity Sensor Module

  • VCC: Connected to 3V3 on ESP8266 NodeMCU
  • GND: Connected to GND on ESP8266 NodeMCU
  • DOUT: Connected to D4 on ESP8266 NodeMCU

Documented Code

#define BLYNK_TEMPLATE_ID "TMPL3ljJ3Anak"
#define BLYNK_TEMPLATE_NAME "Air Quality Montoring System"
#define BLYNK_AUTH_TOKEN "bhqwFBHQez9JeTN8mEHTZhLkci9Dwdo2"

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// Pin Definitions
#define DHTPIN D4
#define DHTTYPE DHT11
#define MQ135_PIN A0
#define BUZZER_PIN D6

// Objects Initialization
DHT dht(DHTPIN, DHTTYPE);
Adafruit_BMP280 bmp; // Default I2C address 0x76
LiquidCrystal_I2C lcd(0x27, 16, 2);

// WiFi credentials
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Arjit Mittal";
char pass[] = "Arjit@3005";

// Blynk Timer
BlynkTimer timer;

void setup() {
  // Serial Monitor
  Serial.begin(115200);

  // Initialize Blynk
  Blynk.begin(auth, ssid, pass);

  // Initialize DHT11
  dht.begin();

  // Initialize LCD
  lcd.init();
  lcd.backlight();

   // Display startup message
  lcd.setCursor(0, 0);
  lcd.print("GROUP 4");
  lcd.setCursor(0, 1);
  lcd.print("AIR MONITORING");
  delay(2000);

  // Set Buzzer pin
  pinMode(12, OUTPUT);

    // Initialize BMP280
  if (!bmp.begin(0x76)) {
    Serial.println("Could not find BMP280 sensor!");
    while (1);
  }

  // Timer to read sensors and update Blynk
  timer.setInterval(2000L, readSensors);
}

void readSensors() {
  // Read DHT11 data
  float temperatureDHT = dht.readTemperature();
  float humidity = dht.readHumidity();

  // Read BMP280 data
  float pressure = bmp.readPressure() / 100.0F; // Convert to hPa
  float altitude = bmp.readAltitude(1013.25); // Standard sea level pressure

  // Read MQ135 data
  int airQuality = analogRead(MQ135_PIN);

  // Display data on LCD
   lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.print(temperatureDHT);
  lcd.print("C");
  lcd.setCursor(0, 1);
  lcd.print("Hum: ");
  lcd.print(humidity);
  lcd.print("%");
  
  delay(5000);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Air Quality: ");
  lcd.print(airQuality);
  lcd.setCursor(0, 1);
  lcd.print("Pressure: ");
  lcd.print(pressure);
  lcd.print("hPa");

  delay(4000);

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Altitude: ");
  lcd.print(altitude);

  delay(3000);
  

  // Push data to Blynk
  Blynk.virtualWrite(V0, temperatureDHT);
  Blynk.virtualWrite(V1, humidity);
  Blynk.virtualWrite(V2, airQuality);
  Blynk.virtualWrite(V3, pressure);
  Blynk.virtualWrite(V4, altitude);

  // Trigger buzzer if air quality exceeds threshold
  if (airQuality > 350 || temperatureDHT > 30) {
    digitalWrite(12, HIGH);
    // Blynk.email("prakharg.1981@gmail.com", "Alert", "Temperature over 28C!");
    Blynk.logEvent("pollution_alert","High Air Quality Detected!");
  } else {
    digitalWrite(12, LOW);
  }
}

void loop() {
  Blynk.run();
  timer.run();
}

This code initializes the sensors and the LCD, reads data from the sensors, displays the data on the LCD, and sends the data to the Blynk platform. The buzzer is triggered if the air quality or temperature exceeds predefined thresholds.