The Idea...
The idea was hatched in a moment of frustration. Once again I was leaving the house for work on a rainy morning only to notice that the sprinklers in the front flower bed were doing their best to drown the plants while mother-nature provided an assist. How many times had I visualized those sprayer heads spitting quarters rather than drops of water as the stupid timer turned the system on even when the flowers didn't need it at all? There had to be a better way.
Searching the tubes I found a number of projects, mostly based on Arduino, that would provide some smarts to my watering system. But I wasn't really happy with a lot of them. Sure, they worked but setup was clunky, features were limited due to the low power available on the Arduino platform, and there wasn't any feedback of when it ran or for how long. I knew I could come up with something better.
Enter the Raspberry Pi running Windows 10 Core. With this platform I had the convergence of processing power, Internet connectivity, and familiar software stack that I needed to make this project a success. So with some prompting from Microsoft and Hackster.io, I took up the challenge.
The Design
The goal of the project is to create an intelligent sprinkler controller that will maximize the water usage of the system to provide sufficient irrigation while minimizing waste. I think this couldn't come at a better time as many regions around the world struggle with drought conditions and limited water supplies. When completed, the "Raspberry Sprinkle" irrigation controller will provide the following:
- Control for one or more irrigation zones.
- Control for an irrigation pump when the system requires it.
- Soil temp and moisture sensing to ensure plants are watered when there is demand.
- Ambient temp and humidity sensing to ensure the system doesn't run when environmental conditions are not appropriate. (Too cold, too humid, etc)
- Aggregated rainfall total and precipitation forecast lookup from one or more weather providers such as the National Weather Service (in the USA) or Weather Underground.
- Flow meter input to total the amount of water used in each irrigation cycle.
- Local manual override for system setup and maintenance.
- OLED display with menu buttons to setup and configure the system.
Building the project
The time frame for the initial build of this project was short so some of the more aggressive features were scaled back in the interest of meeting the deadline. For now, the controller works with a single irrigation zone and all wiring is done on a breadboard. LED's are used to simulate the outputs for the pump relay and the zone valve. Expanding on this project I'll switch to an etched daughter-board, a weather-proof enclosure, and control/sensing for 6 irrigation zones.
The first challenge was dividing up the I/O. I needed an interface on the controller that wasn't an HDMI display since I didn't really want that hanging off the side of my house nor did I want to drag one out there every time I needed to do something. So a LCD or OLED display would work perfect with a few buttons for menu navigation. But LCD's take a lot of pins... 4 at a minimum... which was too many for this project. Adafruit to the rescue! They have some 128x32 and 128x64 OLED graphical displays which have an SPI interface. This reduced the number of GPIO pins needed from 4 to just 2. (The displays still need GPIO for a command/data line and a reset line.) I chose the 1.3" 128x64 display (https://www.adafruit.com/products/938). It connects to SPI0 and two GPIO pins.
In addition to the two GPIO lines needed for the display interface, I also needed 4 GPIO pins for button inputs. I needed 4 buttons; menu, value up, value down, and enter so the user could navigate the menus and change configuration values. I also need two outputs, one for the pump relay and one for the zone valve. I need one input for the flow meter leaving me 3 pins left on the Raspberry's header.
The moisture sensor I'm using is also available from Adafruit (https://www.adafruit.com/product/1298) and has an i2C "compatible" interface. What the manufacturer means is that it will tolerate being on an i2C bus but it won't respond to i2C commands. Rather it uses its own serial protocol. Windows 10 Core doesn't expose the i2C pins on the Pi for direct access rather hiding all of that from you behind the i2C API. So I couldn't manually manipulate the SDA and SCL pins meaning that I had to push the sensor over to two GPIO pins. I'm down to one remaining pin.
I still needed to know the ambient temperature and humidity. And while I could have gotten that from the Internet weather sources, that seems like cheating on a hardware project. So I added a Temperature and Humidity sensor from Sparkfun that they conveniently soldered to a breakout board. I chose this particular sensor because it has an I2C interface which meant I didn't have to fool around with another custom serial interface.
For this build, LEDs substitute for the Pump relay and the Zone control valve while a switch substitutes for the flow meter input. The schematic, however, shows the proper parts as does the BOM. If you are building this yourself and you need irrigation pump support, I suggest a zero-crossing Solid State relay for the pump motor rated for the appropriate horsepower. (There is one on the BOM... just observe load ratings!)
Operation
There are a couple of things the controller needs to know to run properly. For this first go of it, most everything is hard coded in the software. In the near future it will be upgraded to prompt the user the first time the application is run. It needs to know if you have a pump or not. It needs to know if you are using a flow meter and if so, how many pulses per liter the flow meter is setup for. And it needs to know your location so it can pull conditions and forecasts from the weather providers. This will all be done through the display and the four interface buttons right on the controller. No need to plug in a keyboard!
When operational, the controller is pretty much hands-off. That really is the goal of all of this. The display will show two states; the idle state and the cycle active state. In the idle state it will show you the ambient temp, soil moisture value, and the next time a watering cycle is scheduled, if one is scheduled. When a cycle is active, the display changes to show you the cycle run time and the amount of water that had been used to that point. At the end of the watering cycle, the controller will schedule another watering if appropriate.
Watering cycles are determined by several factors including soil moisture level, current and forecast temp, and the probability of rain in the forecast. If it looks like your plants don't need any water, the controller won't schedule a cycle.
Comments