[Work in progress] Automated irrigation system using Raspberry Pi

UPDATED 2015-03-27

Hi. I am currently starting to develop a new project using a Raspberry Pi!

The idea is the following:

As I have some plants in my garden and during the summer, it is a bit annoying to irrigate all of them every day, so I thought “why not to use a RPi and some electric valve to open and close water to the plants.

Now it is just an idea, but what I think is this:

– one valve for each kind of plants (one for apples, one for pears, etc….)
– different quantity of water dipending on the needs of the plant
– rain sensors (If it rains or has recently rained, do not irrigate!)
– irrigation only during the evening


I will keep this post updated as I think about new features or I go on with the project, so stay tuned!



UPDATE 2015-03-27

Hi! I’ve been working a lot on this project.

This is how it will work: there will be two parts: a daemon (or maybe two) and a web interface, which will comunicate using a MySQL database.

The daemon will work and store its data on the DB, and so the web interface.

I have defined the data structure, as well as implemented the data inside the database. I have to say that this part made me an headache! I have been finding different solutions which I could not adopt because of some problems.

The main problem which came out was the rain: obviously in such a project you cannot irrigate the plants while it is raining. But the same if it will rain in a short time.

So I had to define a well-structured database and classes to access it by the PHP. This maybe was the most annoying part, but it revealed it usefullness when, on the PHP, I wrote ” $lastRain = $db->getLastRain() ” instead on writing the SQL in the PHP. This is particularry usefull when you want to change the implementation of the data structure as well.

This is the idea I adopted to implement rain in the irrigation system, let’s start from the basics:

The system has few Modules (every module is a set of plants to be irrigated together, pratically it is a idraulic valve connected to the RPi).
Every module then has some Events…. Every event is water  opening… This means that an Event may require the water to be opened up for some time every 2 days, or every day, etc.

I implemented the events as a time interval after the previous event: for example one event may tell the system to irrigate a plant every 24 hours… This may not be the easiest solution which comes in mind, but I think it’s the best to integrate with rain because of what follows:

Every morning very early (BEFORE the first event of the day), I check the weather weather forecast for the day. If rain is expected for the day, I save the forecast inside a database and this will prevent all the events of the day from being executed.
Moreover, I check the past weather of the past day… If I was expecting rain and It didn’t rain (forecasts may be wrong…), I irrigate the plants “out of event”. Else, if I was expected rain AND IT DID RAINED, I save the “real rain” like an irrigation.

Now the daemon that’s  always running, detects when to irrigate calculating (lastIrrigation+Interval) for each Event. So, in this way, when it rains, it is considered as an irrigation and the Interval is calculated starting from the last rain. The daemon also checks for the forecasts that inibite events for the current day.

Now… If I run the weather check once a day and I forecast rain, I inibite events for the next 24 hours… But I may also run the weather check every 12 hours and inhibite events for 12 hours. The shorter the interval is, the more accurate the forecasts are! (obviously).

This is what I thought about the data structure and it is how I am implementing it at the moment.

I hope to finish the web interface in the next few days, so to start developing the daemon(s).

As I finished everything, I will document everything (better than now) and I want to share it as an Open Source project, so I will post in on my GitHub.

I think I will provide a Chef recipe to effinceltly and easily install it, and a Bash script for who doesn’t use Chef.

I would also like to provide a complete ISO to  flash on the SD card to the users, so that they can load it on the Raspberry and they are ready! (I will document about this and read if it is possible, and how much possible is it)

Stay tuned about Rpirrigate 🙂



Leave a Reply

Your email address will not be published. Required fields are marked *