Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

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

View and Edit Project In Cirkit DesignerImage 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

16x2 LCD

DHT11 Humidity and Temperature Sensor

YL-83 Rain Sensor - Control Board

Ultrasonic Sensor

Resistor (1k Ohms)

Resistor (200 Ohms)

MQ-2 Gas Sensor

BMP180 Barometric Pressure Sensor

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
  }