import dht
import machine
import time
# Pin LED dan DHT22
led = machine.Pin(14, machine.Pin.OUT)
sensor = dht.DHT22(machine.Pin(27))
# Inisialisasi
print("DHTxx test!")
while True:
led.on()
try:
sensor.measure()
humidity = sensor.humidity()
temp_c = sensor.temperature()
temp_f = temp_c * 9/5 + 32
print("Humidity: {:.2f}% Temperature: {:.2f}°C {:.2f}°F".format(humidity, temp_c, temp_f))
except OSError as e:
print("Failed to read from DHT sensor!")
led.off()
# Mematikan LED setelah pembacaan data selesai
led.off()
# Delay 1 detik sebelum pembacaan berikutnya
time.sleep(1)