Skip to content
Home » A DIY Raspberry Pi minigarden you can water from anywhere in the world

A DIY Raspberry Pi minigarden you can water from anywhere in the world

  • by
  • 5 min read
rpi irrigation

After reading Steve Lohr’s book ‘Data-Ism‘, it became clear how big data – the recent evolution in computing, cheap computing power, cheap storage, cheap hardware – can make the jump to the tangible world. In his book, Lohr gives the example of a Californian winery that uses shitloads of sensors to track everything that happens in its vineyards. It enables ‘precision agriculture’ and the possibility of AB-testing two methods of managing crops. I wanted to do that on a microscale. I’ve been using a lot of datasets on this blog, but I decided it was time to create my own datasets: let’s AB-test growing spices!

A couple of weeks later…

After some initial sketches and hardware research it became clear I’d need a bigger budget, more time and perhaps a larger surface. So I decided to simply grow spices, with irrigation powered by a Raspberry Pi.

raspberry pi garden irrigation for spices

The hardware

The plant box is made out of:

  • Some water-resistant OSB wood
  • An 8mm copper pipe
  • 10 mm tubes
  • Silicone for the seams in the wood
  • A water reservoir (a bottle can do)
  • A knob

I had the wood cut in the correct size and I screwed everything together. There’s not a lot to it and I encourage you to be creative and design something more stylish than my creation.

The electronics used for this project:

  • I got the Raspberry Pi 3B with power adapter as a Christmas gift. But any type will do. Not a Zero.
  • Some jumper wires
  • A 5v – 12v relay
  • A water pump
  • A power adapter with this
  • A current distributor, perhaps with a fancy cable

What you also need: a web server that hosts PHP and MySQL. Currently, all calls by all devices are saved to the database, so you’re going to need some storage capacity. In the near future I will create a feature to turn this off.

raspberry pi garden irrigation for spices 2

I know nothing about electronics, so without my colleague Geert, I’d have lost a lot of time, accomplishing nothing or frying my Raspberry Pi. He gave me the relay and provided me with this electronics schematic. Check out his website.

The software

If I wanted to control the water pump using my mobile phone or my computer there were several ways to go forward. I considered and tried using IBM’s IoT ecosystem and NodeRed, but I wanted more flexibility and I wanted to do some actual coding, not just dragging and dropping nodes. I also considered running a web server on my Raspberry Pi, but I did not really want to go through that process. So I decided to do the following.

The Raspberry Pi sends a signal every ten seconds to my web server asking if it should water the plants. The web server does a lookup in the database if water has been requested by the user. It returns a JSON string with the appropriate information for the Rpi to water the plants. On that same moment, sensory data can be written away into the database. I have provided parameters for temperature and moisture, but I am not using it myself yet – it’s on the feature list. Water is requested through a very simple user interface that adds 5 seconds of water for every tap on the one and only button in the interface.

Technologies used are:

  • HTML and CSS for a responsive user interface
  • JavaScript/JQuery for communication between client and server
  • PHP and MySQL for handling the requests of buth the user and the Raspberry Pi
  • Python for programming the Raspberry Pi

You can find the GitHub repository here. What you should do to get it up and running:

  1. Upload everything in the ‘web’ folder to your web server
  2. Run the sql query from createtable.sql
  3. Modify sqllogin.php to match your MySQL credentials
  4. Modify setting.php and add a “secret word”
  5. Add to your Rpi and make it boot automatically.
  6. Modify and use the same “secret word”, also change the url to your file server
  7. Reboot the Raspberry Pi

Browse to the directory in your file server and add the url parameters “?token=the_secret_word_you_chose”. You are now ready to have your plants watered from anywhere in the world.

Enjoy lazy gardening!

Here’s a list of features you can expect to be added in the near future:

  • Token saved to a cookie, so you don’t need to provide it every time (done! 23/05/2017)
  • An admin panel
    • to change the token
    • to add multiple Raspberry Pi’s
    • to turn storage of data off
  • Sensory data: moisture & temperature
  • Push notifications

raspberry pi irrigation finished