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")
Peter S
  • 251
  • 5
  • 14

1 Answers1

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/

CoderMike
  • 7,102
  • 1
  • 11
  • 16