OT: Arduino Leak Sensor Question

Question to the smart people on here that are Arduino aficionados.

If one wanted to make a cheap/easy water leak sensor couldn't you just:

  1. Configure a DI pin with input_pullup
  2. Run two not connected wires in the area you want to detect water - one wired to the input pin (with pullup resistor enabled) and the other to ground.

When there is water, you would basically make a short between ground and the input pin (same thing a switch does when you wire a switch to an input pin w/pullup).

Not the best way to do it if the arduino were battery operated, but if powered I can't think of any reason this couldn't be done this way. But that's why I'm asking for comments. :slight_smile:

I'm no engineer but the biggest problem is that water has resistance and unless your water has a high mineral content it just won't be able able to overcome the resistance of water and is very unreliable if it does. You need some kind of signal amplifier to be able to detect it and that is why many water detector circuits will use the analog input to determine the presence of water.

1 Like

Yeah, that is true. I was thinking about that as well / reading up on a few discussions on that topic. Might need a more complex sensor setup in the end (which is what I was hoping to avoid).

I'm perfectly capable of doing so, and will if needed, was just trying to be lazy. Could likely do it with a simple resistive divider + analog input, for example. Would want to make it a switched power source though to avoid electrolysis.

I believe if you open most leak detectors, yes, you see electrical contacts that get shorted by water. The problem, though, is that your proposed solution would need a low-impedance driver to drive back to your contact sensor.

For that reason, I believe most leak detectors have the pair of contacts feed a high impedance op amp, which necessarily has a low impedance output to drive sensor inputs.

1 Like

You could most likely use a few transistors to amplify the signal and get something useable, with most Arduinos, you are working with 5V, if you use an ESP32 or ESP8266, you will have to work with 3.3V and this gets harder and harder.

Just do a search and get a premade circuit board that is made for use with Arduinos, you can get them for a few pennies on ALiExpress or pay a premium on Amazon if it's needed faster.

2 Likes

It will work. I had built one up before leaving X-10 for the wonderful world of Z-Wave and Zigbee. I don't recall if I used the internal pullup or an external pull up of higher resistance. Id remember from my testing that the sensing of water is robust, not a edge condition.
Mine had three contacts, two ground and one input to the ยตP. I could have left the 3rd contact not connected, or even just a plastic bump but the symmetry of the 3 contacts felt good.

For contacts I purchased some gold plated test pins from eBay. ( something like these )

Now what might be even better, but not ready yet, is firmware from PVTO.info and a TI CC2530 board from eBay. The person writing the PVTO code has not completed the low current version, but it is in the works.

BTW: Us hardware folks appreciate the few times we can be of help to the coders of this forum. You made my day :slight_smile:

1 Like

It can work, that's for sure.

But to everyone's point it depends on the mineral content (conductivity) of the water on question (which can vary greatly), the surface area of detection, and distance between probes. Wouldn't work reliably with just the end of 2 wires, really should affix the wires to metal plates (or higher surface area pins like shown above). If done as a digital input it doesn't have to be especially accurate - just measurable on/off.

Oh well. Probably better ways of doing it anyway. I'll go google some more. Trying to avoid just buying something like an "SOS Leak Sensor" to keep the cost down - and buying pre-made is no fun at all.

I understand you 100% on low cost and fun building it, but what I was refering to is a board like the one below. It's made to detect water and interface with an Arduino, They are cheap and DIY at the same time, I've got one but did not have time to play with it yet, I'm looking into getting a few sensors all in one package where my water heater, water softener and filters are located. So I'll be able to monitor leaks, water flow, salt levels, etc. all in the same package.

https://www.aliexpress.com/item/32950229732.html?spm=a2g0o.productlist.0.0.1e2922b2jlyYIt&algo_pvid=3a5f7060-c7fb-4598-acf0-f722bcc221da&algo_expid=3a5f7060-c7fb-4598-acf0-f722bcc221da-56&btsid=0b0a555b16130630883617035e3cfa&ws_ab_test=searchweb0_0,searchweb201602_,searchweb201603_

1 Like

This is the exact same sensor that I use with my HubDuino code to monitor water in my HVAC pan.

2 Likes

Yeah, I have some of those exact ones already. :slight_smile:

Those DO work. But they are kind of a pain to mount, and with the circuitry on the board itself you have to be careful about not submerging the top of it.

I may concede and do something like this one below. Not 100% sure I can submerge it, but I think I can. Note - I don't INTEND to submerge it, but it would be nice if it didn't ruin my sensor if it happened... lol

Here is one, but there are a few other sources/designs out there. They are all LM393 based, just have different options/gizmos.

Could put 1mm standoffs on it to raise it off floor of drip pan/floor and then mount the arduino/esp8266/esp32+lora/whatever I choose elsewhere / above it.

EDIT: I have a couple on order. I'll play with them when they get here.

2 Likes

Yes mineral content varies wildly, however the small amount of minerals required to make the water conductive enough to sense is trivial. And even if your tap water was = distilled water, any debris on the floor will do the trick.

That matches some of the limited testing I did. Would 'probably' be fine even with condensation off HVAC coils. While that is somewhat distilled (well, not really... But you know what I mean), it certainly isn't completely pure. Hard to empirically test that one though.

I have one in my HVAC pan. The water that condenses then runs into the pan is far from distilled. Absolutely no issue here. As I've said earlier, these are not marginal conditions.

1 Like

If you are not concern with power consumption, I am throwing out an idea perhaps using analog input to read the voltage( hence the resistance) between the pin and the ground. The code just need to poll the analog input pin. Yes, you may still need to pull it up with a resistor.

Using digital logic level has limitation. If you look at how the digital pin work below

https://learn.sparkfun.com/tutorials/logic-levels/all

The issue is when the water (for some reason the content of it or the current temperature) in such away that it put the voltage between the hysteresis of high or low level, it will be hard for the MCU to detect the water. In the sparkfun example, if the voltage end up somewhere between 2 to 2.7 V for TTL type MCU. I do not think that you will get notification.

Using analog input, you can move up and down this hysteresis (adjust the sensitivity) in your code to the level you like.

I don't think you will be able to get adjustable sensitivity with a simple contact (to the water). You might be able to get something if you have a long open element resistor (the resistive element exposed to the water). Even with that, varying mineral content will make the resistance unstable.

As soon as the water touches the electrodes the resistance drops to a fairly low number, adding more contact area will not noticeably make a difference.

Once you are able to sample the input pin with an analog value, you have much more flexibility in the software to perform detection. You can do something simple by filtering so that you get stable value. If you want to be fancy, you can look at the input as wave form which your code can do further fancy evaluation of what is going around the pin.

In this case, I probably just filter with some IIR filter. Then, I would detect some extreme up and down level rather than looking at specific level of water resistance.

There is one experience that I want to share because I come across the following issue in the past. Once you detect water with this design, please clean the pins (electrode) as soon as possible. If you leave it, the small current that passing through during wet condition may form oxidation on the pins if they are left for a long time and repeatedly. Then, it may impact future detection.

In general, we should consider to clean and dry any water sensor that detect water as soon as possible. I would not let it dry by itself for long period of time. We do not know what kind of water it is detecting. An exposure to distilled water is probably not a big deal but not a dirty water.

Since we are talking Arduino, you could probably could enable the PULLUP only when you are reading the pin. This will help with reducing the oxidation. This is a very common technique for resistive soil sensor where the oxidation is much more prevalent.

2 Likes

I think that is definitely true, and is good advice!

Also, to help that (even though it is not battery powered) I am pulsing the power through the sensor a few ms at a time. Old habit from using battery powered arduino/microcontroller devices I guess.

It is still on the bench, but I may just set it up like a battery sensor and put the arduino to sleep and wakeup periodically + on interrupt. Probably not, though, as I'm lazy/short on time and you can't cycle sensor power like that to an external sensor AND use the interrupts for wakeup (as it will never fire).

Something like this:

  digitalWrite(sensorPower, HIGH);  // Turn the sensor ON
  delay(10);                        // wait 10 milliseconds
  
  //get the readings from the sensor
  int level = analogRead(sensorPin1);
  int alarm = digitalRead(sensorPin2);

  // Turn sensor OFF
  digitalWrite(sensorPower, LOW);   // Turn the sensor OFF
1 Like

Yes, something simple like that will help a long way.