#include <DHTesp.h>
#define LED_EXTERNAL 4 //menunjukkan port LED 1:A ada di D berapa (D4)
#define DHT_PIN 15 // menunjukkan port SDA DHT (D15)
DHTesp dhtSensor;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
//LED SETUP
pinMode(LED_EXTERNAL, OUTPUT);
//DHT22
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
}
void loop() {
// put your main code here, to run repeatedly:
TempAndHumidity data = dhtSensor.getTempAndHumidity();
//tampilkan data suhu
Serial.print("Temperatur: ");
Serial.print(data.temperature, 2);
Serial.print(" celsius");
//tampilkan data kelembapan
Serial.print(" Kelembapan: ");
Serial.print(data.humidity, 1);
Serial.print("%");
//menyalakan LED jika suhu > 30 celsius
if(data.temperature > 30)
{
Serial.println(" LED Menyala");
digitalWrite(LED_EXTERNAL, HIGH);
}
else
{
Serial.println(" LED Mati");
digitalWrite(LED_EXTERNAL, LOW);
}
delay(2000); // this speeds up the simulation
}