Simple and reliable water level sensor circuit?

Greetings. This isn’t really a Particle related question, but hopefully it’s still OK to ask here. I’m out of the country and I need to hook up a water sensor to a Photon. It’s a fairly humid environment, but I only care about true water leaks such as a pipe breaking and flooding the place. I brought a fair amount of standard components with me such as resistors/capacitors/diodes/transistors/op-amps/level shifters etc, and I have prototyping boards as well. I’ve seen some really simple circuits with two plates and a resistor that basically just control a transistor, but I’m not sure how reliable they are or if they’re prone to false positives. I brought a couple of these soil humidity sensors as well, but it doesn’t seem like they would be ideal:
All I really need is something rock solid that won’t give me any false positives due to relative humidity, but that will still reliably tell me if there’s a leak. Ideally I’d like to just have the sensor trigger a digital input on the Photon if/when a leak is detected. Any suggestions are much appreciated. Thanks.

Something like this perhaps?

Googling for “DIY leak sensor” might offer better results than we can come up with.

1 Like

Check this example made by Karel. It is simple and to the point :).

1 Like

Thanks @davidgatti
I thought of using that sensor since I brought a few with me, but I was hesitant because my previous experience with it is that the analog value varies quite a bit with temperature, and given that it’s a humidity sensor, I wasn’t sure if I’d be able to reliably detect a leak vs getting a false positive due to high relative humidity in the air. I guess I’ll just have to experiment with it and see what values I get. The advantage of the moisture sensor vs a simple solution with two copper wires is that it’s gold plated (at least the one I have from SparkFun), so it won’t be quite as prone to corrosion.

I never played with that sensor, but I would expect that if it touches water. Te value you get will be drastically different then what you get for just from air humidity.

Check the Wiki page - you get a nice table with a list of values that you can expect based on the condition. It should give you a good idea what to do. Plus they have massive examples read o go :smile:


I built a basement flood detector using this sensor:

The sensor is wired to an analog input on the Photon and I simply set a threshold about halfway between 0 and max V. The sensor itself is very reliable. The Photon, well… not so much.

1 Like

@Muskie, what is it about the Photon that was unreliable?

@peekay123 , the problems I am having have been discussed in detail here: Long Term Photon Connection Stability

Specifically, both of the Photons I own cannot stay connected to WiFi for more than a couple of days. I only have two because I stopped buying them until I feel these issues are resolved. All of the cores I have on the same WiFi network are rock solid and never give me problems.

With the basement flood sensor, reliability is critical. I use the system threading option so that the application will continue to run even if the Photon is not connected to the cloud, but even that doesn’t work. When it disconnects, the application thread hangs, never to recover. As soon as I hit the reset button, it reconnects and runs for a day or two.

I have implemented logic to detect WiFi and/or cloud disconnect and to reset the device, but that isn’t reliable either since the application hangs.

This weekend I plan to flash 0.5.0 in the hope that this issue may have been fixed. I’m not getting my hopes up too high though.

@Muskie, 0.5.0 is working really well. It may also be worth looking at your code to see where there could be issues. :smile:

I’m not the kind of person that thinks his code is perfect, and 34 years of embedded firmware development may have made me a bit overconfident, so I’ll take another look.


@Muskie, I’ve seen unreliable Photon WiFi behavior in a few situations while connected to somewhat unreliable networks. Most recently a few days ago. Turns out I had a badly behaving access point on a Raspberry Pi with a Realtek chip running with a patched unsupported driver. Once I got rid of that and configured the Photon to connect directly to my router, the Photon seems much happier, and I haven’t had any WiFi issues since. I’m sure there are potential corner case bugs lurking in the firmware (as with most OS/firmwares)…

1 Like

And here’s the finished “product”. I just installed it in the location it’s going to monitor, which is a very humid environment. I know the sensor works with 3.3V even though the SparkFun site says to use 5V. Since I have 5V out from the buck converter which feeds the Photon, I added a transistor so that D0 on the Photon can switch 5V power on/off for the moisture sensor. According to the article on SparkFun, it saves the sensor from wearing out too quickly. I didn’t have any polyurethane handy, so I put some shrink tubing over the SMD components of the sensor to hopefully prevent them from oxidizing.

When the sensor is dry, the analog value reads somewhere between 0-10, and when I dipped about 2/3 of it in a glass of water, the value read somewhere around 2,400. So I’ve created an IFTTT recipe that triggers an email when the level goes beyond 500.

@Bluzcat - I have a few of these at home in case there is a leak

Why are you using the soil humidity sensor? I mean surely it can be used as well, but this is not its prime purpose.

This is a good tutorial with a simple code - I have been running it for some time now.

@alexsh1 I ended up using a similar sensor from SparkFun. It looks very much like the one in your picture. I started off with the humidity sensor mainly because that’s what I had at hand, and a couple of other people suggested using it. It worked fine, but at the last minute, I decided to use the other sensor. The code is only a few lines. In the loop() function, I just turn the sensor off, wait a second, then do two reads (discarding the first) and publish the variable to the cloud server. Then the sensor gets turned off, followed by a call to delay() for 2 minutes. Then it starts over again. That’s really all I need. I use IFTTT to monitor the variable.