port: |
Grove: A1 (C16, C17) |
interface: | analog |
output values |
dry soil: 0 - 300 |
Further information: | http://wiki.seeedstudio.com/Grove-Moisture_Sensor |
Order: | https://www.conrad.de/de/p/seeed-studio-101020008-feuchtigkeitssensor-1369548.html |
With the class set for SEK I there is the possibility to develop a plant station. Here, for example, the moisture sensors can be used to check the moisture in a flower pot and water can be added with a pump (or a small container attached to a servo motor) as soon as it is determined that the plant in the pot is too dry.
Makecode
To work with the values of the humidity sensor, the respective value of the pin on which the sensor sends the data must be queried. In this case this is pin C16.
To get the current value shown on the LED display, the block "show number 0" from the "Basics" category can be used. To see the values of the sensor there, we need the right block from the "Pins" category.
The individual pin blocks can be found under the "Advanced" category. There the block "analog values of pin P0" must be selected and "P0" must be changed to "C16". This block is inserted instead of the "0" in the "show number" block.
Python
Die Werte des Feuchtigkeitssensors können über den Grove Pin pin_A1_RX über die Funktion analogread() ausgelesen werden und in einer Variable Feuchtigkeit gespeichert werden:
feuchtigkeit = pin_A1_RX.read_analog()
Anschließend können die Wertebereiche beispielweise auf die drei Zustände trocken, feucht, sehr freucht abgefragt werden und der Status auf dem Display des calliope mini angezeigt werden:
from calliopemini import *
while True:
feuchtigkeit = pin_A1_RX.read_analog() # Wert von 0–1023
if feuchtigkeit < 300:
display.scroll("trocken")
elif feuchtigkeit < 600:
display.scroll("feucht")
else:
display.scroll("sehr feucht")
sleep(1000)