I love to garden, but I live in an apartment building. Luckily, I have a balcony, but it isn’t really large enough for a traditional vegetable garden. The most compact and efficient gardening technique I know of is hydroponics. I have used hydroponic gardening before, and it is amazing. It uses less water and less space than traditional gardening, while improving plant yield. The only bad thing about hydroponics is it is difficult to tell if the system is working correctly, because everything must be opaque. IoT to the rescue! Here is how I built an automated and IoT connected urban garden to maximize my green space and minimize dead plants!
What is Hydroponics?First, here is a crash course in hydroponic gardening. Hydroponics works by exposing bare plant roots to a combination of nutrient-rich water and air. The roots need both in the right proportions or the plant will die. There are lots of unique ways to do this, but here are the three main ways I considered for this project.
1: Keep the roots immersed in nutrient-rich water and pump it out into a reservoir periodically to expose the roots to air. If the reservoir is higher than the plants, all you need to do is turn off the pump to get the water back.
2: Keep the roots in air and periodically pump water from a reservoir into the root chamber to expose them to nutrients. If the reservoir is lower than the plants, all you need to do is turn off the pump to drain the water again.
3: Pump a lot of air bubbles into a bath of nutrient-rich water and float the plants on top. This doesn’t sound like it would work, but it does (I promise).
All of these options require a mechanical pump that can and does occasionally malfunction, meaning the plants don’t get water or air that they need. Additionally, since the components of a hydroponics system are opaque (to prevent algae growth), you are often unaware of these failures until it is too late, and the plants have died.
Option 1 and 3 use more electricity than option 2, as the air pumped into water must be constant and the plants require more time in air than in water. There is also not a convenient way to electronically determine if an air pump has failed. The winner is option 2!
So, lets make a smart, IoT connected controller to minimize what we need to do manually (I can't keep a plant alive to save my life, so I built a robot that is better at it than me).
Controller ParametersI used the Arduino Opla IoT Kit in this project. Specifically, I used the soil sensor, MKR WiFi 1010, and IoT Carrier.
The general goal of this project is to make a smart controller for my lettuce drip tower, which is a variation of Option 2 from above. I would like the controller to do the following:
1) Have an adjustable watering schedule, with variables for both time between watering periods and the length of watering,
2) Check to make sure the plants actually received water from the pumps.
3) Display watering parameters, the soil moisture level, and the air temperature.
4) Water more frequently if needed on hot days.
5) Have a convenient option to manually override the watering schedule if I think the plants need it.
ProgrammingThe first step is to write some pseudo-code to get an idea of what we want to write into our actual script. Pseudo-code is like a draft of our final script, but we don't "translate" it into the Arduino language just yet.
Define my variables
Initialize the hardware
Start the timers
Loop()
Check the timers
If it is time to turn on the pumps (and they aren't already)
Turn on the pumps (Call the PumpsOn() function)
If
Turn off the pumps (Call the PumpsOff() function)
PumpsOn()
Turn on relays
Reset the watering timer
PumpsOff()
Hopefully that is fairly intuitive. First we run the setup function, then we run the loop until the processor is turned off.
You might wonder why I didn't write the loop function like this:
Loop()
Wait x minutes (interval time)
Turn on the pumps
Turn off the pumps
Check to make sure it worked
In the Arduino language, waiting (as I wrote it here) is usually accomplished by the delay()
function. That's a perfectly valid approach, but it would make it more difficult for me to accomplish goals 4 and 5 from above. The delay()
function basically pauses all activity for the time period you specify. With my proposed format, the code can continue checking sensors and doing other things while it is waiting. There are probably several ways to do what I want to here, and some of them may be better than this. Feel free to tinker and experiment for yourself.
Anyway, now we have to translate the pseudo-code into the Arduino programing language. That could be the subject of it's own tutorial, but it's pretty straightforward once the pseudo-code is written. The full code is linked at the end of this tutorial, and is heavily commented, so you should be able to see what parts of the draft above got translated into a particular section.
DashboardI set up a simple dashboard to display and control the system. The Sliders control the various intervals, and there is even a button to manually override the system if you think it needs an extra watering.
Final ThoughtsIt's currently quite cold where I live, so I haven't been able to give the system a full, long term test yet. All of my tests so far have been successful. To integrate this to the hydroponics system, the controller can be placed in a waterproof enclosure and the pumps attached to the relays. In the code I linked here I only use relay one, but it could be easily modified to have both on the same schedule (or even a different schedule, if you feel fancy!).
Rockwool is a very common substrate for hydroponics, but I got very volatile sensor readings from it, and the moisture stake split the entire cube in half when I inserted it.
I'll be using peat moss substrate for my plants, and placing the moisture sensor in that gave me very good results. I imagine coco coir would behave similarly, but I don't have any on hand to test it.
Comments