#include "DHTesp.h"
#include <LiquidCrystal_I2C.h>
const int DHT_PIN = 23;
LiquidCrystal_I2C lcd(0x27, 16, 2);
DHTesp dhtSensor;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, EPS32!");
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Tes sensor DHT22");
}
void loop() {
// put your main code here, to run repeatedly:
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("Temp: "+ String(data.temperature, 2)+ "°c");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("suhu : ");
lcd.setCursor(10, 0);
lcd.print("RH : ");
lcd.setCursor(0, 1);
lcd.print(data.temperature,1);
lcd.print((char)233);
lcd.print("c");
lcd.setCursor(10, 1);
lcd.print(data.humidity,1);
lcd.print("%");
delay(2000); // wait for a new reading from the sensor (DHT22 has ~0,5Hz sample rate)
}