简体   繁体   中英

Read exact moisture values from soil moisture sensor using raspberry Pi

I am new to IoT and I am trying to read the soil moisture sensor readings using Raspberry Pi. I need the EXACT moisture values and NOT just the boolean values as in the water is present or not.

I have tried reading the exact values using Arduino-UNO but not sure on how to do it with Raspberry Pi in python. I have this code that I found on Intructables. https://www.instructables.com/id/Soil-Moisture-Sensor-Raspberry-Pi/

#!/usr/bin/python
import RPi.GPIO as GPIO
import time

#GPIO SETUP
channel = 21
GPIO.setmode(GPIO.BCM)
GPIO.setup(channel, GPIO.IN)

def callback(channel):
        if GPIO.input(channel):
                print "no Water Detected!"
        else:
                print "Water Detected!"

GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300)  # let us know when the pin goes HIGH or LOW
GPIO.add_event_callback(channel, callback)  # assign function to GPIO PIN, Run function on change

# infinite loop
while True:
        time.sleep(1)

This code just tells if the water is detected or not but I need the actual values of moisture.

It is based on the type of output your sensor can provide as well the configuration of the controller I/O channel. A digital sensor and IO pin can only give 0 or 1 input which is 0V or 3/5V which you are presently using. For the requirement you specified, the sensor and IO must be of analog type which gives varying 0-3/5V based on the moisture level. Go through the sensor spec and find out whether analog output it can give then program for the same. From the link you shared it seems the sensor output is digital(DO) which is not suitable for your requirement. Find a sensor from market which can give AO(analog output).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM