As winter approaches and the harvest season comes to a close. Most hobbyist gardeners usually call it quits for the season.
For me, I wanted to make use of that period from late autumn to late winter/early spring to grow something I can eat, or even experiment with something I've never grown before (like ginseng or indoor potatoes) or even get a head start with growing seeds that I can transplant to my garden next spring (winter melon).
While there are grow lights with timing functions, that is not enough for me.
I want a system that is able to
- Turn run a grow light for about ten hours.
- The grow light time can be adjusted.
- Have the ability to water my plants automatically.
- My watering system should NOT water my plants whenever it is dry and should only water it every few days or so.
- My watering system should be somewhat adjustable, so instead of every few days, I can adjust it to water once a week if needed.
- Analytics is not needed.
- Security. I don't want an 'incident' where someone accidentally (or maliciously) turn my watering system 24/7 and flood my garage, kill my plants and waste my power bill or be part of a botnet. Not likely to happen, but you never know.
- Scale. In case I want to grow multiple crops indoors that require different light exposure, water level, etc. in the future, I want to manage it all on one system.
For this project, I will be using the Azure Sphere dev board along with Microsoft's Azure IoT Central to create my watering system. However, because this will be using IoT Central, there will be a subscription cost to it.
The Azure Sphere dev board will be attached to a Mikroe 3 click relay module. This relay module will be responsible for controlling the grow light and the watering pump.
The IoT Central will be the main point of interaction and is where all user settings can be adjusted such as time to turn on/off grow light.
Setting up Microsoft Azure IoT CentralImportant. This guide assumes you are somewhat familiar with pairing an Avnet Azure Sphere dev board with IoT Central. If not, please refer to the following guide:
After you have created a template, go to the settings tab and do the following:
1) Create four different Number item.
2) Enter in the display name, field Name, Unit of Measure, etc as shown in the table below
3) Create a Toggle
4) Enter in the display name, field Name, Unit of Measure, etc as shown in the table below
|Display Name| Field Name | ON Display Text | OFF Display Text | Initial Value |
The end result should look similar to the following:
You can now migrate the Azure Sphere dev board to the modified template.
Programming the Azure Sphere and Code ModificationsFor this project, the demo code provided by Avnet works great as a start point and so, I checked out the sample code at
https://github.com/bawilless/AzureSphereHacksterTTC
and made my own modifications to the deviceTwin.h, device_twin.c, main.c and the app_manifest.json files. The code I modified is shown in the code section.
In main.c, I added several time structs in order to monitor time and added additional logic behavior based on the time (such as how long the pump should be turned on, should the grow light be active, etc.). I also added an option in case I want to turn the pump on locally.
Since the dev board will be talking to IoT Central, I need to set the device twin files (device_twin.c and deviceTwin.h) by adding four twin keys in the twinArray dictionary on like 65 (pumpOnTime, timeToAutoWater, growOntime, growoffTime and clickBoardRelay2) as well as additional functions so main.c can get the status of the twin key variables.
During this process I discovered that if a twin device is set up as a boolean but NOT mapped to a GPIO pin, a segmentation fault will occur as it always try to get the GPIO value associated with the Boolean twin device. Since I'm using a toggle command (which is a boolean twin device) but not mapping it to a GPIO pin, I had to remove 178-185 in the device_twin.c file.
Furthermore, since the main.c class needs to talk with the device_twin.c variables, the header file (devicetwin.h) must also be modded so the functions can be called from main.c
For this project, the click 3 Relay is placed on click slot #1. In order to turn on the relay, GPIO pins 16 and 34 must be enabled in app_manifest.json or else you'll get an access error. Furthermore, because the system is time dependent, System Time is also set to true. Note that somewhat sensitive information is censored out
Since the Azure Sphere dev board includes an interface with Mikroe click boards, there isn't too much to do than wiring the relays. I decided to use relay #1 to control the grow light and relay #2 to control the pump.
To control the grow light, I have to splice a three prog cable. However, because the grow light needs to be placed higher than the pump, which needs to be closer to the ground near a water source, I have to splice the three prog cable with another foot of wire. I ended up splicing the neutral line of the three prog, attached a butt splice and then attaching the additional foot of 18 AWG wire, which then feeds to relay #1.
I am currently using a 5V power supply to power both the Azure Sphere board and the pump and I decided to use a small protoboard as a 5V junction point in order to have an easier time to wire the board to 5V and the pump to the relay.
While optional, I decided to keep everything in a self contained box, but to do so, I'll need to cut several holes in a wooden box using a rotary tool. Afterwards, I screwed the dev Azure Sphere, the pump, and a DC barrel jack using wood screws.
The grow light needs to be somewhat high compared to the pot. I didn't have any fishing wire or a place to mount my grow light and so I ended up using a spare walker lying around.
While I'm happy with this project, it is currently the middle of October as of this writing and as a result, I do not have anything growing other than potato sprouts. Unfortunately, at this point, this is playing the waiting game against nature. Once I have something growing, maybe I'll considering scaling the sytem up to grow multiple crops with multiple growlight and have it all be controlled from one IoT Central hub.
Comments