/**
ESP32 + DHT22 Example for Wokwi
https://wokwi.com/arduino/projects/322410731508073042
*/
#include "DHTesp.h"
const int DHT_PIN = 15;
const int led = 4;
const int buzzer = 14;
DHTesp dhtSensor;
void setup() {
pinMode(led, OUTPUT);
pinMode(buzzer, OUTPUT);
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
}
void loop() {
TempAndHumidity data = dhtSensor.getTempAndHumidity();
Serial.println("suhu: " + String(data.temperature, 2) + "°C");
Serial.println("kelembapan: " + String(data.humidity, 1) + "%");
Serial.println("---");
tone(buzzer, 200);
delay(1000);
tone(buzzer, 250);
delay(200); // Wait for a new reading from the sensor (DHT22 has ~0.5Hz sample rate)
}