from machine import Pin, ADC
import dht
import time
sensor = dht.DHT22(Pin(5))
pir = Pin(13, Pin.IN)
led = Pin(11, Pin.OUT)
ldr = ADC(Pin(28))
while True:
sensor.measure()
temp = sensor.temperature()
luz = ldr.read_u16() # 👈 corregido
if temp > 25 and pir.value() == 1:
print("ALERTA: Temperatura a mas de 25ºC y movimiento detectado")
for _ in range(5):
led.on()
time.sleep(0.5)
led.off()
time.sleep(0.5)
elif temp > 25:
print("La temperatura supera los 25°C")
elif pir.value() == 1:
print("Se ha detectado movimiento")
else:
led.off()
if luz < 30000:
print("Hay luz")
else:
print("No hay luz")
time.sleep(1)