//libraries
#include <DHT.h> //importing library for sensor
#include <LiquidCrystal_I2C.h>
//Constants
#define DHTPIN 7 // using number 7
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT sensor
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
//Variables
float hum; //Stores the humidity value
float temp; //Stores the temp value
int sensorPin = A0; // select input pin for the potentiomemter
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// Initialize the LCD
lcd.init();
lcd.backlight();
Serial.begin(9600); // start communication between serial and sensor
dht.begin();
}
void loop() {
// Delay before reading sensor data
delay(2000);
// Read temperature and humidity data
hum = dht.readHumidity();
temp = dht.readTemperature();
// Print temperature and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" C");
// Display temperature and humidity on the LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temp);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print(hum);
lcd.print(" %");
// Delay after displaying temperature and humidity
delay(2000);
}