from machine import Pin
import dht
import utime
led = Pin(2, Pin.OUT)
temp = dht.DHT22(Pin(5))
def temp_measure(a):
for i in range(a):
temp.measure()
temperature = temp.temperature()
print('Temperature Sensor Value:', temperature)
utime.sleep(0.5)
print('EXIT MEASUREMENT')
return temperature
while True:
temperature_value = temp_measure(5)
utime.sleep(0.5)
if temperature_value >= 25: # Adjust the threshold as needed
print("Temperature is too high!")
led.on() # Turn on the LED
else:
print("Temperature is normal.")
led.off() # Turn off the LED