PiPlanter – A Plant Growth Automator

New Version The Post Below Is Out Of Date Click Here For The New Version


This post is many months in the making and I am very proud of the thing’s I’ve done here, and very thankful to all of those (specifically at www.reddit.com/r/raspberry_pi) who have helped me along my way to getting this project up and running.

This page contains every single post related to this project, please feel free to go back and look at my progression and pick up tips along the way if you want to try something like this.

Let’s get this going, here’s an overview video:

There are 8 parts to this system and, you guessed it, I’ll be going in-depth about every single one!

Sensor Network

So at it’s core, the PiPlanter is a Sensor Network & Pump System. Here’s a video explaining the sensor array:

This project uses a TMP35-37 sensor to get a pretty precise temperature reading of the room. Later down in this post you can find out the algorithm to determine the temperature in Fahrenheit. It also uses a basic LDR to get the relative ambient light level in the room. Along with those two sensors, there are 4 relative humidity sensors of my own design, here’s a picture of them as seen in this post:

9allassemb

They’re hooked up to the ADC (mentioned later) in the same way that the LDR is, with a voltage dividing resistor, and then fed directly into ADC. The principal behind this sensor is that when you insert it into soil, the water in that soil connected the two probes, causing a voltage to flow across them. So if there is more water in the soil, more electrons will flow across them, and the analog value will be higher. It’s very basic, but it works. I’ve done several long term tests, and over time, as the soil becomes dryer, the value gets lower, indicating relative dryness. Here is a picture of the four probes in the soil, with the plants.

The TMP sensor’s output is plugged directly into the ADC and the LDR is very basically connected to the ADC as well, this is essentially how how the whole thing is setup on the breadboard:

Capture

Pump System

The pump system is pretty dead simple. Essentially it is a PowerSwitch Tail II switching the mains to a 9v DC power supply. The 9v power supply is connected directly to a 12v DC submersible pump. Instead of using a motor driver chip, which requires 3 pins to do, and the chip would get hot and whatnot, I’ve decided to go with this method.

The pump is not self priming. This means it cannot make the transition from pumping air to pumping water. I wrestled with this problem for a long time, and came up with what I think is an elegant solution. I submerged the pump directly into the water, which means the pump will never fill with air, and will always pump water when activated. Here’s a video explaining the pump system:

Raspberry Pi ADC

The next system is the ADC connected to the Raspberry Pi. It is an 8 bit, 8 port analog to digital converter that can easily run on 3.3v so it’s perfect for the pi. Here is the chip, and you set it up as follows (I took this from an earlier post I wrote)

Now we need to set up the specific libraries for python the first of which being spidev, the spi tool for the raspberry pi which we can grab from git using the following commands:

You also need to (copied from http://scruss.com/blog/2013/01/19/the-quite-rubbish-clock/):

As root, edit the kernel module blacklist file:

Comment out the spi-bcm2708 line so it looks like this:

Save the file so that the module will load on future reboots. To enable the module now, enter:

To read from the ADC, add the following to your python code. The full code will be listed later:

So just use “readadc(n)” to get a value.

Python Code

I’ve made a real effort this time to comment my code well, so I’m not going to do a line by line breakdown like I often do, but I will clearly state the installs and setup things as follows. I’m assuming you have python-dev installed.

Download and install: APScheduler, this is a very straight forward install

Download and install: tweepy, you will need to go through the API setup process.

Download and install: flickrapi, you will need to go through the API setup process.

Here’s the source code for the python component of this project:

There you go! Essentially, every hour, the raspberry pi samples data from 4 humidity probes, an LDR and a tmp sensor. Once the sampling is complete, it dumps the data into a mysql database. From there the data is rendered into a graph using pChart in the form of a .png image. From there, that .png files is uploaded to flickr using this api. Once the file is uploaded, it returns it’s photo ID to the python script. From there, a tweet is built containing the brightness at the time of the tweet, the temperature at the time of the tweet, and the average moisture of the plants. It also uses the photo ID from flickr obtained earlier to build a URL leading to that image on flickr which it tweets as well. The final part of the tweet is a url that leads to this post! (taken from)

MySQL Database

The database is extremely simple, after installing MySQL set it up and create table that follows this syntax:

Pretty basic stuff, the table is just where the python script dumps the data every hour.

PChart Graph

The software driving the graphing part of the project is a bit of php graphing software called pchart. It allows me to graph mysql values from a table in a variety of ways. It is very important, and the code for the php script is as follows:

As you may be able to guess, upon the calling of this script, the program looks for a table called “piplanter_table_17” and does a bunch of stuff as commented to produce a graph. This is what a sample graph looks like:

Wed Jun 26 19:39:17 2013

This is data taken over 6 days, and it’s a lot to look at, but it’s good stuff.

Twitter & Flickr Integration

As you hopefully derived from the python code, this project uses Twitter to send data to me. Instead of using an email server or sending sms messages, I decided on twitter because of a few reasons. I use the service constantly, so I won’t ever miss a tweet. The API seemed really easy to use (and it was!) and allowed more than one person to acess the data at any one time. I decided to use flickr as my image hosting service for a lot of the same reasons, but the main one was their 1TB storage per person. You’ve already seen a sample flickr upload, so here’s a sample tweet:

That’s essentially it! Thank you for reading, and please ask questions.

32 Comments

  1. Question – how much does each sensor cost? If you had a typical garden hose, could you just use a switch instead of a pump to push the water out at specified intervals?

    I guess my ultimate question is – what would it take (in terms of cost and feasibility) to turn this into a system for a full-size greenhouse?

    -Jeremy-

    1. The sensors cost cents on the dollar, and it would be super easy to switch a garden hose. It wouldn’t cost that much at all to make this full sized, and it would very be doable. The only problem is that I don’t have a greenhouse.

      1. Very cool – I like the idea of feeding the sensor input into a central repository and managing the watering based on feedback. Nice work

  2. Great project, thanks for the writeup! I might suggest that some of the text on the pchart graph could be reduced for clarity, though… the data point labels on the green line appear to show 9-digit precision ?

  3. Very nice work. I was thinking of doing something exactly the same. I’m also growing herbs indoor in a plastic storage container 😀

    1. Let me know if you end up doing something like this, I’d very much like you see your interpretation, and especially with something very water hungry like herbs.

  4. Cool project. I have a quick question. What program did you use for creating the nice breadboard layout. I see a lot of people using it, but I have never seen what program they use.

    Thanks,

  5. How much variance did you get some sensors in the same planter? How far apart were they? I am just wondering if I put one sensor in a 2×4 planter if it’ll be sufficient.

      1. I have 4 planters at my place and I was hoping I could just do 1 in the middle of each then come up with some sort of selective pumping system to only water the planters that need it. Now you need to invent a roomba type machine that pulls out weeds and scares away cats and harvests and packages everything for you. (Let me know when you’re done)

  6. Hi Devon,
    Great job!
    I’m doing something similar with a LAMPP (wheezy, apache, mysql, python and php) stack and dallas 1 wire temp sensor. I’ve got it displaying on a webpage (therm.hopto.org).
    I tried to add pChart and was given the error message about not having GD support enabled on php?
    Was there something special you did with your php or pChart install?
    Thanks,
    Robin

  7. I’m sure we were a lot thinking about doing this. But you made it ! Congratulations !:)
    There’s a lot to do with that ! Online gardeners is the next thing !

  8. Hey im very interested in your projekt and i try to rebuilt your setting on my own is it possible that you may post the way how you wired the water and light sensor to the adc and how you built the voltage dividing resistor?

  9. Great post!
    I just wanted to ask that if its possible to do it on a larger scale? like a few acres? If yes, can you please tell?

  10. Hi,
    Can you please provide the complete list of material (including board, sensors and other stuff) for a absolute beginner. Any good place to buy everything together would be a great help.
    Thanks for this

  11. Hi,My name is Eddie , i am quite fascinating what your do this project ,Its is Freak Out for me!and i wish to get you all information about this project include the circuit and the Sensor Array ,where did you find the circuit anywhere,bcoz i cant find inside the internet?

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.