from machine import Pin
from time import sleep
import dht
sensor1 = dht.DHT22(Pin(14))
sensor2 = dht.DHT22(Pin(12))
com1 = Pin(27, Pin.OUT)
com2 = Pin(26, Pin.OUT)
com3 = Pin(25, Pin.OUT)
com4 = Pin(33, Pin.OUT)
fan1 = Pin(15, Pin.OUT)
fan2 = Pin(2, Pin.OUT)
fan3 = Pin(4, Pin.OUT)
fan4 = Pin(5, Pin.OUT)
def tempsensor():
sensor1.measure()
sensor2.measure()
temp1 = sensor1.temperature()
hum1 = sensor1.humidity()
temp_f1 = temp1 * (9/5) + 32.0
temp2 = sensor2.temperature()
hum2 = sensor2.humidity()
temp_f2 = temp2 * (9/5) + 32.0
print('Temperature: %3.1f C' %temp1)
print('Temperature: %3.1f F' %temp_f1)
print('Humidity: %3.1f %%' %hum1)
print('Temperature: %3.1f C' %temp2)
print('Temperature: %3.1f F' %temp_f2)
print('Humidity: %3.1f %%' %hum2)
def TestrelayCom():
com1.value(0)
com2.value(0)
com3.value(0)
com4.value(0)
sleep(1)
com1.value(1)
com2.value(1)
com3.value(1)
com4.value(1)
sleep(1)
def TestrelayFan():
fan1.value(0)
fan2.value(0)
fan3.value(0)
fan4.value(0)
sleep(1)
fan1.value(1)
fan2.value(1)
fan3.value(1)
fan4.value(1)
sleep(1)
#satrt program
while True:
try:
TestrelayFan()
#sleep(2)
except OSError as e:
print('Failed to read sensor.')