#define BLYNK_TEMPLATE_ID "TMPL3BH0c0g5z"
#define BLYNK_TEMPLATE_NAME "Relay"
#define BLYNK_AUTH_TOKEN "TnidsQCmQGjAwzh2qAydcW_pEfWurGEe"
import dht
from machine import Pin
from time import sleep
sensor = dht.DHT22(Pin(28))
red = Pin(5, Pin.OUT)
green = Pin(7, Pin.OUT)
blue = Pin(8, Pin.OUT)
while True:
try:
sensor.measure()
temp = sensor.temperature() # corrected here
print("Temperature:", temp, "°C")
# Turn off all LEDs first
red.off()
green.off()
blue.off()
# Decide LED based on temperature
if temp < 25:
red.on()
print("Cool")
elif temp >= 25 and temp < 50:
green.on()
print("Hot")
else: # temp >= 50
blue.on()
print("Very Hot")
except OSError as e:
print("Sensor read error:", e)
sleep(2)
Loading
pi-pico-w
pi-pico-w