from machine import Pin
import time
import dht
sensor = dht.DHT22(Pin(15))
buzzer = Pin(14, Pin.OUT)
red = Pin(16, Pin.OUT)
green = Pin(17, Pin.OUT)
blue = Pin(18, Pin.OUT)
def set_color(r, g, b):
red.value(r)
green.value(g)
blue.value(b)
while True:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
print("Temp:", temp, "°C")
print("Humidity:", hum, "%")
if temp > 30 and hum > 70:
set_color(1,0,1) # Purple
buzzer.on()
elif temp > 30:
set_color(1,0,0) # Red
buzzer.on()
elif hum > 70:
set_color(0,0,1) # Blue
buzzer.on()
else:
set_color(0,1,0) # Green
buzzer.off()
time.sleep(2)