Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Voltaat Arduino Ultimate Kit
120 min
Share

Simple Weather Station with LCD Display

There is no need to stare out the window or constantly check your phone for the latest weather updates! You can make your own weather station that will provide you with real-time weather information.

Project Video

Overview

For this tutorial, we will use the DHT11 sensor to monitor temperature and humidity levels and the rain sensor to detect rain status. Finally, we’ll display all this data on the LCD.

Getting the Items

Arduino Uno R3 (Voltaat Version)
Get Item
DHT11 Temperature & Humidity Sensor
Get Item
Raindrops Detection Sensor
Get Item
2×16 LCD with I2C Module
Get Item
Half-size Breadboard
Get Item
Jumper Wires - Male to Male (40 Pack)
Get Item
Jumper Wires – Male to Female (40 Pack)
Get Item

Steps

Wiring it Up

Follow the wiring diagram shown in the image below to connect the DHT11, raindrops sensor and the LCD to the Arduino.

 Connections from the Arduino to the breadboard:
 
    • Arduino 5v pin → breadboard 5v line
    • Arduino GND pin → breadboard GND line


 Connection form the DHT11:

   • GND pin → Arduino GND pin
   • Signal pin → Arduino digital pin 2
   • VCC pin → Arduino 5V pin


 Connection from the raindrops sensor:

   • VCC pin → breadboard 5v line
   • GND pin → breadboard GND line
   • Signal pin → Arduino analog pin A0


 Connection from the LCD:

   • VCC pin → breadboard 5v line
    • GND pin→ breadboard GND line
   • SDA pin→ Arduino analog pin A4
    • SCL pin → Arduino analog pin A5

Coding

/*

 Voltaat learn (http://learn.voltaat.com)

 Link for full tutorial:

 DHT11 library:

 Adafruit sensor Library:

 Wire Library:

 LiquidCrystal I2C Library:

 Tutorial: Simple Weather Station with LCD Display

 

 Connections from the Arduino to the breadboard:

 

 • Arduino 5v pin → breadboard 5v line

 • Arduino GND pin → breadboard GND line

 Connection form the DHT11:

 • GND pin → Arduino GND pin

 • Signal pin → Arduino digital pin 2

 • VCC pin → Arduino 5V pin

 Connection from the raindrops sensor:

 • VCC pin → breadboard 5v line

 • GND pin → breadboard GND line

 • Signal pin → Arduino analog pin A0

 Connection from the LCD:

 • VCC pin → breadboard 5v line

 • GND pin→ breadboard GND line

 • SDA pin→ Arduino analog pin A4

 • SCL pin → Arduino analog pin A5

*/

// Define libraries

#include "Wire.h" // include the Wire library for I2C communication

#include "LiquidCrystal_I2C.h" // include the LiquidCrystal_I2C library for the LCD display

#include "DHT.h" // include the DHT library for the DHT11 sensor

const int rainSensorPin = A0; // The analog pin that the rain sensor is connected to

DHT dht (2, DHT11); // Initialize the DHT11 sensor on digital pin 2

const float heavyRainfallThreshold = 2.0; // Threshold for heavy rainfall

LiquidCrystal_I2C lcd(0x27, 16, 2); // Initialize the LCD display

float prevT = -999.0; // Initialize previous temperature to an invalid value

float prevH = -999.0; // Initialize previous humidity to an invalid value

bool prevRain = false; // Initialize previous rain value to false

//Commands inside void setup run once

void setup() {

 Serial.begin(9600); // Initialize serial communication at 9600 bits per second

 lcd.init(); // Initialize the LCD display

 lcd.backlight(); // Turn on the backlight

 dht.begin(); // Start the DHT11 sensor

 pinMode(rainSensorPin, INPUT); // Set the rain sensor pin as an input

 lcd.clear(); // Clear the LCD display

 lcd.setCursor(1, 0); // Set the cursor to the first row, second column

 lcd.print("Voltaat Learn"); // Display a welcome message

 delay(3000); // Wait for 3 seconds

 lcd.clear(); // Clear the LCD display

 lcd.setCursor(3, 0); // Set the cursor to the first row, fourth column

 lcd.print("Welcome to"); // Display a welcome message

 lcd.setCursor(1, 1); // Set the cursor to the second row, second column

 lcd.print("Weather Station"); // Display a welcome message

 delay(3000); // Wait for 3 seconds

}

//Commands inside void loop run forever

void loop() {

 float T = dht.readTemperature(); // Read the temperature from the DHT11 sensor

 float H = dht.readHumidity(); // Read the humidity from the DHT11 sensor

 int rainSensorValue = analogRead(rainSensorPin); // Read the value from the rain sensor

 bool isRaining = rainSensorValue < 500; // Determine if it is currently raining

 // Only update the display if the values have changed

 if (T != prevT || H != prevH || isRaining != prevRain) {

   lcd.setCursor(2, 0); // Set the cursor to the first row, third column

   lcd.print("Temp: "); // Display the temperature label

   lcd.print(T); // Display the temperature

   lcd.print((char)223); // Display the degree symbol

   lcd.print("C"); // Display the Celsius unit

   lcd.setCursor(0, 1); // Set the cursor to the second row, first column

   if (isRaining) { // If it is currently raining

     lcd.print("Raining "); // Display the rain status

   } else { // If it is not currently raining

     lcd.print("No Rain "); // Display the rain status

   }

   lcd.print("H:"); // Display the humidity label

   lcd.print(H); // Display the humidity

   lcd.print("%"); // Display the percentage symbol

   // Store the current values as previous values for the next update

   prevT = T;

   prevH = H;

   prevRain = isRaining;

 }

 delay(2000); // Wait for 2 seconds

}

Testing it Out

After connecting the DHT11 and raindrop sensor to the Arduino and uploading the code, the LCD screen will display “Voltaat Learn” for 3 seconds. Then it will display “Welcome to Weather Station” for another 3 seconds.

Then it will display the temperature value in Celsius degrees and the humidity value in percentages, besides the rain status.

Resources

No items found.