#include <LiquidCrystal_I2C.h>
#include "DHTesp.h"
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
DHTesp dhtSensor;
void setup() {
//********DHT22*****
Serial.begin(115200);
dhtSensor.setup(15, DHTesp::DHT22);
//************lcd*********
lcd.init(); // initialize the lcd
lcd.backlight();
pinMode(4, OUTPUT);
pinMode(14, OUTPUT);
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
//**************************
lcd.clear(); // clear display
lcd.setCursor(0, 0); // move cursor to (0, 0)
lcd.print("Temp: " + String(data.temperature, 2) + "Clesious"); // print message at (0, 0)
lcd.setCursor(0, 1); // move cursor to (2, 1)
lcd.print("Humidity: " + String(data.humidity, 1) + "%"); // print message at (2, 1)
delay(2000); // display the above for two seconds
if (data.temperature > 40.0) {
digitalWrite(14, HIGH); // Turn on the LED
} else {
digitalWrite(14, LOW); // Turn off the LED
}
if (data.humidity > 60.0) {
digitalWrite(4, HIGH); // Turn on the LED
}
else {
digitalWrite(4, LOW); // Turn off the LED
}
}