#include <DHT.h>
#include <LiquidCrystal_I2C.h>
// Initializing an instance of the DHT library using the digital pin 12 and the type of the DHT22 sensor
DHT dht(12, 22);
// Initializing two instances of the LiquidCrystal_I2C library using the I2C address 0x26 and 0x27, 16 columns and 2 rows
LiquidCrystal_I2C lcd1(0x26, 16, 2);
LiquidCrystal_I2C lcd2(0x27, 16, 2);
void setup() {
// Starting the serial communication with a baud rate of 9600
Serial.begin(9600);
// Initializing the DHT sensor
dht.begin();
// Initializing and turning on the backlight of the first LCD display
lcd1.init();
lcd1.backlight();
// Initializing and turning on the backlight of the second LCD display
lcd2.init();
lcd2.backlight();
}
void loop() {
delay(2000);// Delay for 2 seconds
float temp = dht.readTemperature();// Reading the temperature from the DHT sensor
float humidity = dht.readHumidity();// Reading the humidity from the DHT sensor
if (isnan(temp) || isnan(humidity))// Checking if the readings are valid
lcd1.home();
lcd2.home();
lcd1.print("Error in DHT sensor.");
lcd2.print("Error in DHT sensor.");// If the readings are not valid, printing an error message to each LCDs
else
{
// If the readings are valid, printing the temperature on the first LCD display
lcd1.home();
lcd1.print("Temperature : ");
lcd1.setCursor(0, 1);
lcd1.print(temp);
// Printing the humidity on the second LCD display
lcd2.home();
lcd2.print("Humidity : ");
lcd2.setCursor(0, 1);
lcd2.print(humidity);
}
}