import network
import time
from utime import sleep, sleep_ms
from machine import Pin, PWM
import dht
import ujson
PIN_TEMPERATURE_SENSOR = 15
PIN_SERVO = 16
MAX_TEMPERATURE = 30
sensor = dht.DHT22(Pin(PIN_TEMPERATURE_SENSOR))
servo = PWM(Pin(PIN_SERVO, mode=Pin.OUT))
servo.freq(50)
while True:
print("Measuring weather conditions...\n")
sensor.measure()
# If Temp >= 30, run the servo
if sensor.temperature() >= MAX_TEMPERATURE:
servo.duty(26)
sleep(0.6)
servo.duty(123)
sleep(0.6)
# If Temp < 30, stop the servo
elif sensor.temperature() < MAX_TEMPERATURE:
servo.duty(0)
sleep(0.5)
else:
print("No change")