Build a Raspberry Pi Water Sensor

The following is a water or moisture sensor for the Raspberry Pi that could be used for such projects as detecting leaks, rain, if a tank is full or determining if plants need watering.
The sensor works by detecting if two probes have been shorted out by water. Both probes must be immersed for the sensor to activate as here where two wires are shown in a bowl of water. Only a tiny current flows between the two probes, about 2.7μA, but the Pi can detect this.

The circuit is as follows and comprises three resistors:
Important: Make sure there is no possibility for the Pi to be splashed by liquids otherwise you may destroy it.
The circuit can be connected to any of the GPIO inputs on the Raspberry Pi GPIO header and will send the input high if water is detected between the probes. It works from 3.3V which can also be drawn from the GPIO header.
- The 3.3V power can be taken from GPIO header pin 1.
- GND is available on pin 6.
- Any of the GPIO inputs can be used e.g. GPIO 12 which is on pin 32.
Important: Ensure you use 3.3V power only. The Pi also has 5V power on the GPIO header quite nearby but using this pin by mistake may destroy the Pi as the GPIO inputs can only accept 3.3V. Check carefully which pin you have connected to.
The pin positions are shown below in relation to the Raspberry Pi board:
The following Python program can be used to read the state of GPIO 12:
#!/usr/bin/env python3 import RPi.GPIO as GPIO import time WATER_SENSE_GPIO_PIN = 12 GPIO.setmode(GPIO.BCM) GPIO.setup(WATER_SENSE_GPIO_PIN, GPIO.IN) try: while True: value = GPIO.input(WATER_SENSE_GPIO_PIN) if value: print("Water detected") else: print("No water detected") time.sleep(0.25) except KeyboardInterrupt: GPIO.cleanup()
When the script is run it prints if water is detected:
pi@sensorpi:~ $ ./water_sensor.py
No water detected
No water detected
No water detected
Water detected
Water detected
Water detected
Here's one I made earlier. This example has four copies of the circuit soldered onto a veroboard supplying four independent water sensors. Each of the sensors is connected to a different GPIO input. In this case GPIO inputs 12, 16, 20 and 21 are used for the four inputs. Potentially, 26 sensors can be attached to one Raspberry Pi.
One pair of probes per sensor are connected with screw terminals. One of the sensors is shown attached to probes.
