/**
ESP32 + DHT22 Example for Wokwi
https://wokwi.com/arduino/projects/322410731508073042
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHTesp.h"
const int DHT_PIN = 15;
DHTesp dhtSensor;
// LCD 설정: 주소 0x27, 16x2 디스플레이
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
// 시리얼 통신 초기화
Serial.begin(115200);
// DHT 센서 초기화
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
// LCD 초기화
lcd.init();
lcd.backlight();
}
void loop() {
// 온도와 습도 데이터를 읽기
TempAndHumidity data = dhtSensor.getTempAndHumidity();
// LCD 출력
lcd.setCursor(0, 0); // 첫 번째 줄 첫 번째 칸
lcd.print("TEMP: ");
lcd.print(data.temperature, 2); // 소수 둘째자리까지
lcd.print(" (C)");
lcd.setCursor(0, 1); // 두 번째 줄 첫 번째 칸
lcd.print("HUM : ");
lcd.print(data.humidity, 1); // 소수 첫째자리까지
lcd.print(" (%)");
// 시리얼 모니터에 출력
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
Serial.println("---");
// 2초 대기
delay(2000);
}