A leak at home got me looking at water level sensors, but Arlo’s recent annoucement EOL’ing camera support pushed me over the edge into DIY IoT devices.
Luckily, in a really simple form, a water leak sensor simply uses water to close the circuit; so a closed circuit indicates water (or some other conductor!) was detected between the leads. Note that this set up cannot be used to detect leak of distilled water, because, well, distilled water cannot conduct electricity.
A brief search for a low-cost MCU with ADC and WiFi support turned up the ESP8266 family which costs ~$3 as of this writing. Awesome!
Specifically, I picked up the ‘ESP8266 ESP-12 D1 Mini NodeMCU Lua WeMos D1 Mini WIFI 4M Bytes Module’. I powered the MCU via a micro-USB. Solder 24-gauge wires to the 3.3V and the ADC pins on the chip, and let the open leads on the other ends of the wire lay on the floor where I’d like to detect leaks. And, done – that’s the hardware set up.
Next up, software. Programming for the ESP8266 is pretty straight forward, given the really awesome set of libraries for:
- Connecting the MCU to WiFi
- Running a basic web server on the MCU
- mDNS support so new devices can be auto-discovered
- And, of course, to read the sensor values via ADC
The next bit is to integrate with HomeKit (using Homebridge). Fortunately, again, I stumbled upon the very simple, and readable dauden/homebridge-nodeMCU repository that I tweaked a bit to include mDNS-based device discovery support. My adaptation of this Homebridge plugin is here, and also includes the NodeMCU code.
Easy peasy!
Future:
- I’m also experimenting running this set up with 2x1.5v AA batteries; the Blink wireless camera has demonstrated that even with a WiFi device onboard, the set up can be made to last ~2 years, but let’s see how efficient this particular set up is!
- One can of course 3D-print enclosures for this setup and make it appropriately water proof, perhaps? I’ll include 3D-print model files, if I get that far!