#include <DHT.h>
#include <Wire.h> // Include Wire library for I2C communication
#include <LiquidCrystal_I2C.h> // Include LCD library for I2C
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD address (usually 0x27 for a 16x2 LCD)
float hum;
float temp;
void setup() {
Serial.begin(9600);
dht.begin();
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the backlight
}
void loop() {
hum = dht.readHumidity();
temp = dht.readTemperature();
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print("%, Temperature: ");
Serial.print(temp);
Serial.println(" degrees Celsius");
lcd.clear(); // Clear the LCD screen
lcd.setCursor(0, 0); // Set the cursor to the first column and first row
lcd.print("Humidity: ");
lcd.print(hum);
lcd.print("%");
lcd.setCursor(0, 1); // Set the cursor to the first column and second row
lcd.print("Temperature: ");
lcd.print(temp);
lcd.print("C");
delay(1000);
}