Introduction: How to Make an Automated Greenhouse

About: Melissa Van de Velde Student MCT at Howest (Kortrijk)

Taking care of greenhouse plants can be quite a challenge. You have to constantly take the temperature into account, which should be reasonably high, but at the same time not too high. It is also important that the plants are still supplied with enough CO2 (which is sometimes not the case if the windows of the greenhouse have been closed for a while). And it's also important that the plants always receive the right amount of water. Taking all this into account is not easy, that's why I made a fully automated greenhouse.

Supplies

Look at the BOM file above for a more detailed overview of the components.

Electronic components:

  • Raspberry Pi 4 model B
  • Raspberry Pi 4 USB-C Power Supply
  • T-Cobbler Plus GPIO expansion board for Raspberry Pi (optional)
  • Micro SD Card 16GB
  • Water Pump
  • Breadboard
  • Breadboard power supply
  • Jumper wires
  • LCD Display
  • Resistors
  • DHT11 Temperature and humidity sensor
  • Soil moisture sensor
  • Heat shrink tubes
  • CCS811 Air Quality Sensor
  • Servo Motors

Construction components:

  • Plexiglass
  • Hinges
  • Transparent silicone
  • Wooden planks
  • Corner slats
  • PVC tube
  • Small transparent flexible PVC tube
  • Corner connection brackets
  • Small screws
  • Small bolts
  • Water reservoir

Tools:

  • Drilling machine
  • Jigsaw
  • Fretsaw
  • Caulking gun
  • Saw with a miter box
  • Sandpaper

Step 1: Setting Up the Raspberry Pi

First we need to install the operating system of our raspberry pi.

  1. Go to Raspberry Pi operating system images and download the version without desktop.
  2. Extract the zip file and write the image to your SD card (with BalenaEtcher, WIN32 Disk Imager...)
  3. Open the cmdline.txt file and add "ip=192.168.168.168" add the end (this ensures that we will be able to communicate with our pi via our ethernet cable).
  4. Add an empty file called 'ssh' (without any extension!) to your SD card (this will make sure that the Raspberry Pi activates SSH on startup).
  5. Safely remove the SD card from your computer and insert it in the Raspberry Pi.
  6. Plug the Raspberry Pi in and wait a couple minutes.

Step 2: Connect to the Raspberry Pi

Now we are going to connect with the Raspberry Pi

  • For Mac users: open the terminal and type in "ssh pi@192.168.168.168" and press enter.
  • For Windows users: download Putty and create a SSH connection to "192.168.168.168".

Now you can log in with default user "pi" and the password "raspberry".

Expand the filesystem

sudo raspi-config

Select "Advanced Options" > "Expand Filesystem"

Enable the I2C interface

sudo raspi-config

Select "Interfacing Options" > "I2C" > "yes"

Add your wifi

sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Go to the bottom of the file and add:

network={<br>     ssid="your-wireless-network-name"            <br>     psk="your-password"<br>}

Close and save this file.

Update the Pi

apt update
apt upgrade

Install Apache

apt install apache2 -y

Install packages Python

pip3 install flask-cors
pip3 install flask-socketio
pip3 install mysql-connector-python
pip3 install gevent
pip3 install gevent-websocket

Reboot your Raspberry Pi

sudo reboot

Step 3: Setting Up the Database

Setup MariaDB on the Raspberry Pi

Install

apt install mariadb-server mariadb-client -y

Secure

mysql_secure_installation

When asked for the root password press Enter. Now you are able to change the password. After this you will get a couple of question; type in "y" and press Enter for each one of them.

Add user

mysql -u root -pgrant all on *.* to 'your-username'@'localhost' identified by 'your-password' 
grant grant option on *.* to 'your-username'@'localhost'
flush privileges
exit

Setup MySQLWorkbench

Install MySQLWorkbench on your computer and add a new connection. You can see my settings in the screenshot above. Use the same username and password that you used on the Pi. Add the database from my Github.

Step 4: Building the Circuit

Follow the images above to build the circuit.

Step 5: Building the Case

The base

First I started with making a wooden box the size of a plastic planter box that I had with wooden planks and I connected them with corner connection brackets (as you can see on the first picture). For the walls of the base I used spare wooden planks from my garden house (those have a small groove where the plexiglass perfectly fits in).

The walls

After making the base I started with sawing the plexiglass plates for the walls. I drew the walls on the plexiglass and started sawing through it with my regular saw. One of the walls has a door with hinges, for this one I drilled 4 holes in the corners of where I wanted the opening to be and started sawing from one corner to another with a fretsaw. I drilled small holes through the plexiglass to add the hinges with small bolts.

Attention: when cutting plexiglass use a very fine saw blade and a small drill otherwise the plexiglass will crack!

Connecting the walls to the base

First I started cutting the wooden corners to connect the plexiglass walls with the base. Than I used transparent silicone to squirt into the grooves of the base and placed the plexiglass inside of them. After that I reinforced the walls with the woorden corner planks and some silicone.

The box

When the base and the walls where dry I started making the box next to the greenhouse to put all my electronics in. I connected the walls of the box with corner connection brackets and very small screws. I also made an opening for the power supply and an opening for the LCD display. The door is fixed with hinges and magnets.

The roof and windows

I saw 2 big rectangles for the roof. After that I drilled very small holes in the corners where the windows should be. Than you have to saw through the plexiglass from one hole to another with a fretsaw. I let my dad cut the windows out because I kept having cracks and my lines were extremely crooked.

To hide the crooked lines of the windows I added small wooden planks on the borders, on the inside and outside. The wooden planks on the outside are slightly smaller so the window falls into it. I drilled through the planks and the plexiglass with a small drill and added the hinges with small bolts.

For the ridge on the roof I used a bigger wooden corner plank and some silicone. To make sure that the water is spread evenly I added a PVC tube under the ridge of the roof and drilled a couple of holes in it.

Wiring

Now you have to add your electronics. I drilled the Raspberry Pi in the roof of the box next to the greenhouse and I hung the breadboard against the wall. I drilled holes through the box and the base for the wires as you can see on the picture. I connected the sensors and wires to the plexiglass walls with silicone.

When I added the servos to the windows I realised the servo arm was too small so I added a toothpick with some glue and adhesive tape but I recommend buying bigger servo arms.

Step 6: Download the Code From Github

You can download all my code (front and backend) from my Github. Feel free to adapt the code to your preferences.

Frontend

To display the website you need to do the following steps.

sudo -i
nano /etc/apache2/sites-available/000-default.conf

Go to the line with "DocumentRoot /var/www/html" and change this to "DocumentRoot /home/student/automated-greenhouse/frontend". Close and save the file (Ctrl + C > "y" > press Enter).

service apache2 restart
nano /etc/apache2/apache2.conf

Search for the following lines:

Options FollowSymLinks
AllowOverride All
Require all denied

And change this to:

Options FollowSymLinks Includes ExecCGI
AllowOverride All
Require all denied

Close and save the file (Ctrl + C > "y" > press Enter).

service apache2 restart

Backend

Add a service to your Pi so that the backend stats running when the Pi gets plugged in:

nano automatedgreenhouse.service

Add the following lines to this new file (with your own username):

[Unit]
Description=ProjectOne Project
After=network.target
[Service]
ExecStart=/usr/bin/python3 -u /home/student//Code/Backend/app.py
WorkingDirectory=/home/student//Code/Backend
StandardOutput=inherit
StandardError=inherit
Restart=always
User=your-username
[Install]
WantedBy=multi-user.target x-

sudo cp automatedgreenhouse.service /etc/systemd/system/automatedgreenhouse.service
sudo systemctl enable automatedgreenhouse.service

Step 7: Use the Automated Greenhouse

From now on the backend will start running when the Pi is plugged in. To see the website you just have to surf to the ip-address shown on the LCD display.

Now you can enjoy your own automated greenhouse :D

If you run into any problems or have a question or suggestion, feel free to leave a comment. I'll try to get back to you as fast as I can.