from machine import Pin, I2C
import ssd1306
import time
import dht
sensor = dht.DHT22(Pin(12))
relay = Pin(25, Pin.OUT)
relay.value(0)
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
plants = {
'Tomato' : {
'min_temp': 20,
'max_temp': 28,
},
'Lettuce' : {
'min_temp': 15,
'max_temp': 22,
},
'Pepper' : {
'min_temp': 22,
'max_temp': 30,
},
}
# choose the plant profile
plant_name = 'Lettuce'
# get the plant profile
plant = plants[plant_name]
# get min & max temp in the profile
min_temp = plant['min_temp']
max_temp = plant['max_temp']
while True:
sensor.measure()
temp = sensor.temperature()
humidity = sensor.humidity()
# check the temp of plant to know on or off the fan
if temp > max_temp:
relay.value(1)
fan_status = 'ON'
else:
relay.value(0)
fan_status = 'OFF'
# OLED Display
oled.fill(0)
oled.text(plant_name, 0, 0)
oled.text('Temp: ', 0, 18)
oled.text(str(temp), 65, 18)
oled.text('Hum: ', 0, 34)
oled.text(str(humidity), 65, 34)
oled.text('Fan: ', 0, 50)
oled.text(fan_status, 65, 50)
# showing the text on the OLED Display
oled.show()
time.sleep(2.2)Loading
ssd1306
ssd1306