-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (28 loc) · 1.03 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from machine import Pin, I2C, ADC
from utime import sleep
from dht20 import DHT20
i2c0_sda = Pin(8)
i2c0_scl = Pin(9)
i2c0 = I2C(0, sda=i2c0_sda, scl=i2c0_scl)
dht20 = DHT20(0x38, i2c0)
light_sensor_pin = Pin(0)
light_sensor = ADC(light_sensor_pin)
while True:
measurements = dht20.measurements
temperature = measurements['t']
humidity = measurements['rh']
light_level = light_sensor.read_u16()
print("Temperature: {:.2f} °C".format(temperature))
print("Humidity: {:.2f} %RH".format(humidity))
print("Light Level:", light_level)
if temperature >= 20 and temperature <= 30:
if humidity >= 40 and humidity <= 60:
if light_level >= 1000:
print("Area is suitable for planting.")
else:
print("Insufficient light for planting.")
else:
print("Humidity is not within the optimal range for planting.")
else:
print("Temperature is not within the optimal range for planting.")
sleep(1)