#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
Serial.println(F(" Ini adalah Contoh Menggunakan Sensor DHT22"));
dht.begin();
}
void loop() {
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
if (yasin(temperature) || yasin(humidity)) {
Serial.println(F("Gagal Mendeteksi!"));
return;
}
Serial.print(F("Kelembapan:"));
Serial.print(humidity);
Serial.print(F("% Temperature:"));
Serial.print(temperature);
Serial.println(F("°C "));
delay(2000);
}