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

Arduino UNO Based Environmental Monitoring System with LCD Display

Image of Arduino UNO Based Environmental Monitoring System with LCD Display

Circuit Documentation

Summary

The circuit is designed to monitor environmental parameters such as temperature, humidity, rain presence, and air quality, and display the information on an LCD screen. It uses an Arduino UNO as the central microcontroller to interface with a DHT11 humidity and temperature sensor, a YL-83 rain sensor, an MQ-2 gas sensor, and an HC-SR04 ultrasonic sensor. The data from these sensors is displayed on a 16x2 LCD. The circuit also includes resistors for current limiting and voltage adjustment purposes.

Component List

Arduino UNO

  • Microcontroller board based on the ATmega328P
  • Provides digital and analog I/O pins for interfacing with various sensors and devices

16X2 LCD

  • Alphanumeric liquid crystal display
  • Capable of displaying 16 characters per line across 2 lines

DHT11 Humidity and Temperature Sensor

  • Measures ambient humidity and temperature
  • Provides digital output data

YL-83 Rain Sensor - Control Board

  • Detects raindrops through the analog output
  • Provides digital output for rain detection

Ultrasonic Sensor (HC-SR04)

  • Measures distance by emitting ultrasonic waves and timing their return
  • Provides precise, non-contact distance measurements

Resistor (1k Ohms)

  • Used for current limiting or voltage division
  • Resistance: 1000 Ohms

Resistor (200 Ohms)

  • Used for current limiting or voltage division
  • Resistance: 200 Ohms

MQ-2 Gas Sensor

  • Detects various combustible gases and smoke
  • Provides both analog and digital outputs

Wiring Details

Arduino UNO

  • 5V and GND pins provide power to the sensors and LCD
  • Digital pins D2 to D13 and analog pin A0 are used for interfacing with sensors and the LCD

16X2 LCD

  • VSS, RW, and K pins are connected to GND
  • VDD pin is connected to 5V
  • V0 pin is connected to a 1k Ohm resistor for contrast adjustment
  • RS, E, D4 to D7 pins are connected to Arduino digital pins for data/command transmission
  • A pin is connected to a 200 Ohm resistor for backlight control

DHT11 Humidity and Temperature Sensor

  • VDD pin is connected to 5V through a 200 Ohm resistor
  • DATA pin is connected to Arduino digital pin D2
  • GND pin is connected to GND

YL-83 Rain Sensor - Control Board

  • VCC pin is connected to 5V through a 200 Ohm resistor
  • GND pin is connected to GND
  • DO pin is connected to Arduino digital pin D3

Ultrasonic Sensor (HC-SR04)

  • +VCC pin is connected to 5V through a 200 Ohm resistor
  • Trigger pin is connected to Arduino digital pin D6
  • Echo pin is connected to Arduino digital pin D13
  • GND pin is connected to GND

Resistor (1k Ohms)

  • One end is connected to the V0 pin of the LCD for contrast control

Resistor (200 Ohms)

  • One end is connected to the A pin of the LCD for backlight control
  • Other end is connected to the power supply lines of the sensors

MQ-2 Gas Sensor

  • VCC pin is connected to 5V through a 200 Ohm resistor
  • GND pin is connected to GND
  • ANALOG pin is connected to Arduino analog pin A0

Documented Code

#include <DHT.h>
#include <LiquidCrystal.h>
#include <NewPing.h> // Include the NewPing library for the ultrasonic sensor

#define DHTPIN 2
#define DHTTYPE DHT11
#define TRIG_PIN 6
#define ECHO_PIN 13
#define MAX_DISTANCE 200

#define GAS_LOW_THRESHOLD 40 // Upper limit for Low AQI
#define GAS_MEDIUM_THRESHOLD 60 // Upper limit for Medium AQI
#define DISTANCE_THRESHOLD 7 // Distance in cm for covering the sensor
#define PAGE_INTERVAL 3000 // Interval in milliseconds to change pages

DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // Update the pin numbers according to your setup

NewPing sonar(TRIG_PIN, ECHO_PIN, MAX_DISTANCE);

const int rainSensorPin = 3;
const int gasSensorAnalogPin = A0;

int currentPage = 0; // Variable to store the current page
unsigned long lastChangeTime = 0; // Variable to store the last time the page was changed

void setup() {
  lcd.begin(16, 2);
  dht.begin();
  Serial.begin(9600);
  pinMode(rainSensorPin, INPUT);
}

void loop() {
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  int rainStatus = digitalRead(rainSensorPin);
  int gasAnalog = analogRead(gasSensorAnalogPin);

  // Calculate AQI percentage
  int gasPercentage = map(gasAnalog, 0, 1023, 0, 100); // Map directly from 0% bad to 100% good

  // Debugging print statements
  Serial.print("Gas Analog Value: ");
  Serial.println(gasAnalog);
  Serial.print("Mapped Gas Percentage: ");
  Serial.println(gasPercentage);

  // Determine AQI category
  String gasStatus;
  if (gasPercentage <= GAS_LOW_THRESHOLD) {
    gasStatus = "Low";
  } else if (gasPercentage <= GAS_MEDIUM_THRESHOLD) {
    gasStatus = "Medium";
  } else {
    gasStatus = "High";
  }

  delay(100);

  unsigned int uS = sonar.ping();
  int distance = uS / US_ROUNDTRIP_CM;

  if (distance >= DISTANCE_THRESHOLD) {
    if (millis() - lastChangeTime >= PAGE_INTERVAL) {
      currentPage = (currentPage + 1) % 2; // Swap pages every PAGE_INTERVAL milliseconds
      lastChangeTime = millis(); // Update the last change time
    }
  } else {
    lastChangeTime = millis(); // Reset the last change time if an object is detected
  }

  lcd.clear();
  if (currentPage == 0) {
    lcd.setCursor(0, 0);
    lcd.print("Temp: ");
    lcd.print((int)t - 2); // Display temperature as an integer
    lcd.print((char)223); // Degree symbol
    lcd.print("C");

    lcd.setCursor(0, 1);
    lcd.print("Rain: ");
    lcd.print(rainStatus == HIGH ? "Yes" : "No");
  } else if (currentPage == 1) {
    lcd.setCursor(0, 0);
    lcd.print("Humidity: ");
    lcd.print((int)h); // Display humidity as an integer
    lcd.print("%");

    lcd.setCursor(0, 1);
    lcd.print("AQI: ");
    lcd.print(gasStatus);
    lcd.print(" ");
    lcd.print(gasPercentage); // Display AQI percentage
    lcd.print("%");
  }

  // Print to Serial for debugging
  Serial.print("Temp: ");
  Serial.print((int)t); // Print temperature as an integer
  Serial.print(" C, Humidity: ");
  Serial.print((int)h); // Print humidity as an integer
  Serial.print(" %, Rain: ");
  Serial.print(rainStatus == HIGH ? "Yes" : "No");
  Serial.print(", Gas Level: ");
  Serial.print(gasStatus);
  Serial.print(" (");
  Serial.print(gasPercentage); // Print gas percentage
  Serial.println("%)");
  delay(1000);
}

This code is designed to run on the Arduino UNO microcontroller. It initializes the sensors and LCD, reads data from the sensors, and displays the information on the LCD. It also prints the sensor data to the serial monitor for debugging purposes. The code includes functionality to switch between different display pages based on a time interval or the presence of an object near the ultrasonic sensor.