I have to admit to being rather lazy when it comes to gardening so watering the hanging baskets/tubs a couple of times a day in the summer doesn't seem to be good use of my time. Also, after coming back from holiday, the said items look either dead or certainly on their way out if it has been hot whilst being away (not sure how we always manage to book a holiday abroad the only week it is hot and sunny in the UK?).
My first attempt at automatically watering the garden was to use a relatively inexpensive timer unit which you can set to switch on several times a day and for a defined period.
Unfortunately, this unit didn't last long! As well as being battery driven, these units use a motor with a set of gears to control a rotating valve. I found the valve would regularly get stuck or leak and there was always uncertainty about whether or not it was working OK.
So my requirements for a DIY irrigation controller were:
- Not too expensive
- Would be reliable
- Could connect between the outside tap and the irrigation system (garden hose connections)
- Could be operated remotely
- Would be powered from a low voltage supply from the mains (keep the mains voltages away from the water)
- Would automatically shut off in the case of a mains/power failure.
- Would always shut off after a set time as a precaution (to overcome the times when I've turned it on manually but forgotten to turn it off again!)
- Optionally to control turn-on/off based on weather forecasts (MQTT and Home Assistant control). This was so that it didn't have to water the garden if it was already raining!
WARNING!!!!! Any mains power supply used should either remain inside the property in protected conditions or kept in a waterproof enclosure. If in any doubt, consult a qualified electrician. Also, the electronics should be similarly protected using a waterproof enclosure and kept some distance from the water supply.
Note: Should you decide to build one of these, you should check the Wifi signal strength at the location you will be installing the Arduino controller (presumably outside) as it will require a good signal to work correctly. One way to check this would be to use a mobile phone with an app for Wifi signal strength monitoring.
The simplest way to achieve these requirements was to use a normally closed 12v solenoid controlled from a WEMOS Arduino. The solenoid comes with a cover but I wrapped insulating tape to give some improved rain/weather protection. My intention is to 3D print an extra enclosure around the solenoid for even better protection. Also ensure the wires to the solenoid have a 'droop' so that rain water doesn't run down the cable and into the solenoid.
The WEMOS Arduino can be programmed to support Amazon Alexa Integration using the excellent FauxmoESP library by Xose Perez (my thanks to Xose for all his support and hard work over the years on this library). This allows voice commands to turn it on/off as well as scheduled turn on/off timing. It also means it could be controlled anywhere in the world via the Amazon Alexa app on a mobile phone.
If you haven't used the FauxmoESP library before, I suggest you try some simple examples first e.g. get Alexa to turn on/off the builtin LED on the WEMOS to ensure it works OK with your Alexa setup before embarking on this project.
Unfortunately, I couldn't see a way of making the Alexa side of things conditional based on the weather so I added MQTT support which would allow additional control from Home Assistant.
The first implementation with the MQTT/Home Assistant control worked fine until (wouldn't you just know it?) we were away on holiday once and came home to find the watering system had failed!! I discovered the Raspberry Pi MQTT/Home Assistant server had failed (flash memory card had died) and the WEMOS was stuck in an infinite loop just trying to connect to the Pi so failed to turn on the watering system at all.
So, I removed the MQTT side of things to get back up and running again therefore the code shown here does not include the MQTT side of things but this could be easily restored if needed however consideration should be given to what to do if the Arduino can't connect with the MQTT server for any reason.
The code also supports over the air updates. This makes changing the code a simple task and without having to disconnect from water pipes etc.
The code has a timed override so that the valve cannot be left on inadvertently for excessive periods of time.
A 12v supply was an obvious choice in order to be able to drive the solenoid. Any 12v supply is OK but make sure the PSU current capability is sufficient to easily supply the combined solenoid and WEMOS current).
The WEMOS D1 accepts a 5v input supply but the I/O pins are 3v3. There are various regulators which could be used to drop the 12v to 5v for the WEMOS D1 but I used an LM2596 adjustable DC-DC module as I had one spare at the time (ensure it is adjusted to 5v output before connecting to the WEMOS D1!!!). This could be replaced with a simpler 5v regulator if required.
The next problem is how to drive the solenoid on/off from the WEMOS D1 (3v3 I/O). Again, this can be done in several ways but to make life easier for me, I used a TB6612FMG motor drive module. This module is probably a bit of over-kill but is relatively cheap and meant no additional veroboard etc. was required to support the additional components. The TB6612FMG also contains the necessary protection diodes for when the solenoid switches off. By configuring the processor I/O pins in a certain way in software, the TB6612FMG board can be supported above the WEMOS board by soldering 4 of the pins to the WEMOS board using header pins. Although the TB6612FMG can drive 2 DC motors, only one driver is used and no PWM is used - it is simply turned on or off. The motor.h file is adapted from the standard motor library to provide some specific functionality (e.g. recording what time the valve was opened, maintaining valve status etc.)
The credentials.h file holds the WIFI settings (SSID and password) and any MQTT settings, along with some key defines e.g. the key phrase Alexa will respond to (ALEXA_TAG). The default is "watering system" so the command "Alexa turn watering system on" should then water the garden! The MAXONTIME_MINS defines how long the valve will remain open if not turned off beforehand.
Pay close attention to the wiring of the solenoid to ensure the correct polarity. Be aware too that it is possible for the TB6612FMG to reverse the drive polarity so wiring and software configuration are important.
Also make sure the solenoid is connected to the watering system the correct way round (usually indicated by an arrow on the solenoid).
As you can see in the photos, the tap is connected by a short hose to the top of the solenoid valve. The bottom of the valve is connected to a Y connector so that 2 hoses can be connected (one for the front garden and one for the back garden). These hoses then connect to various irrigation pipework and then via drippers to the hanging baskets/tubs etc.
Control is then either via an Alexa voice command or through the Alexa app. Within the Alexa app, the watering system can be turned on/off from anywhere in the world or using the Alexa sheduling, at specific times of the day for defined periods.
Including the MQTT code in the software would enable even better scheduling and control via Home Assistant based on weather forecasts, rain history, moisture sensors etc.
Comments
Please log in or sign up to comment.