Welcome to our modest greenhouse automation project. This is not intended as a step-by-step tutorial but rather a general description or outline. Each greenhouse will differ and the user has to adapt parts of this project to theirs. Nonetheless we hope the reader gets something useful from our project. Cheers, and happy tinkering!
(Please excuse the rough video demonstration. We are not videographers nor editors ;) )
This project came out of necessity and was developed over time, slowly adding more and more functionality. One of our greenhouses is situated far enough away from the main building that it is outside of a wifi zone. In order to automate the greenhouse a wireless sensor network (WSN) is developed. The greenhouse acts as the Follower Node and communicates with the Leader Node (in the building, within wifi zone) via the popular NRF24L01+PA+LNA. The Follower Node gathers data, sends it to the Leader Node, which acts based on either pre-set automation rules or user input. The Leader Node sends relay commands back to the Follower Node. The Leader Node has wifi connectivity via the ESP32 Dev Board. The Blynk platform is used to act as the GUI for the user.
The Follower Node gathers temperature data as well as the status of the window (via a hall sensor). Based on this the window is either OPENED and CLOSED, as well as fans are either turned ON or OFF. Both of these are controlled by default either with pre-set automated rules (such as if temp > 30 C and window is closed, then open window), or a manual user overwrite. In the manual user overwrite the user can control the relays as they desire, using the app that was developed on Blynk.
Various other logic are added in the background such as when the user enables a manual overwrite (say for opening the windows) that a timer is started. The timer is such that after 1 hour it triggers the user-set manual overwrite to disable and the program to return to automation mode. This is done so that if a user opens a window via manual overwrite mode and then forgets to close it that the window does not remain open when the temperature drops to critically low values during night time. After 1 hr a manual overwrite is disabled and if the temperature is indeed low, the automated rules will kick in to close the window.
Finally, just for fun, all of the electronics as well as linear actuator and fans are off-grid, powered by 100W PV solar, a 60AH battery and a 1kW inverter. Although the greenhouse is wall powered, we wanted to test a small off-grid setup. The electronics don't require much power and only the fans are the largest drain on the system. (1-2 W when collecting and sending sensor data but no relays are ON, ~8W for 50 seconds when opening or closing the window, ~80W when fans are ON). If we find the fans are too demanding we can either remove one of them to cut consumption in half. or add another PV panel. Furthermore, when the fans are in automated mode, they turn on only for 10 minutes at a time and then remain off for 30 mins. This is to further reduce power consumption. We've done some back-of-the-envelope calculations and find that without heating this system is just big enough to power these electronics. Battery is large enough to supply energy for around 2-3 days if the sun is out. Luckily we live in Canada's most sunniest city!
Main OutlinePeripherals/Sensors (on Follower Node):
- Temperature
- Hall (to determine whether the window is open or closed)
- 1602 LCD connected via I2C (onboard I2C backpack)
Relays (controlled by Follower Node):
- Relay 1 to send signal to control box of linear actuator to OPEN window
- Relay 2 to send signal to control box of linear actuator to CLOSE window
- Relay 3 to turn ON/OFF fans.
- NOTE: The linear actuator that opens and closes the window comes with a control box. This control box has screw terminals on the back that allow for manual user input to open and close. It is to these inputs that Relay 1 and Relay 2 are connected.
Hardware:
- The Follower Node: In the greenhouse is an Arduino Nano connected to an NRF24L01+PA+LNA using the Proto-N2RF board. The temperature and hall sensors are connected on the prototyping section of the board. Signals are send to three of the four relays, which are on a separate module. Temperature is also displayed to a 1602 LCD for easy user reading without using the app to know what the temperature is. NOTE: The Proto-N2RF board is designed to interface with the Nano and NRF24L01+PA+LNA, has a prototyping section, and an interface to the 1602 LCD so that it can be mounted directly onto the board - all of these we are using in this project, making this the perfect choice for this project.
- The Follower Node: This node controls a 4-channel relay module, which is contained in its own IP68 enclosure. Only three of the four relays are used. The first two relays are connected to the linear actuator that opens/closes the window. This device came with its own control box. The relays to open and close are connected to this control box where the appropriate pins are exposed via screw terminals. The third relay controls an outlet on another enclosure. Basically this makes a "smart plug" which can control anything plugged into the outlet. In our case the two fans.
- The Leader Node: In the building is an ESP32 Dev Board connected to an NRF23L01+PA+LNA using the Proto-N2RF board. No sensors or relays on this board. This part is not shown here as it is straight forward. Basically just the ESP32 sitting on a prototyping board and connected to the NRF. Again, we use the Proto-N2RF for this as it easily interfaces the NRF, even though we are not using the Nano.
Code Philosophy:
Since the Follower Node is outside of the wifi zone, the Follower and the Leader Nodes have to talk to each other regularly to exchange data and command signals. One of the ways to do this (which is good because it is easy, but not good because it is hard to scale if there were more Follower Nodes added later) is as follows. The Master to send regular command signals to the Follower (once per second). These command signals are for the relays. Command signals can be produced either by the automation rules (see below) or by user input (via Blynk app). When the Follower Node receives these commands it sends back an ACK payload. Contained inside this payload are sensor data (temp and hall). When the Leader gets the ACK, it starts over and sends a new command signal.
This method is not great and has some limitations, but it works well enough in our setup. The data send to and from the Follower is not very big so using the ACK payload method to return sensor data is sufficient. Also note that by the time the Leader Node gets the sensor data, it is already one iteration behind. Since the communication frequency is 1Hz, this means the sensor data is at least 1 second old. However, things in a greenhouse move slow and this delay is not an issue. We could even decrease the communication frequency to 0.1Hz to preserve power, and it would not impact the user much.
The controls work in two modes: Automation mode and Overwrite mode. Regarding the automation rules, the main idea is as follows (written in made-up syntax for easy readability).
if ((temp >= temp_high_setpoint) && (window_status == CLOSED)) then
Turn ON relay 1 (window open relay)
This relay is on a timer and disables after the timer has expired
if ((temp <= temp_low_setpoint) && (window_status == OPEN)) then
Turn ON relay 2 (window close relay)
This relay is on a timer and disables after the timer has expired
if ((window_status == OPEN) && (temp >=temp_fan_setpoint)) then
Turn ON relay 3 (fan relay)
else
Turn OFF relay 3
Note a few key points:
- The temperature setpoints have a hysteresis gap so that the system doesn't get into an Open/Close back-to-back situation.
- While in automation mode, the user buttons are disabled on the app.
- The above automation rules can be manually overwritten by the user by enabling manual overwrite mode. This mode comes with a timer of 1 hr and afterwards disables manual overwrite mode and goes back to automation mode.
- A sanity check is added to prevent the user from simultaneously turning on both Relay 1 and Relay 2 (opening and closing window at the same time).
NOTE: We did not include a schematic of the Leader Node as this is a basic connection of the NRF24L01+PA+LNA and the ESP32 Dev Board. No sensors or otherwise devices are used (besides a smoothing cap on the Vin for the NRF).
Blynk IOT:
We've used the Blynk IOT platform for a different project and it worked out great. Therefore, we decided again to use Blynk for this greenhouse automation project. We are using the free subscription and although the features are limited, it is sufficient. Particular features we really like about Blynk are:
- Free subscription has sufficient features unlocked to make a moderately complicated app.
- Online community/forum is active and helpful.
Let's do a back-of-the envelope calculation to see if our 100W, 60Ah system is sufficient. This is not super accurate, but will give us an idea how close we are to staying within our energy budget. First some assumptions
- Number of window open/close cycles per day = 4
- Fan 10min ON/30min Off cycles per day = 8
- Lowest allowable battery SOC = 50%
- Number of days of autonomy without any sun (100% battery run) = 3 days
- Inverter power consumption based on load = 10% of load
- Number of sunny hours per day = 4
- PV efficiency including charger = 50%
- Inverter efficiency = 80%
Some of these assumptions are fairly conservative, such as PV efficiency including charger being around 50%. This is likely close enough though (we haven't measured) as the charger is not of the MPPT type. Also the inverter is not high quality, so 80% is likely accurate. Note that the inverter is rated at 1kW, which is far more than what we will require as all items combined use less than 0.1kW at any time. Next we note the energy usage of the various items in our system:
- PCB and associated electronics (NRF, sensors, LCD). Uses around 2W. It runs 24hr/day, therefore it uses 0.048 kWh.
- Linear actuator for window. Uses around 8W. Takes about 50sec to open and 50sec to close. Assuming 4 Open/Close cycles per day this comes to 0.001 kWh.
- Fans. Both combined take about 80W. Assuming 10mins ON/30mins OFF cycle, and 8 such cycles per day, this comes to 0.107 kWh.
- Inverter. We haven't measured - that's why this is a back-of-the-envelope calculation ;) - The consumption is based on the load. Let's simply assume the inverter takes 10% of whatever the load is. Therefore, sum the above kWh and take 10% of that. This equates to 0.016 kWh.
The total daily consumption is therefore 0.171 kWh. On a sidenote, we pay around CAD $0.075/kWh. If we used our main power, it would only cost around 1.2 cents/day (removing the inverter from this calculation as it wouldn't be needed if using wall power). Not too bad!
Finally, given the battery and PV assumptions above, we can see that we need a battery that has 85 Ah of capacity (at 12V) and a PV panel of 107W... so we are actually pretty close. With our 60 Ah battery we will not last 3 days and stay above 50% SOC. But we could do 2 days.
Future Upgrades/Work still to be doneThis setup is far from perfect, nor finished. It is an evolving project. Below are some changes we plan to make in the coming months:
- Custom 3D print an enclosure for the Proto-N2RF.
- Humidity sensor on the Follower Node and push this data to the Blynk app for user to read.
- Increase ACK payload array to send back more data, mostly useful for debugging. This is also required when adding more sensors.
- Expand on the automations such as heating at night and opening the main door to allow even more airflow. Although, if adding heating our off-grid solution will no longer be sufficient (too small) and we will have to go back to main power in order to supply the space heater.
In this project we are switching 120V devices (namely, the two fans), using up to 80W while running. Working with these ratings can be dangerous if not done professionally. We have the in-house experience to do this electrical work such as wiring and connection of appliances safely. Please take caution if you plan on switching appliances via relays at these ratings.In order to make switching of the appliances via relays as safe as possible we made sure to only use components/wires rated for the voltage and current ratings. Furthermore, no terminals that are at 120V are exposed. The entire relay module is placed in an IP68 enclosure, using IP68 connectors to connect the appliance (fans).
Comments