#include "DHTesp.h"
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 2
const int DHT_PIN = 13;
DHTesp dhtSensor;
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
lcd.init();
lcd.backlight();
// Print something
lcd.setCursor(0, 0);
lcd.print("Tempt:");
lcd.setCursor(0, 1);
lcd.print("Hum:");
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: " + String(data.temperature, 2) + "C ");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
lcd.setCursor(5, 0);
lcd.print(String(data.temperature, 2) + "C ");
lcd.setCursor(4, 1);
lcd.print(String(data.humidity, 1) + "% ");
delay(2000); // Wait for a new reading from the sensor (DHT22 has ~0.5Hz sample rate)
}