My pond loses water.
Whether it's due to the fish partying too much, racoons drinking it all, or thirsty plants, this is causing our fish to worry that one day they'll need to evolve to be desert creatures. That's no way to live. Or maybe it's those darn hummingbirds sipping incessantly!
And I'm not always too observant to notice the lowering water levels before the pump starts to show up out of the muck. So it's definitely time to automate! Using the IOT2020, a sprinkler valve, and some clever sneaky wires here and there, I should be able to get this task under control. Plus if I can make it do some sort of tracking of water loss, it could maybe warn me of excessive loss so I can go put a stop to that excessive loss. (In reality it's usually leaves and moss in the river that does it).First Steps
There are really only two required pieces for this project:
- A way to monitor the water level
- A way to add water.
Adding the water can get tricky, but lucky for me the existing sprinkler system happens to run a water line right behind the waterfall of the pond. So I decided to add a sprinkler valve, with the output of the valve simply adding into the waterfall.
That in itself could be enough to keep the fish happy - add a little timer and viola! - the pond keeps itself topped up. However, that can waste a lot of water. Thus the introduction of our fancy never-been-done-before (in my backyard) special water level detection and pond topping up solution.
The IOT2020 - Industrial strength Arduino
To automatically detect and fill, I chose to use the IOT2020. It's an industrial Arduino-compatible platform which gives safe reliable control that's super easy to program.
The nicest part of this platform is that coding and prototyping can be done on a basic Arduino Uno and then transferred seamlessly to the IOT2020. It also provides extra capabilities like built-in networking in case I choose to add web connectivity to the project later.
There are 2 little but important details to keep in mind for the IOT2020. The first is that it uses a 24 volt input which, if enabled, is transferred directly to the VIN pin of the Arduino headers. That's enough to break most low-voltage circuits, so I recommend keeping the jumper set to disable/disconnect VIN.
The second detail is that the Arduino part of the IOT2020 can be set to use either 3.3 or 5 volt I/O. The parts I was using (especially the relay) requires 5 volts and it took me a moment to figure out why it wasn't working! I recommend changing the jumper to set it to 5 volts for easy relay control.
The circuit really consists of 2 separate functional components (as mentioned above)
- the sensors
- the top-up relay.
The IOT2020 uses the sensors to figure out when to add water, and it uses the relay to turn on the sprinkler valve at the right time.Sensors
The sensors are simply (very long) wires that are placed into the pond to detect when water needs to be added. I chose to use 2 sensor wires (plus at least one wire for ground) to detect low water and high water level. Using two sensors avoids frequent on/off cycles that are likely to occur with a single sensor in wavy conditions or even just when topping up. In my setup the low water sensor indicates when the water level is too low, and the high water sensor indicates when the pond is full enough. I found that having the sensors about 6" apart in my pond requires only a few minutes of top-up time while not allowing the water level to get too low. That amount of water also takes a long time (days to weeks) to leave the pond.
The theory was that placing the sensor wire and ground into water would short them out like a regular switch, but while testing I found that this was not entirely true - even with a small 1/2" gap, water (tap and pond) still has a fairly high resistance (just over 1 M-Ohm), which meant I couldn't just use the internal pullup resistors. Using external higher-value pullup resistors solved that problem, but unfortunately also means adding a bit more complexity to the circuit. (I think mine are about 4 M-Ohm).
The source code for the probe testing is available on GitHub. I used 2 stranded pairs from an old Cat-5 cable (telephone wire would work too), wrapped around a bamboo chopstick. Of the pairs, the solid colours were connected to D5 and D6, and the white/dotted wires I connected to GND. For testing this I used an Arduino Uno because everything is more accessible on it - easier for prototyping.Turning on the Water
Controlling a sprinkler valve is easy - simply connect the sprinkler's regular power source through a relay that's connected to the IOT2020. The sprinkler valve's ground stays connected as before. In my case that meant all I had to do was run a wire from the 24VAC of the sprinkler controller to the relay, and then connecting the wire of the sprinkler valve to the other side of the relay. The ground of the valve stays connected through the regular sprinkler controller, which connects it to the other side of the 24VAC adapter.
Turning on a relay with Arduino is simple - it's identical to turning on an LED. I used a small relay module for my initial testing.
Once that was working I decided to use a separate relay instead, to make it easier to fit within the IOT2020 enclosure as a shield. This required an extra transistor and resistor. Oomlout has a great tutorial on the details of controlling a relay with Arduino.Putting it all together
Now that we can sense the water level and turn on the sprinkler valve, it's time to bring it all together with some logic. The details are in the finished Arduino sketch on GitHub.
The quick explanation is that the IOT2020 turns the water on when the bottom (low water) sensor goes dry, and it turns the water off when the top (high water) sensor gets wet.
The first prototype used a small LED and button battery to emulate the sprinkler valve, and a jar of water to emulate the pond.
I also added some safety code to make sure the pond filler doesn't stay on too long. In most cases that would indicate a severe failure of some sort. The safety is a basic counter/timer that checks to see how long the pond filler is on. If it's on for longer than 15 minutes, it shuts off the valve and flashes the warning LED. I used the IOT2020's "user" LED for that purpose, but you might want to add an external red LED to make it more noticeable. After tripping the warning, the filler won't come on again until the controller is reset (human intervention required!)
For prototyping I put the circuit onto a breadboard and then copied the circuit onto some cheap protoboard I had available. I learned a few lessons in that process - one, the cheap board I had was one-sided which made the installation of the header pins rather tricky. And it was low quality which meant the copper pads pulled off the board in several spots. It all works fine enough but for the future I'll buy some 2-sided Arduino proto shields instead (I had one but planned to use it on another project).
The other lesson was in details - I soldered it up quickly late one night. Then I didn't get back to it until 2 weeks later and (after many failures and much debugging time) found out I missed a power connection and missed 2 solder joints.
I purposely left the VIN pin off my shield, because I didn't want the risk of shorting that to anything. I also did my initial testing of this shield on a cheap Arduino clone, just in case!
If you have access to custom PCB services, I recommend creating a high quality custom board instead - the Fritzing file in my GitHub project has all the details. I haven't tested it, so you might want to double check my work first!
When you're switching from using an Arduino UNO while prototyping to the IOT2020 for production, remember to change the settings.
The final step in all this is to connect everything up to the real thing:
- Add the sensor stick to the pond
- install the IOT2020 beside the sprinkler controller.
In conclusion, the system works well and the fish are happy. I found the IOT2020 is very easy to use, and you can tell by the final picture that it looks a whole lot more professional than my storage-container sprinkler solution!
The same setup can also be used to sense and add water to things like coffee makers, hot tubs, and swimming pools. The same relay that I use for the sprinkler valve could also be used to switch a low-voltage pump, for example. (Don't use it for higher voltage switching, as that is not safe for the average user/hobbyist).Thank You
P.S: This and other projects are also available on my blog: http://techblog.mulberryland.com/