Hello
I connected my Soil Moisture sensor to my RaspberryPi following this tutorial.
But I have small problem with reading the analog value of humidity. When I put the sensor to the glass of water, the Digital LED on sensor turn ON, but my script still returns 0. This is the script I’m talking about:
#!/usr/bin/python
import spidev
import os
import time
delay = 5
spi = spidev.SpiDev()
spi.open(0,0)
def readChannel(channel):
val = spi.xfer2([1,(8+channel)<<4,0])
data = ((val[1]&3) << 8) + val[2]
return data
if __name__ == "__main__":
try:
while True:
val = readChannel(0)
#if (val != 0):
print(val)
time.sleep(delay)
except KeyboardInterrupt:
print "Cancel."
It read good value once. After reading the good value I changed the script to print the value even if it’s 0
What is the problem? Did I damage the sensor by putting it into glass of water?
How far did you submerge it? I have no experience with this device, but I would think that as long as you kept the water below the circuitry (i.e. the dark part at the top) it would probably be OK. If you submerged the whole thing that would probably have killed the sensor.
Try stopping the RPi, unplug it, replug it back in, then restart the RPi and try again. If it still reads 0 I’d say the sensor is dead.
I haven’t reached the dark part. What I read about this sensor one hour ago, it often reads value 0 even if the sensor is submerged in water. I think I have to check this in flower pot.
(a bit off topic)
I would suggest a capacitve soil moisture sensor
It also reports an analog value like yours but it has the big advantage that the electrodes do not corrode.