#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHTPIN 15 // Pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302)
// Initialize the LCD with the I2C address 0x27 and 16x2 size
LiquidCrystal_I2C lcd(0x27, 16, 2);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// Initialize the LCD and the DHT sensor
lcd.init();
lcd.backlight();
dht.begin();
// Display welcome message
lcd.setCursor(0, 0);
lcd.print("Temp & Humidity");
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
float h = dht.readHumidity();
float t = dht.readTemperature();
// Check if any reads failed
if (isnan(h) || isnan(t)) {
lcd.setCursor(0, 1);
lcd.print("Error reading!");
return;
}
// Print temperature and humidity on the LCD
lcd.setCursor(0, 1);
lcd.print("T:");
lcd.print(t);
lcd.print("C H:");
lcd.print(h);
lcd.print("%");
// Update readings every 2 seconds
delay(2000);
}