Wifi Water Leak Detector

Here is how I made a leak sensor, its now sitting under my kitchen sink

HW for leak detector with ESP8266

You donā€™t need the water sensor module. The inputs are sensitive enough without it, as long as you use a very week pull-up resistor. I found 3.9M Ohm worked best.

Thanks again man! I think Iā€™m getting close!
Nice photo editing btw :slight_smile:

I had to change the code a bit (of the testing firmware) for it to be reset itā€™s state after a few seconds for testing again (otherwise it will stay down forever until a complete on-off, even reset wonā€™t clear itā€™s state)

Problem is, itā€™s not being reset-ed. I have to phisically disconnect the gpio jumper and return it for it to be able to detect again.
I mean- it detects the leakage only once, reset button wont work, only power down or pulling out and in the gpio jumper.
Any suggestion about that?
I guess it could work that way, accept i will have to pull it out of the power plug when i want to reset it (like an event of a leakage)

Attaching it here if anyone is interested:

#include <Arduino.h>
void setup(){
    Serial.begin(115200);  
    pinMode(D5, OUTPUT);
    pinMode(D2, INPUT); 
}
void loop(){
    int sensor=digitalRead(D2);
    Serial.println(sensor);  
    if(sensor==LOW){
        digitalWrite(D5, HIGH);
        delay(5000);
        digitalWrite(D2, HIGH);
        digitalWrite(D5, LOW);
    }else{
        digitalWrite(D5, LOW);
        
    }
    delay(250);
}

I did the sketch with TinkerCad https://www.tinkercad.com/

Now moving on to esphome:

esphome:
  name: flod_sensor_1
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "*****"
  password: "*****"
  manual_ip:
    static_ip: 192.168.1.10
    gateway: 192.168.1.1
    subnet: 255.255.255.0

logger:
  level: WARN

api:

ota:

binary_sensor:

  - platform: status
    name: "Kitchen Leak Status"

  - platform: gpio
    pin:
      number: D2
      inverted: True
    name: "Sink Leak"
    id: sink_leak
    on_press:
      then:
      - switch.turn_on: flod1_status_led
    on_release:
      then:
        - switch.turn_off: flod1_status_led

sensor:
  - platform: wifi_signal
    name: "Kitchen Leak WiFi Signal"
    update_interval: 15s
    filters:
      - sliding_window_moving_average:
          window_size: 15
          send_every: 15
          send_first_at: 15
    icon: mdi:wifi

switch:
  - platform: gpio
    name: Flod sensor 1 status led
    id: flod1_status_led
    pin:
      number: D4

Thatā€™s my config for the esphome node.
It act the same as the arduino one, as expected.

Thank you so much for your help, you are awesome!!

Your indentation is bit off:

    on_press:
      then:
      - switch.turn_on: flod1_status_led
    on_release:
      then:
        - switch.turn_off: flod1_status_led

Should be:

    on_press:
      then:
        - switch.turn_on: flod1_status_led
    on_release:
      then:
        - switch.turn_off: flod1_status_led

Donā€™t think thatā€™s your issue though.

Mine definitely resets as soon as the probe is removed from the water. Try a slightly lower resistance, remove one of your 1M resistors.

Yeah I think thatā€™s not the issue but thanks for noticing :slight_smile:
I tried to remove one by one, also with no resistors, same result. so weird.
Noob alert, sorry, I donā€™t know much about electronics but just an assumption, maybe it has something to do with this capacitor being charged for the first time and then not being discharged when the short breaks?
Or maybe my probe has an internal capacitor??? :thinking:

Bought it from here:

Couldnā€™t find any information or datasheet on this probe. I assume itā€™s dumb, but who knowsā€¦

No capacitor. Thatā€™s just a cable connected to some electrodes.

Youā€™ve got it back to front.

The capacitor charges through the weak pull up resistor which is detected as a high logic level on the gpio. The water shorts out the capacitor. Which is detected as a logic low on the gpio and turns on the LED. When the water is removed the capacitor charges up again via the weak pull-up resistor which is detected as a high logic level.

If the capacitor is not charging the input could be floating. When you removed a resistor you did connect the resistor chain back up didnā€™t you? You did not leave it open circuit?

Sure I did, not that kind of noob :grin:
Iā€™ve tried to replace the capacitor for a new one - same issue.
Tried a smaller one - same issue.
So I think we are on to the issue but I have 0 clue how to resolve it :worried:

Take a close up photo of your breadboard.

tried to get as close as i can, its the same as the sketch youā€™ve fixedā€¦


BTW, Iā€™ve tried to short the two wires that connects to the probe to see what happens - it behaves exactly the same so I guess itā€™s not the probe.
Sometimes touching it again will detect low, but randomly, sometimes even touching one of the wires (which is really weird).

Your circuit looks ok. Though for a high impedance circuit like this you really should keep the wires as short as possible to prevent picking up noise. Anyway, assuming you donā€™t live next door to an AM broadcast stationā€¦

I only tested this on an ESP32, you are using an ESP8266. So we may have to adjust the resistor value to one that works.

The good news is that it is detecting water. We just need it to reset. To do that we need to incrementally reduce the resistor value from 3.9M Ohms down to some other value.

If you go too low the probe will stop detecting water.

If you are too high it wonā€™t reset.

We have a starting point of 3.9M, reduce that in half to 2M. Does it still detect water? If so reduce the resistor by half again to 1M. Does it still detect waterā€¦? Keep doing this halving of the previous resistance until it does not detect water. Do not go to 0 Ohms. Then step up by a 1/4 of the previous value. So if it worked at 1M but did not detect water at 500K Go to 750K. Find the point where it just detects water. Does it reset when you remove water from the probe tips? Try increasing the resistance a bit more, does it still reset?

Find a point where it reliably detects water and resets. That is how I did it originally and found 3.9M worked well for my ESP32 boards.

1 Like

Wellā€¦ stepped it down one at a time, way down to 100K Ohms resistorā€¦

OH BOY!

So anyone that want to do it with a D1 mini or I guess any other esp8266 based board that isnā€™t very fancy, as far as I can tell, should use a ~100K resistor

Thank you so much for your dedication to help others and give so much of your time, itā€™s very much appreciated!

** I will solder the components onto a demo pcb and will print a 3d case for it, I will post here the results :wink:

1 Like

Iā€™m really surprised there is such a difference between the ESP32 and ESP8266 I/O. Great that you got it working though :+1:

tom_I, thank you for sharing this project and being so responsive with help. Iā€™m entirely new to stuff like this, so forgive me if this post isnā€™t helpful, but is there any reason not to just stick two bare wires into a sponge for the sensor? I have two like that right now on my ESP32 that seem to be working fine. I was unable to detect water using stainless steel probes (maybe my config is wrong) so thatā€™s why Iā€™m using this method instead.

Here is my config:

esp32_touch:
  iir_filter: 10ms

binary_sensor:
  - platform: status
    name: "Kitchen Sink Sensor Status"
  - platform: gpio
    pin:
      number: GPIO27
      mode: INPUT_PULLUP
      inverted: True
    name: "Water Bowl"
    id: water_bowl
  - platform: gpio
    pin:
      number: GPIO32
      mode: INPUT_PULLUP
      inverted: True
    name: "Kitchen Sink Leak"
    id: kitchen_sink_leak
  - platform: gpio
    pin:
      number: GPIO33
      mode: INPUT_PULLUP
      inverted: True
    name: "Dishwasher Leak"
    id: dishwasher_leak

I originally wanted to detect when the dogā€™s water bowl got below a certain level using the stainless steel probes. Since that didnā€™t work I was able to instead use a reed float switch Iā€™ll include the link for if anyone else is interested. The kitchen sink and dishwasher leak sensors were just a bonus since I already had an ESP32 in the same area.
https://www.amazon.com/gp/product/B07PZBK5T9/ref=ppx_yo_dt_b_asin_title_o08_s01?ie=UTF8&psc=1

Minus the sponge thatā€™s exactly what I am doing. Using the touch sensor instead of just relying on water to short the probes should be a bit more sensitive for pure water. Using dosed town water or well water with dissolved solids should work either way.

Did you watch the values reported in the logger and set an appropriate threshold for the touch sensors?

Also for more than one touch sensor you need to remove this:

  iir_filter: 10ms

Sorry, Iā€™m not exactly sure what you mean by setting the threshold for the touch sensors or the values reported in the logger. The ESPHome logs only show whether the sensor state was ON or OFF.

Maybe Iā€™m not configuring them properly as touch sensors? Because I have three of them on the same ESP32 board that are working without removing the iir_filter: 10ms line.

And thanks for the incredibly quick reply!

1 Like

Iā€™ve played around a little and found out that the analog pin can be used too :slight_smile:
So here is what Iā€™ve ended up doing:

Thankā€™s for all the help @tom_l!

Nice write up, thankā€™s a lot for this!

Just build a leak detector based on a d1 mini and Iā€™m having trouble to detect water. Using a 100k resistor like mentioned letā€™s the probes react on metal but no luck for me with tap water :potable_water:.

Guess I now need to increase the resistor value again till I can detect water - is that right @tom_l?

Thanks so much for this. I built one and installed it in the basement, by the bulkhead door, where we have had leaks in the past. It works great!

1 Like

I had this same question about logging the threshold and found this info on ESPHome.