Saw this post on reddit and wanted to do it myself. But since my garding skills and reliability when it comes to plants are about zero, I wanted to automate that process.
- Raspberry Pi 3
- Camera
- Waterpump and tubes
- 5V Relais
- SD card, dirt, seeds, case...
I installed Ubuntu Server on the Raspberry Pi to be able to run my node scripts - could have done this using a microcontroller but I am more familiar with linux and higher level programming languages so I used the Raspberry Pi which was laying around for years. Afterwards I installed the latest node version and was ready for scripting.
A CRON job in the script activates the waterpump twice a day at 8am and 7pm for a few seconds, which is enough for watering my garden. The interval and timespan of pumping has to be calibrated depending on the pump, type of seeds and size of the garden.
The script can be found here.
The Raspberry Pi itself is capable of doing a timelapse using the raspistill
command. But since I also wanted to store the images in a database, I automated this process of taking pictures using a node script. By default the script takes an image every 30 minutes, uploads it onto imgur and moves it afterwards to the timelapse folder. You can adjust the intervals by editing the cron-job definition.
The script can be found here.
The setup is divided into several hardware and software specific steps...
- Setup a Raspberry Pi (preferably with Ubuntu)
- Install node.js and npm (can be done using nvm)
- Connect and enable the camera using this guide
- Clone this repository onto your Pi and install dependencies in the scripts folder
cd scripts && npm install
- You will have to register an application here
- Open the following Link with your apps credentials in browser and grant access:
https://api.imgur.com/oauth2/authorize?client_id=XXX&client_secret=XXX&response_type=token
- After getting redirected, extract your
access_token
andrefresh_token
from the browser url - Create a new album, open it and extract its ID from the browser url
- do not set it publicly visible
- Create a .env file in the root directory using
cp .env.template .env
and add your informations
To be able to control the waterpump using the Raspberry Pi you have to wire it correctly using the 5V relais, which was a bit tricky for me as a noobie to electronics at first but managed to get it running with a bit of help of a friend. The following text and image should help you get going...
- Connect
Pin 2 (5V Power)
to one of therelais DC
pins - Connect
Pin 6 (GND)
to the other one of therelais DC
pins - Connect
Pin 11 (GPIO 17)
to the thirdrelais IN
pin- used to control the relais via scripts
- Connect
Pin 4 (5V Power)
torelais COM
pin- now on the otherside of the relais
- Connect
Pin 9 (GND)
to one of the wires of the waterpump - Connect the other waterpump wire with the
relais NC
pin
By de-/activating the GPIO 17
pin on the Raspberry Pi you are now able to switch the relais and with it the waterpump on and off.
I wanted to provide a website where I can take a look at my plants whenever I want.
First I wanted the project to be selfcontained and not depend on external services, but that would have meant to run the website on the Raspberry Pi in my local network, do a port forwarding and dynamically update my external IP via dyndns... so to make it a bit easier I used the imgur API to upload, and host all the images. With this setup I am able to run the website publicly on the internet via Github Pages and access the timelapse images using the imgur API.
The website also uses the enviroment variables defined in the .env file to access the images hosted on imgur. You can run the npm run dev
command inside the www folder
for an development server, which can be accessed via localhost:8080
. More informations on how to use or run the website can be found here.
The website and the current state of my garden can be found here.