0

I've got the classic Iduion Water Sensor (Link) and I want it to simply detect the presence of water but I get unreliable readings when using it like this:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

Power = 18
Sensor = 23
GPIO.setup(18,GPIO.OUT)
GPIO.setup(23,GPIO.IN,pull_up_down=GPIO.PUD_DOWN)

GPIO.output(Power, 1)
time.sleep(0.2)
print("Sensor Power: ON")
    i = 1
    while i <= 100:
            state = GPIO.input(Sensor)
            if state == 1:
                    print("Stop")
                    print(str(state))
                    i = 100
            i += 1
            time.sleep(0.5)
    GPIO.output(Power, 0)
    print("Sensor OFF")

The Sensor works as it should by printing 1 and stopping the program when detecting water but after some time running the code it keeps printing 0 although there's water on the sensor.

Edit: Fixed the link. Iduino is just a name that shows when googling the standard Water Sensor for Arduino an Pi.

I'm aware that 3.3 Volts from the GPIO might not be sufficient but I don't get why it works reliably from time to time. I'm powering the Pi with 5V 1A. I am aware that this is an analog sensor. I tried to get rid of the internal pull down solution and now it works quite good:

    import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

Power = 18
Sensor = 23
GPIO.setup(18,GPIO.OUT)
GPIO.setup(23,GPIO.IN) ---> Only difference compared to code above

GPIO.output(Power, 1)
time.sleep(0.2)
print("Sensor Power: ON")
    i = 1
    while i <= 100:
            state = GPIO.input(Sensor)
            if state == 1:
                    print("Stop")
                    print(str(state))
                    i = 100
            i += 1
            time.sleep(0.5)
    GPIO.output(Power, 0)
    print("Sensor OFF")
3
  • I don't think powering your sensor from a GPIO pin is a good idea - they can only provide a tiny amount of power. Should Iduino be Arduino? Your link doesn't work - is that a link to your own project that we can't see?
    – CoderMike
    Commented Jul 2, 2019 at 20:27
  • 1
    Your water sensor is an analog device. You might like to see the output voltage vs portion submerged in water. (raspberrypi.stackexchange.com/questions/99550/… ) There are two ways to read the analog voltage: (1) use an ADC, as described in my answer. (2) Use a two resistor voltage divider, and by trial and error, get the output range between 0V to 1.5V. You can then use Rpi GPIO pin to read this analog voltage, any value below approx 0.8V is read as Low, and above 0.8V is read as High.
    – tlfong01
    Commented Jul 3, 2019 at 7:01
  • why is the voltage divider needed for differencing between Low and High? I am measuring 0 Voltage when No water and up to 2.5 when fully submerged via the multimeter. I thought that is enough to use it as a water presence tester. I don't need the analog output
    – Peter S
    Commented Jul 3, 2019 at 14:41

1 Answer 1

1

That sensor looks like it has an analogue output ! You would need an ADC (analogue to digital converter) to connect that correctly to a Pi.

In this example, we will explain how to use a water sensor to detect the amount of water we have in a tank. We will use the S pin as analog input connecting Arduino, the value read will be higher depending on the sensor surface is covered with water.

http://osoyoo.com/2017/09/27/arduino-lesson-water-sensor/

1
  • as stated I only need to know i there's water and not how far the sensor is submerged. Since the Sensor return 0 V if not water is present an up to 2.5 if it's fully submerged, i thought this would be enough for my needs
    – Peter S
    Commented Jul 3, 2019 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.