// Include necessary libraries
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <DHT.h>
// Define the pin for the DHT22 sensor
const int dhtpin = 4;
// Create an object for the LCD display and DHT sensor
LiquidCrystal_I2C lcd(0x27,20,4);
// Create an object for the DHT sensor
DHT Sensor(dhtpin,DHT22);
// Variables to store temperature and humidity values
float temp = 0;
float Humidity = 0;
float c = 0;
float f = 0;
void setup() {
// Initialize the LCD display
lcd.begin(20,4);
lcd.backlight();
// Display a welcome message on the LCD
lcd.setCursor(4,1);
lcd.print("Weather Station");
delay(3000);
// Clear the LCD and initialize the DHT sensor
lcd.clear();
Sensor.begin();
// Set the DHT22 pin as INPUT
pinMode(dhtpin,INPUT);
}
void loop() {
// Read humidity and temperature values from the DHT22 sensor
Humidity = Sensor.readHumidity();
temp = Sensor.readTemperature();
delay(500);
// Convert temperature to Fahrenheit
f= temp * 1.8 + 32;
// Display temperature and humidity on the LCD
lcd.setCursor(0,0);
lcd.print("Temp (F): ");
lcd.print(f,1);
lcd.setCursor(0,1);
lcd.print("Temp(C): ");
lcd.print(temp,1);
lcd.print(" C ");
lcd.setCursor(0,2);
lcd.print("Humidity: ");
lcd.print(Humidity,1);
lcd.print(" % ");
delay(200);
}