import dht
from machine import Pin, PWM, SoftI2C
from time import sleep
from i2c_lcd import I2cLcd
d_pin = 13
servo = PWM(Pin(15, Pin.OUT), freq=50)
buzz = PWM(Pin(2,Pin.OUT))
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=10000)
lcd = I2cLcd(i2c, 0x27, 2, 16)
a = dht.DHT22(Pin(d_pin))
while 27:
a.measure()
#print("TEMPERATURE :",a.temperature())
#print("HUMIDITY : ",a.humidity())
lcd.move_to(0,0)
lcd.putstr("Temp:")
lcd.move_to(5,0)
lcd.putstr(str(a.temperature()))
lcd.move_to(9,0)
lcd.putstr("'C")
lcd.move_to(0,1)
lcd.putstr("Humd:")
lcd.move_to(5,1)
lcd.putstr(str(a.humidity()))
lcd.move_to(9,1)
lcd.putstr("%")
#f = (a.temperature()*9/5)+32
#print("temp in f : ",f)
sleep(1)
if(a.temperature()>45 and a.humidity()>60):
servo.duty(50)
buzz.freq(1500)
sleep(1)
else:
servo.duty(125)
buzz.freq(5)
sleep(1)