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

Arduino UNO-Based Weather Station with LCD Display and Multiple Sensors

Image of Arduino UNO-Based Weather Station with LCD Display and Multiple Sensors

Circuit Documentation

Summary

This circuit is designed to monitor environmental conditions using various sensors and display the data on a 16x2 LCD. The circuit includes an Arduino UNO microcontroller, a DHT11 humidity and temperature sensor, a YL-83 rain sensor, an ultrasonic sensor, an MQ-2 gas sensor, a BMP180 barometric pressure sensor, and a 16x2 LCD display. The Arduino UNO reads data from the sensors and displays the information on the LCD. The circuit also includes resistors to ensure proper voltage levels for certain components.

Component List

  1. Arduino UNO

    • Description: Microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. 16x2 LCD

    • Description: Liquid Crystal Display with 16 columns and 2 rows.
    • Pins: VSS, VDD, V0, RS, RW, E, D1, D0, D2, D3, D4, D6, D5, D7, A, K
  3. DHT11 Humidity and Temperature Sensor

    • Description: Sensor for measuring humidity and temperature.
    • Pins: VDD, DATA, NULL, GND
  4. YL-83 Rain Sensor - Control Board

    • Description: Sensor for detecting rain.
    • Pins: VCC, GND, DO, AO, POS, NEG
  5. Ultrasonic Sensor

    • Description: Sensor for measuring distance using ultrasonic waves.
    • Pins: +VCC, Trigger, Echo, GND
  6. Resistor (1k Ohms)

    • Description: Resistor with a resistance of 1000 Ohms.
    • Pins: pin1, pin2
  7. Resistor (200 Ohms)

    • Description: Resistor with a resistance of 200 Ohms.
    • Pins: pin1, pin2
  8. MQ-2 Gas Sensor

    • Description: Sensor for detecting gas levels.
    • Pins: GND, VCC, ANALOG, Digital
  9. BMP180 Barometric Pressure Sensor

    • Description: Sensor for measuring barometric pressure.
    • Pins: 3.3, SDA, SCL, GND, VCC

Wiring Details

Arduino UNO

  • 5V: Connected to VDD of 16x2 LCD, VCC of YL-83 Rain Sensor, +VCC of Ultrasonic Sensor, VCC of MQ-2 Gas Sensor, VCC of BMP180, and VDD of DHT11 Humidity and Temperature Sensor.
  • GND: Connected to VSS, RW, and K of 16x2 LCD, GND of YL-83 Rain Sensor, GND of Ultrasonic Sensor, GND of MQ-2 Gas Sensor, GND of BMP180, and GND of DHT11 Humidity and Temperature Sensor.
  • A0: Connected to ANALOG of MQ-2 Gas Sensor.
  • A4: Connected to SDA of BMP180.
  • A5: Connected to SCL of BMP180.
  • D13: Connected to Echo of Ultrasonic Sensor.
  • D12: Connected to D7 of 16x2 LCD.
  • D11: Connected to D6 of 16x2 LCD.
  • D10: Connected to D5 of 16x2 LCD.
  • D9: Connected to D4 of 16x2 LCD.
  • D8: Connected to E of 16x2 LCD.
  • D7: Connected to RS of 16x2 LCD.
  • D6: Connected to Trigger of Ultrasonic Sensor.
  • D3: Connected to DO of YL-83 Rain Sensor.
  • D2: Connected to DATA of DHT11 Humidity and Temperature Sensor.

16x2 LCD

  • VSS: Connected to GND.
  • VDD: Connected to 5V.
  • V0: Connected to pin1 of 1k Ohm Resistor.
  • RS: Connected to D7 of Arduino UNO.
  • RW: Connected to GND.
  • E: Connected to D8 of Arduino UNO.
  • D4: Connected to D9 of Arduino UNO.
  • D5: Connected to D10 of Arduino UNO.
  • D6: Connected to D11 of Arduino UNO.
  • D7: Connected to D12 of Arduino UNO.
  • A: Connected to pin1 of 200 Ohm Resistor.
  • K: Connected to GND.

DHT11 Humidity and Temperature Sensor

  • VDD: Connected to 5V.
  • DATA: Connected to D2 of Arduino UNO.
  • GND: Connected to GND.

YL-83 Rain Sensor - Control Board

  • VCC: Connected to 5V.
  • GND: Connected to GND.
  • DO: Connected to D3 of Arduino UNO.

Ultrasonic Sensor

  • +VCC: Connected to 5V.
  • Trigger: Connected to D6 of Arduino UNO.
  • Echo: Connected to D13 of Arduino UNO.
  • GND: Connected to GND.

Resistor (1k Ohms)

  • pin1: Connected to V0 of 16x2 LCD.
  • pin2: Connected to GND.

Resistor (200 Ohms)

  • pin1: Connected to A of 16x2 LCD.
  • pin2: Connected to GND.

MQ-2 Gas Sensor

  • GND: Connected to GND.
  • VCC: Connected to 5V.
  • ANALOG: Connected to A0 of Arduino UNO.

BMP180 Barometric Pressure Sensor

  • 3.3: Not connected.
  • SDA: Connected to A4 of Arduino UNO.
  • SCL: Connected to A5 of Arduino UNO.
  • GND: Connected to GND.
  • VCC: Connected to 5V.

Code Documentation

#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
  }