from machine import Pin
import dht
import time
sensor = dht.DHT22(Pin(4))
buzzer = Pin(14,Pin.OUT)
red = Pin(33,Pin.OUT)
green = Pin(32,Pin.OUT)
relay = Pin(25,Pin.OUT)
while True:
try:
sensor.measure()
tempC = sensor.temperature()
humi = sensor.humidity()
print("Temp in C: ", tempC)
print("Humidity in %: ", humi)
if tempC > 40:
print("Fan on")
relay.on()
red.on()
green.off()
buzzer.on()
else:
print("Fan off")
relay.off()
red.off()
green.on()
buzzer.off()
#error haddling code
except Exception as e:
print("Error : ",e)
time.sleep(2)Loading
esp32-devkit-c-v4
esp32-devkit-c-v4