// #include <DHT.h>
// #include <LiquidCrystal_I2C.h>
// #define DHTPIN 4 // Pin connected to the DHT sensor
// #define DHTTYPE DHT11 // Specify the type of DHT sensor (DHT11 in this case)
// // Uncomment one of the following lines to use a specific DHT sensor model
// //#define DHTTYPE DHT21
// //#define DHTTYPE DHT22
// DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor
// LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD I2C address to 0x27 for a 16x2 display
// void setup() {
// dht.begin(); // Initialize the DHT sensor
// lcd.init(); // Initialize the LCD
// lcd.backlight(); // Turn on the LCD backlight
// }
// void loop() {
// float humidity = dht.readHumidity(); // Read the humidity
// float temperature = dht.readTemperature(); // Read the temperature
// lcd.clear(); // Clear the LCD screen
// lcd.setCursor(0, 0); // Set the cursor to the first row and column
// if (isnan(humidity) || isnan(temperature)) {
// lcd.print("Error reading");
// } else {
// lcd.print("Humidity=");
// lcd.print(humidity); // Print the humidity
// lcd.print("%");
// lcd.setCursor(0, 1); // Set the cursor to the second row and first column
// lcd.print("Temp=");
// lcd.print(temperature); // Print the temperature
// lcd.print("Celsius");
// }
// delay(2000); // Wait for 2 seconds before updating the readings
// }
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 4 // Pin connected to the DHT sensor
#define DHTTYPE DHT11 // Specify the type of DHT sensor (DHT11 in this case)
// Uncomment one of the following lines to use a specific DHT sensor model
//#define DHTTYPE DHT21
//#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor
LiquidCrystal_I2C lcd(0x27, 16, 2); // Set the LCD I2C address to 0x27 for a 16x2 display
void setup() {
dht.begin(); // Initialize the DHT sensor
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on the LCD backlight
}
void loop() {
float humidity = dht.readHumidity(); // Read the humidity
float temperature = dht.readTemperature(); // Read the temperature
lcd.clear(); // Clear the LCD screen
lcd.setCursor(0, 0); // Set the cursor to the first row and column
if (isnan(humidity) || isnan(temperature)) {
lcd.print("Error reading");
} else {
lcd.print("Humidity=");
lcd.print(humidity); // Print the humidity
lcd.print("%");
lcd.setCursor(0, 1); // Set the cursor to the second row and first column
lcd.print("Temp=");
lcd.print(temperature); // Print the temperature
lcd.print("Celsius");
}
delay(2000); // Wait for 2 seconds before updating the readings
}