#include <LiquidCrystal_I2C.h> // include the LCD library
#include <DHT.h> // include the DHT library
#define DHTPIN 2 // define the DHT data pin
#define DHTTYPE DHT22 // define the DHT sensor type
DHT dht(DHTPIN, DHTTYPE); // create a DHT object
LiquidCrystal_I2C lcd(0x27, 16, 2); // create an LCD object
void setup() {
lcd.begin(16, 2); // initialize the LCD with 16 columns and 2 rows
dht.begin(); // initialize the DHT sensor
lcd.init();
lcd.backlight();
}
void loop() {
float humidity = dht.readHumidity(); // read the humidity from the sensor
float temp = dht.readTemperature();
lcd.clear(); // clear the LCD screen
lcd.setCursor(0, 0); // set the cursor to the top left corner
lcd.print("Humidity: "); // display the text "Humidity: "
lcd.print(humidity); // display the humidity value
lcd.print("%"); // display the percent symbol
lcd.setCursor(0,1);
lcd.print("TEMP: ");
lcd.print(temp);
lcd.print("C");
delay(1000); // wait for 1 second
}