from machine import Pin
import dht
from time import sleep_ms, ticks_ms
from machine import I2C, Pin
from i2c_lcd import I2cLcd
RELAY_CTRL_PIN = 19
relay = Pin(RELAY_CTRL_PIN, Pin.OUT)
sensor = dht.DHT22(Pin(26))
AddressOfLcd = 0x27
i2c = I2C(0, sda=Pin(22), scl=Pin(21), freq=400000)
lcd = I2cLcd(i2c, AddressOfLcd, 2, 16)
print(" Connected!")
prev_weather = ""
while True:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
if (temp > 27 or hum > 30):
relay.value(1)
else:
relay.value(0)
if temp != prev_weather:
lcd.move_to(1,0)
lcd.putstr(f"temp :{temp} C")
lcd.move_to(1,1)
lcd.putstr(f"Hum :{hum} %")
else:
time.sleep(0.5)