#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, ESP32!");
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)223);
lcd.print("C");
lcd.setCursor(10, 0);
lcd.print(data.humidity,1);
lcd.print("%");
delay(2000); // Wait for a new reading from the sensor (DHT22 has ~0.5Hz sample rate)
}