1. System functions
Monitoring of soil moisture, ambient temperature, light intensity
Automatic watering according to current environment, cold weather automatically heats soil
2. Required Components
Tpyboard Board 1 pieces
Photosensitive Module 1 Blocks
DS18B20 Module 1 Block
Soil Moisture Detection Module 1 block
DuPont Line several
Relays 2 X
3. Wiring method
After the wiring is complete, main.py, boot.py, ds18x20.py, onewire.py are imported into the Tpyboard v102 drive letter to run. Automatic watering Experiment Code
5. Source code
from pyb import Pin, adcfrom ds18x20 import ds18x20 gl = ADC (Pin (' Y12 ')) #300亮-1700 Dark SD = ADC (PIN (' Y11 ')) #1800干-800 Wet WD = ds18x20 (Pin (' Y10 ')) KS = Pin (' Y9 ', pin.out_pp) JR = Pin (' Y8 ', PIN.OUT_PP) while true:print (' \ t light intensity: ', gl.read (), ' \ t soil humidity: ', sd.read (), ' \ t current temperature: ', wd.read_temp ()) Pyb.delay (200 ) if Gl.read () <=250: #阳光充足 if Sd.read () >800: #多浇水 ks.value (1) Else:ks.value (0) elif Gl.read () >=1300: #阳光不足 if Sd.read () >1200: #少浇水 ks.value (1) else:ks.value (0) Else: #阳光一般 if Sd.read () >1000: #正常浇水 ks.value (1) Else: Ks.value (0) if Wd.read_temp () <18: #温度过低 jr.value (1) else:jr.value (0)
TPYBOARDV102 automatic watering system of Micropython example