Grove Analog Resistive Plant Moisture Sensor
- Page ID
- 51679
\( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)
The grove moister sensor is an analog device.
Therefore it interfaces through an analog port. The required input voltage is 3.3 to 5 volts.
Copy and paste the following python code in the Thonny IDE and name it bootcampMoistureSensor.py.
#!/usr/bin/python3 import time from grove.grove_moisture_sensor import GroveMoistureSensor # Import the sensor library and name it GroveMoistureSensor for this script. # connect to analog pin slot A0) PIN = 0 # Set the port (pin) to use for analog input. sensor = GroveMoistureSensor(PIN) # Make a sensor object set to the analog pin input. print('Detecting moisture...') while True: # Using while true makes this an infinite loop. Use Ctrl-C to exit the loop. m = sensor.moisture # Get the current moister value and put in in the variable named ‘m’. if 0 <= m and m < 300: result = 'Dry' elif 300 <= m and m < 600: # The if else block. result = 'Moist' else: result = 'Wet' print('Moisture value: {0}, {1}'.format(m, result)) # Format and print the data. time.sleep(2) # Sleep for X seconds.
Run the script and dab a little water onto the paper towel wrapped around the sensor probes.
The output of the script should change from dry to moist with more water making it wet.
Output should be similar to the following;
Moisture value: 296, Dry Moisture value: 297, Dry Moisture value: 298, Dry Moisture value: 297, Dry Moisture value: 297, Dry Moisture value: 300, Moist Moisture value: 299, Dry Moisture value: 300, Moist Moisture value: 301, Moist Moisture value: 302, Moist Moisture value: 298, Dry Moisture value: 308, Moist Moisture value: 310, Moist Moisture value: 313, Moist Moisture value: 313, Moist Moisture value: 314, Moist Moisture value: 315, Moist Moisture value: 316, Moist Moisture value: 317, Moist Moisture value: 319, Moist Moisture value: 318, Moist
As it dries out it look like this;
Moisture value: 301, Moist Moisture value: 303, Moist Moisture value: 302, Moist Moisture value: 302, Moist Moisture value: 301, Moist Moisture value: 301, Moist Moisture value: 299, Dry Moisture value: 300, Moist Moisture value: 298, Dry Moisture value: 299, Dry Moisture value: 299, Dry Moisture value: 299, Dry Moisture value: 299, Dry Moisture value: 297, Dry Moisture value: 298, Dry Moisture value: 299, Dry