Software apps and online services
I've been growing some tomatoes, chili peppers and other vegetables on my balcony for a couple of years now and while in general I did reasonably well (I'm really not a gardener but I enjoy figuring out how to make things grow) the biggest issue was really when in August I went abroad for summer holidays and instructed my neighbors to take care of my plants. While they probably did their best, it wasn't really enough. One year I returned and the tomatoes were close to drying out (reducing the harvest quite a bit), the other year they were flooded. So I decided that this year I'd take care of it myself. And here's how:A homegrown irrigation system for the homegrown veggies
There are already plenty of projects on the internet for this sort of thing, nevertheless I want to share my setup as I think it turned out quite well and I hadn't seen one with a sophisticated app to control it remotely.
What makes this one different from most others, is that it can be controlled by an app, will show logs and graphs and is accessible remotely so that one can check up on it while on summer holidays. In addition to that, this was possible without coding at all. I didn't even need a command line on the Raspberry Pi a single time.
One other peculiarity of this setup is that I live on the topmost floor in a 3 floor house and have a rather large terrace. However, don't have any water supply on that terrace. So in order to get water I decided to collect it from the roof into a water batter and use a water pump to distribute it from there to the plants.Shopping parts
Let's have a closer look on the hardware parts used in this project:
Scrolling through the list of images above you'll see:
- a rain barrel to collect rain water (100 l)
- 3 plant pots
- a Raspberry Pi Zero W
- a set of small valves to adjust the water flow
- a rubber tube (10 m)
- a water pump
- a GPIO relay
- 5 analog soil moisture sensors
- an analog - digital converter (ADS1115)
- a water proof casing for the electronics
For the software I decided to go with nymea as I've already had good experiences with that for other projects I made.Let it rain!
As a first step, I placed the barrel next to the roof and using a cable canal placed at the roof it would redirect some of the rain water above the gutter into the barrel. As the rest of the setup would take me a couple of days to figure out all the things, the barrel had some time to fill up. When the first rain came along, I went outside and adjusted the system a little so that it would collect enough water to eventually accumulate the full 100 liters.
The objective is clear: In the end there should be a Raspberry Pi with a bunch of soil moisture sensors and a way to control (turn on and off) the water pump.
Connecting the sensors
As the Raspberry Pi doesn't have analog GPIO pins, I needed an analog - digital converter to connect them. I went for the ADS1115. At first I tried to use the Alchemy Power Pi-16ADC as that seemed to be made especially for the Raspberry Pi but it turned out it isn't that great. The weird thing about that one is that while it runs on 5V power supply, it can only measure a range of 0 - 2.5V (or -2.5V to 2.5V in dual channel mode) on the analog inputs. In my opinion this makes it pretty useless for the Raspberry Pi as you'll need an external voltage divider to supply the analog devices with a 2.5V signal, given the RPI only has a 3.3V and a 5V pin. In addition to that, the moisture sensors are said to work in a range of 3.3V to 12V.
So instead of building some logic to adjust all this, I decided to go for an ADC that's better suited for this use case and went for the ADS1115. That one can be used at different voltage levels between 0.5 to 6V.
This device is connected to the Raspberry Pi via I²C and reads up to 4 analog inputs.
The wiring is as follows:
I've decided to run everything on 3.3V, so all the VCC pins (green wires) are connected to the Raspberry Pis 3.3V (pin 1). All the GND pins (black wires) are connected to the Raspberry Pis GND (pin 38).
The I²C bus, consisting of SCL and SDA only needs to be connected between the Raspberry Pi and the ADS1115. SCL (yellow wire) is found on the RPi on pin 3 and SDA (orange wire) on pin 2. On the ADS115 they are on pin 3 and 4 but they're also labelled nicely there.
Connecting the relay/pump
The water pump is connected to a relay which is controlled by a GPIO output on the Raspberry Pi. I decided to connect it to GPIO10 which is on pin 19 on the Raspberry Pi. In addition to the GPIO, the relay obtains power from the 5V pin on the Raspberry Pi. Obviously GND needs to be connected too. The water pump, being an AC powered device, gets one wire connected directly to the AC, and the other passing through the output of the relay.
All in all, the complete wiring ended up looking like this:
I used a mobile phone charger from an old BlackBerry BBX phone. It says it produces an output of 1A which seems enough to drive a Raspberry Pi Zero, the relay and 4 sensors. At least I didn't experience any issues. Using a more powerful Raspberry Pi, like a 3B+ or even a model 4, may require a more powerful charger.Getting the software ready
As said before, I decided to use nymea for the software. For that, I downloaded the nymea image from nymea.io, flashed it to the SD card for the Rasperry Pi and booted it up. Using nymea:app it can be connected to WiFi by using the Bluetooth to WiFi setup as described on the nymea site:
Once the RPi is connected to the WiFi, it can be set up and controlled with nymea:app. First, let's set up the relay on the GPIO:
For that we first add a new "thing" for the GPIO 10 by using Configure Things -> + -> GPIO for Raspberry Pi -> GPIO 19 (Pin 19).
That will make a new item appear in nymea which can already be used to toggle the GPIO and with that turn on and off the water pump. However, in order to get even more out of the setup, we can create another "thing" of type Generic irrigation and connect that to the GPIO "thing" in its settings. The following video shows the setup:
Once set up, there will be two entries. One for the raw GPIO (in the uncategorized group) and one for the irrigation. Entering the irrigation view allows you to control the water flow. Either manually, or for a preset amount of time:
Moving on to the moisture sensors:
The setup is quite similar. Instead of the GPIO we'll be adding the ADS115 in nymea. Nymea will detect the ADS115 on the I²C bus automatically during the setup. When asked for parameters, the defaults will be ok. As mentioned before, the ADS1115 supports different voltages on the reading inputs. As we connected the sensors to the 3.3V power supply, we'd ideally need to have an input range from 0 to 3.3V. Sadly, 3.3V exactly isn't available, but let's just pick the closest larger one, which is 4.096V for now. After adding, the 4 input voltages will appear in the uncategorized section in nymea, right next to the GPIO.
Just like with the GPIO setup, this now already reads the sensor values from the sensors, however, it's not very nice yet as values are displayed in a range from 0 to 1, reflecting an input voltage from 0V to 4.096V. Obviously we want them to display as a moisture level in %. For that, we set up a generic moisture sensor, just like we did with the irrigation "thing" and connect that one to an input from the ADS1115. This step we'll repeat 4 times, once for each of the sensors and connect each one to a different input.
Almost done! Just one thing missing. Remember, we've connected the sensors to the 3.3V power supply but set up the ADS1115 to read input values from 0 to 4.096V. This means, that we'll never get the full range of values from the sensors but nymea currently thinks that 0V on the ADS means 0% moisture while 4.096V would reflect 100% moisture.
In addition to that, the sensors being used here are quite cheap ones and not really precise. So it easily happens that the min/max ranges aren't completely right.
We can fix those issues by calibrating the sensors in nymea:
Grab a glass of water (I've used the - by now full - water barrel) and put a sensor into there. You'll see it peak out to some value. As the sensor is in the water, that would be 100% wet, so adjust the range in the thing settings of the sensor until it matches 100%. Then remove the sensor from the water and hold it in the air. Adjust the range again until this value matches 0% moisture:
And that's it. Now we're having a nice chart of the sensor values in nymea:
Repeat the calibration for all the connected sensors.Steering the water flow
In order to distribute the water to all the plant pots, I just connected the rubber tube to the water pump and submerged the water pump in the barrel. Then I attached the tube to the wall around my balcony and directed one stream to each plant pot. There I split it up again to distribute it on two places in each pot. I turned on the pump and adjusted the valves on each end so that it would distribute the water equally. Later on, when different plants consume a different amount of water, the valves need to be adjusted more to accommodate the situation.
There is one caveat with this setup tho. Given the water level in the barrel is higher than the outlets on the valves, this would cause a water suction once the tube is filled with water and the flow wouldn't stop any more even after turning off the pump. To fix this, the last valve needs to be placed higher than the barrels upper border.
The termination valve can be closed to a level where it would not let water flow, but only drip a little bit. It is important to not fully close this valve but instead allow it to suck in air. This way, turning off the pump would start sucking in air from this terminating valve and eventually empty the tubes again and stop the water flow. Here's a simple drawing of the water and air flow:
And that's it. The setup is completed. We can now use nymea:app to turn on and off the water pump and check on the soil moisture using the app. Now it's time to fine tune the setup.
So far this all happens locally in the network but the whole point of this was to be able to control all of it remotely. In order to do so, we'll be connecting the app and the Raspberry via nymea:cloud. All that's needed is to enable the cloud connection in the box settings and then log in with the app to nymea:cloud too. When the app and the raspberry both have a cloud connection established and they meet for the first time, they will automatically be paired and from that point on, opening the app will automatically connect to the Raspberry Pi through the internet - if a local network connection is not possible. Nymea will always prefer the local network connection if it's available.
Another thing we can do now is to create smart rules to automatically turn on and off the irrigation. Just go to the "magic" section in nymea:app and set up the rules to your liking. For instance, such rules can automatically enable the water pump daily on a certain time, or when the soil moisture sensors values fall below a certain level.What's next
While this setup now certainly caters for my initial requirements, there are a few more things which I'd like to get done eventually.
Right now, if the water barrel empties, there would be no protection for the pump to run dry which might damage it as those pumps normally use the water to cool themselves down. It would be easy to add another water sensor to nymea which would prevent the pump from running. I'd probably do that with a smart rule which is activated whenever the pump is turned on and turn it off right away if the water sensor reports there is no water. Perhaps it would require to drill some holes in the barrel, put the sensor in there and close the holes again with silicone. Perhaps I'll add that next spring.
One other thing I want to do is to eventually replace the moisture sensors. The ones I used are quite bad. Especially the fact that they're resistive and don't have any sort of corrosion protection. After a couple of weeks I already noticed them degrading. I complained to the reseller (banggood) as I originally ordered some with corrosion protection and they returned me half the money. Still that leaves me with the bad sensors for now. Next spring I'll replace them with new ones for sure.Conclusion
So all in all I think it turned out quite great. Especially nymea made it really easy to set things up on the software side. I think I'll still have more fun with this project over the next years as I'll sure be using it again next spring.