//FOR DHT22 SENSOR
#include<DHT.h>
#define DHTPIN 8
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
//FOR LCD DISPLAY
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Change address to 0x27 or 0x3F depending on your LCD
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// put your setup code here, to run once:
dht.begin();//for dht
lcd.init(); // Initialize LCD
lcd.backlight(); // Turn on backlight
lcd.setCursor(0, 0);
lcd.print("DHT DATA DISPLAY");
delay(1000); // Pause before starting loop
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
float humidity=dht.readHumidity();
float temperature=dht.readTemperature();
if(isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TEMP: ");
lcd.print(temperature); // Display the counter value
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print("HUMIDITY: ");
lcd.print(humidity);
lcd.print(" "); // Clear any old digits
}