from machine import Pin
import utime
import dht
from esp32_gpio_lcd import GpioLcd
sensor = dht.DHT22(Pin(15))
led = Pin(2, Pin.OUT)
relay = Pin(4, Pin.OUT)
temp = 0
hum = 0
lcd = GpioLcd(
rs_pin = Pin(13),
enable_pin = Pin(12),
d4_pin = Pin(14),
d5_pin = Pin(27),
d6_pin = Pin(26),
d7_pin = Pin(25),
num_lines = 4,
num_columns = 20)
lcd.move_to(0,0)
lcd.putstr("Le Thanh Nam")
lcd.move_to(0,1)
lcd.putstr("THCN2 K60")
def display_sensor():
global temp, hum
sensor.measure() #sensor begin
temp = sensor.temperature()
hum = sensor.humidity()
lcd.move_to(0,2)
lcd.putstr("temperature: ")
lcd.move_to(13,2)
lcd.putstr(str(temp))
lcd.move_to(18,2)
lcd.putstr("*C")
lcd.move_to(0,3)
lcd.putstr("Humidity: ")
lcd.move_to(10,3)
lcd.putstr(str(hum))
lcd.move_to(15,3)
lcd.putstr("%")
while True:
display_sensor()
if temp > 30:
led.value(1)
if temp < 25:
led.value(0)
if hum > 80:
relay.value(1)
if hum < 70:
relay.value(0)