import machine
import dht
import time
# Setup LED pins
led1 = machine.Pin(17, machine.Pin.OUT)
led2 = machine.Pin(1, machine.Pin.OUT)
led3 = machine.Pin(0, machine.Pin.OUT)
# Setup DHT22 sensor
dht22 = dht.DHT22(machine.Pin(4))
# Main loop
while True:
# Read temperature and humidity from sensor
dht22.measure()
temperature = dht22.temperature()
# Check temperature and turn on corresponding LED and message
if temperature <= 16:
led1.value(1)
print("Udara dingin")
elif temperature > 16 and temperature < 30:
led1.value(0)
led2.value(1)
print("Udara hangat")
elif temperature >= 30 and temperature < 50:
led1.value(0)
led2.value(0)
led3.value(1)
print("Udara panas")
else:
led1.value(0)
led2.value(0)
led3.value(0)
# Wait for 1 second
time.sleep(1)