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

Arduino UNO Based Weather Station with I2C Sensors and LCD Display

View and Edit Project In Cirkit DesignerImage of Arduino UNO Based Weather Station with I2C Sensors and LCD Display

Weather Station Circuit Documentation

Summary

The circuit is designed to create a weather station that measures temperature, humidity, atmospheric pressure, and light intensity, and detects rain. It uses an Arduino UNO as the central microcontroller to interface with various sensors including a DHT22 for temperature and humidity, a BMP180 for atmospheric pressure, an RTC DS3231 for real-time clock functionality, an LDR module for light intensity, and a rain sensor. The data from these sensors is displayed on an I2C LCD 16x2 screen. The circuit is powered by a 9V battery connected through a 2.1mm male connector.

Component List

Wiring Details

DHT22

Arduino UNO

BMP180

RTC DS3231

I2C LCD 16x2 Screen

9V Battery

2.1mm Male Connector

Rain Sensor

LDR Module 3 pin

Documented Code

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#include <RTClib.h>  // RTC library for DS3231 or DS1307

#define DHTPIN 2       // Change pin according to your ESP8266 GPIO
#define DHTTYPE DHT22  // Type of DHT sensor
DHT dht(DHTPIN, DHTTYPE);

Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085);

// ESP8266 uses GPIO4 (D2) and GPIO5 (D1) for I2C by default
LiquidCrystal_I2C lcd(0x27, 16, 2);  // LCD I2C address

RTC_DS3231 rtc; // Initialize RTC object

void setup() {
  Serial.begin(115200);  // Use a higher baud rate for ESP8266
  dht.begin();
  
  // Initialize the BMP180 sensor
  if (!bmp.begin()) {
    Serial.println("Could not find a valid BMP085 sensor, check wiring!");
    while (1);
  }

  // Initialize RTC
  if (!rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  // Check if RTC lost power
  if (rtc.lostPower()) {
    Serial.println("RTC lost power, setting the time!");
    // The following line sets the RTC to the compile time
    rtc.adjust(DateTime(F(_DATE), F(TIME_)));
  }
  
  lcd.begin(16, 2);  // Initialize LCD
  lcd.backlight();   // Turn on backlight
  
  // Display welcome message
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Weather Station");
  delay(2000); // Display for 2 seconds
}

void loop() {
  delay(2000);

  // Read temperature and humidity from DHT22
  float humidity = dht.readHumidity();
  float temperature = dht.readTemperature();
  
  if (isnan(humidity) || isnan(temperature)) {
    Serial.println("Failed to read from DHT sensor!");
  } else {
    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.print(" %\t");
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" *C");
  }

  // Read pressure from BMP180
  sensors_event_t event;
  bmp.getEvent(&event);
  if (event.pressure) {
    Serial.print("Pressure: ");
    Serial.print(event.pressure);
    Serial.println(" hPa");
  } else {
    Serial.println("Failed to read from BMP180!");
  }

  // Get current time from RTC
  DateTime now = rtc.now();
  
  // Display values on the LCD

    // Display the time on LCD
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Time: ");
  lcd.print(now.hour(), DEC);
  lcd.print(":");
  lcd.print(now.minute(), DEC);
  lcd.print(":");
  lcd.print(now.second(), DEC);
  lcd.setCursor(0, 1);
  lcd.print("Date: ");
  lcd.print(now.day(), DEC);
  lcd.print("/");
  lcd.print(now.month(), DEC);
  lcd.print("/");
  lcd.print(now.year(), DEC);
  
  delay(2000); // Update every 2 seconds
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Temp: ");
  lcd.print(temperature);
  lcd.print(" C");
  lcd.setCursor(0, 1);
  lcd.print("Hum: ");
  lcd.print(humidity);
  lcd.print(" %");

  delay(2000); // Update every 2 seconds
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Pressure: ");
  lcd.print(event.pressure);
  lcd.print(" hPa");
  lcd.setCursor(0, 1);
  lcd.print("Rain: ");
  lcd.print(analogRead(A0));  // Use the appropriate pin for rain sensor
  
  delay(2000);  // Update every 2 seconds
  
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("LDR: ");
  lcd.print(analogRead(A1));  // Use the appropriate pin for LDR
  lcd.setCursor(0, 1);
  lcd.print("Light Int.");

  delay(2000);  // Update every 2 seconds
}

This code is designed to run on an Arduino UNO and interfaces with the various sensors to collect data, which is then displayed on the LCD screen. The code includes initialization and error checking for each sensor, as well as functions to read and display the sensor data. The RTC module is used to display the current time and date. The LCD screen displays the weather station's welcome message, temperature, humidity, pressure, rain sensor data, and light intensity in a rotating fashion, updating every 2 seconds.