I’ve been trying to find a way to detect a water leak using an esp and I can’t find sensors to fit my needs.
I built an automatic irrigation system for my indoor plants. I was hoping to put a small water tray inside a larger water tray, if the water overflows to the larger one, the contact sensor flips and esp knows to stop watering. There are a few guides online but all of them speak of water sensors that I can’t manage to find anywhere online. Does anyone have any experience with this or a sensor you can point me to?
A lot of leak sensors utilize the conductivity of water to close a circuit and allow detection by a electronic device. An example is below, although it may be cheaper to buy a pre-packaged device and utilize the sensor only.
With a 3d printer and some wire, the same could be achieved without the sensor. Just two wires spaced slightly off the floor.
I made my own.
two nails, parallel, about 1.5" apart pushed through a 2" section of PVC tube, a wire soldered to the head of each. Stick this ‘probe’ into the soil to measure its moisture, or lay it where water might appear.
One wire goes to a GPIO output (to supply 3.3v for sensing).
The other wire goes to the ADC line, and to a 10K resistor to ground, to provide a voltage divider for measuring changes in the moisture in the soil.
Program the ESP to periodically:
turn on the GPIO,
wait a second,
read the ADC value,
turn off the GPIO.
I programmed it to do this because continuous voltage would cause more rapid degradation of the ‘probes’.
I use it to plot the trend of soil dehydration, so I know when the pump needs to send more water in.
It would work just as well to detect plain water in a pan, or the absence thereof.
For the binary test (water, no water) using a GPIO input instead of ADC would probably work just fine, too, but you may want the ‘probes’ closer together, and perhaps no pulldown resistor.
I built a leak sensor with this device today. The LS-2600 is not a “contact closure” switch. Rather, it provides a trickle current when wet. So, red cable goes to 3.3v and black to A0 (the ADC) on a nodemcu esp8266 (not a stand-alone 8266). Cut the sensor cables and tin the leads if you want less than 12 feet.
The relative esphome code is:
switch: # controls the LED on the nodemcu8266
- platform: gpio
name: "$devicename LED"
id: ledlight
pin:
number: D4 # GPIO2 Blue LED pin
inverted: yes
sensor:
- platform: adc
pin: A0 # Red = 3.3v Black = A0
name: "LS-2600 Sensor $devicenumber"
id: adc_sensor
update_interval: 10s # default is 60
binary_sensor:
- platform: analog_threshold
name: "Leak Sensor $devicenumber"
sensor_id: adc_sensor
threshold: 0.15
filters:
- delayed_on: 50ms
- delayed_off: 50ms
- delayed_on_off: 50ms
on_press:
- switch.turn_on: ledlight
on_release:
- switch.turn_off: ledlight
I put the nodemcu onto a small breadboard, hot-glued the sensor wires to the breadboard, and glued the board into a plastic travel soap box with holes cut for power and sensor wires.
No hubs, apps or batteries needed. Cost under $30 including 5V1A power. Assumes available WiFi.