from machine import Pin
import time
import machine
import dht
d = dht.DHT22(machine.Pin(23))
import ssd1306
scl = machine.Pin(22, machine.Pin.OUT, machine.Pin.PULL_UP)
sda = machine.Pin(21, machine.Pin.OUT, machine.Pin.PULL_UP)
i2c = machine.I2C(scl=scl, sda=sda, freq=400000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c)
def display_reads():
d.measure()
temp = d.temperature()
humid = d.humidity()
oled.fill(0)
oled.text('Temperature *C:',10,10)
oled.text(str(temp),90,20)
oled.text('Humidity %:',10,40)
oled.text(str(humid),90,50)
oled.show()
print('Temperature:',temp,'*C','','Humidity:',humid,'%')
INTERVAL = 2000
start = time.ticks_ms()
led1 = Pin(2, Pin.OUT)
led2 = Pin(4, Pin.OUT)
led3 = Pin(16, Pin.OUT)
while True:
display_reads()
d.measure()
temp = d.temperature()
humid = d.humidity()
time.sleep(0.5)
if temp <= 10 and humid <= 35:
led1.on()
led2.off()
led3.off()
elif temp <= 35 and humid <= 65:
led1.off()
led2.on()
led3.off()
elif temp > 35 and humid > 65:
led1.off()
led2.off()
led3.on()
else:
led1.off()
led2.off()
led3.off()