from machine import Pin, SoftI2C
from time import sleep
import dht
from i2c_lcd import I2cLcd
dht_pin = 27
dht_sensor = dht.DHT22(Pin(dht_pin))
led_pin = 19
led = Pin(led_pin, Pin.OUT)
LCD_SDA_PIN = 21
LCD_SCL_PIN = 22
i2c = SoftI2C(scl=Pin(LCD_SCL_PIN), sda=Pin(LCD_SDA_PIN), freq=100000 )
lcd = I2cLcd(i2c, 0x27, 2, 16)
while True:
dht_sensor.measure()
sleep(2)
temp = dht_sensor.temperature()
humidity = dht_sensor.humidity()
if temp < 20:
led.value(1)
else:
led.value(0)
lcd.clear()
lcd.putstr("Temp: {:.1f} c\n" . format(temp))
lcd.putstr("Humidity: {:.1f}%" .format(humidity))
sleep(2)