Site icon Roel Peters

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

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.

The hardware

The plant box is made out of:

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:

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.

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:

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 egarden.py to your Rpi and make it boot automatically.
  6. Modify egarden.py 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:

Exit mobile version