Introduction: Aruduino Gardening

The goal of this project was to build an automated Arduino gardening setup.  I set up temperature, light and soil moisture sensors.  It also has a solenoid that opens when the soil moisture drops below a certain level.  That is connected to a gravity fed subterranean irrigation system that waters the plant with minimal evaporation.  I used parts from a couple of kits from SparkFun (http://www.sparkfun.com/products/11576) and (http://www.sparkfun.com/products/10725).

I am also uploading my sensor data to thingspeak.com (https://thingspeak.com/channels/6904)

I would like to upgrade these parts and design as I go along, but here's what I used.

Parts needed:
1 x arduino uno
1 x breadboard
1 x TMP36 Temp Sensor
1 x Photocell
1 x Homemade soil moisture sensor (2 bolts, 2 nuts and a length of wire)
1 x 1/2" Gravity Feed Electric Solenoid Valve DDB-CD-12VDC (http://www.ebay.com/itm/1-2-Gravity-Feed-Electric-Solenoid-Valve-DDB-CD-12VDC-/300653378588)
1 x ConnectPort X2
1 x XBee 2mW - series 2
1 x XBee Explorer USB
1/2" irrigation tubing
An enclosure (I used a generic plastic box picked up at a local hardware store)




Step 1: The Circuit

The circuit is a compilation of others that I found online for the various sensors.  I uploaded a diagram of the setup that I created using Fritzing.

I used the SparkFun kit initially for prototyping and then I moved it to the enclosure.

Step 2: The Build

The build was fairly simple.  I just had to put everything together.

Enclosure:
I moved all of the electronic components to the enclosure.  I used double sided tape to mount the breadboard and arduino to the enclosure. I poked holes through the case to mount the light and temperature sensors externally and I attached them with quick connects.  I used tape to make them somewhat waterproof.

I drilled holes in both sides of the case.  These are to accommodate the power supplies, solenoid, and soil moisture sensor. I used hot glue to seal the holes.

Soil Moisture sensor:
For the soil moisture sensor I used a length of wire (lamp or speaker wire will do) and stripped the ends and attached  one end to the two bolts using the nuts to secure the wire.  I pushed the bolts through a chunk of Styrofoam to give the setup a little stability.  I used quick connects to attach the other end back to the power supply and Arduino.

Irrigation system:
I attached the solenoid to the planter by cutting a whole in the top of the planter and using a zip tie to secure the solenoid.  I used the same wire and quick connects to attach the solenoid to the power supply and Arduino.

I have a recycled plastic bottle setup as the water supply.  From there I ran 1/2" irrigation tubing to the solenoid.   I then ran the tubing around the inside of the planter with about 3" in between the coils.  After I ran the tubing I used a thumb tack to poke holes in the tubing.  I spaced the holes about 6" apart.  I was simply using trial and error to get the amount of water flow I was wanting.  I bent the tubing and zip tied the end to stop the flow at the end of the tube.

Step 3: Uploading the Data

There are many ways to get the data from the sensors, but I used a connectport X2 and an xbee to upload the data to thingspeak.  They were included in the kits from SparkFun.

I setup XIG (https://code.google.com/p/xig/) on the connectport X2 to enable the Arduino it to upload it's sensor data.  There are many tutorials on setting up the Connectport and XIG, so I won't go into that.

I uploaded the data to https://www.thingspeak.com/.  After setting up an account all you need to to is setup the channels and you can use the serial print command in the Arduino code.  The again have many examples of how to upload data from several devices.

XIG will take the serial data and upload it to the appropriate channel.  Here is the excerpt from my code for an example:

//upload sensor data
  String stringOne = String("http://api.thingspeak.com/update?key=XXXXXXXXXXXXXXXXXX&field2=") + photocellReading + String("&field3=") + moistReading + String("&field1=") + tempReadingF;
  Serial.println(stringOne);

I declare a string for my sensor data then I upload it to thingspeak by using my unique API key and defining a field for each of my sensors.


Step 4: Twitter Updates

I'm using the thingspeak react application to post updates to Twitter if certain conditions are met.  Here's a link to the react documentation:  http://community.thingspeak.com/documentation/apps/react/

Any time the temperature goes over 100 degrees or under 40 degrees Fahrenheit it will post an update to twitter using the ThingTweet app.  It will also post an update if the moisture level is low and remains low for more than 4 hours, which would mean that it is possibly out of water or something is wrong.  The last notification is to notify me if the Arduino has not updated Thingspeak in 2 hours.  Then I know something is wrong with the data collection.

Here's a link to my twitter feed: https://twitter.com/green_garduino

Note:  Since the temperature sensor is flaky, that is all it has been tweeting about

Step 5: Arduino Code

This was my first project with an Arduino, so some of the code could be optimized I'm sure.  It's setup to take all of the sensor data, open the solenoid if the moisture level is low, upload the sensor data to thingspeak and then check again in an hour.

Here is the code that I used:

#define aref_voltage 3.3

//Light sensor
int photocellPin = 0;
int photocellReading;

//Temperature sensor
int tempPin = 1;
int tempReading;
int tempReadingF;

//Moisture sensor
int moistPin = 2;
int moistReading;

//Solenoid
int waterValvePin = 9;

void setup(void) {

  Serial.begin(57600);  
  analogReference(EXTERNAL);
}


void loop(void) {
  //analog readings
  photocellReading = analogRead(photocellPin); 
  moistReading = analogRead(moistPin);
  tempReading = analogRead(tempPin);

  //digital output
  pinMode(waterValvePin, OUTPUT);
  digitalWrite (waterValvePin, LOW);

  //Calculate Temperature
  float voltage = tempReading * aref_voltage / 1024;
  float temperatureC = (voltage - 0.5) * 100 ;
  float temperatureF = (temperatureC * 9 / 5) + 32;
  tempReadingF = temperatureF;

//If soil is dry water for 10 seconds
if (moistReading < 600)
{
digitalWrite(waterValvePin, HIGH);
delay(10000);
digitalWrite(waterValvePin, LOW);
}

  //upload sensor data
  String stringOne = String("http://api.thingspeak.com/update?key=XXXXXXXXXXXXXXXXXX&field2=") + photocellReading + String("&field3=") + moistReading + String("&field1=") + tempReadingF;
  Serial.println(stringOne);

  delay(3600000);
}

Step 6: Final Thoughts

Everything has been running well for a few weeks.  Here is the link to my sensor data on thingspeak:  https://www.thingspeak.com/channels/6904

The temperature sensor has been a little flaky, but it is just the basic sensor included in the kit.  I would like to potentially upgrade the sensors and add additional/different sensors to different plants.  I would have all of them communicating through a zigbee network back to the Arduino.  I would also like to make the entire setup solar powered.

We may also move this to a large planter or a community garden next spring.  Hopefully this is an iterative process and I will continue to improve the setup as I go along.

Thanks for reading,
Alex


Step 7: Update

I have slightly tweaked the water source to eliminate a leak.  I added a 90 degree angle connector to take the bend out of the tubing.

The setup is leak free for now and the peppers are starting to ripen and should be ready within a few weeks.

Step 8: References