Introduction: Garduino: Gardening + Arduino

About: bicycles, gardening, and other important stuff

Garduino is a gardening Arduino. So far, Garduino:
-Waters my plants whenever their soil moisture level drops below a predefined value.
-Turns on grow lights, but only when it's dark out and only long enough to make the plants get 15 hours of total light (sunlight + supplemental light) daily.
-Alerts me if the temperature around the plants drops below 50 degrees.

This is the first grow-light and auto-water setup i know of that takes into account natural sunlight received and soil moisture level before turning on water / light.

This and other projects I've built are available as kits / products at my website.

I heavily relied on knowledge / inspiration / encouragement from:
-Mikey Sklarand his many green-tech projects
-Selwyn Pollit's permaculture knowledge
-Mitch Altman, for giving me a long-overdue lesson on how to properly solder

Future expansions might include:
-Teaching my Garduino to brew his own compost tea from greywater.
-Using pulsed, red-and-blue LED grow lights (like Mikey Sklar's setup) to significantly increase efficiency.
-Adding a solar panel and batteries to remove any need for a power grid.
-Testing for soil ph level and air CO2 content.

Step 1: Obtain Your Materials

I built this using recycled / free materials wherever I could think to. It cost significantly less than $100 in total. Here's what I used:

The relays:
2 http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?jameco_page=42&langId=-1&productId=187151&catalogId=10001&freeText=omron+g5le-1&storeId=10001&search_type=all&ddkey=http:StoreCatalogDrillDownView
Omron G5LE-1 relays]
2 http://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?langId=-1&storeId=10001&catalogId=10001&productId=1537918&
1N4004 diodes]
1 A.C. extension cord
1 A.c. power cord
1 A. C. outlet

The watering system:
1 Tiny clean-water pump
1 Plastic milk jug
~2 Old road bike tubes
1 Milk crate
String

The lighting system:
1 4' fluorescent light fixture
1 "plant type" fluorescent bulb (I used the Ott-Lite, but any bulb marketed as for plants should be fine)

The soil moisture sensor:
2 galvanized nails, 1-4" in length

The light sensor:
1 photocell

The temperature sensor / alert:
1 LED (any you'd use with an Arduino will do)
1 10k-ohm thermistor

The plants and holders:
A variety of seeds, preferably that'll grow into things you'd like to eat. Everywhere, I hear people recommend swiss chard as an easy starter plant...

Planting containers:
As many plastic milk jugs as you'd like. I used ~30.
28-gallon clear plastic storage containers. You'll need one for every 6 milk jugs.
~5 red bricks for each storage container, or anything else that will allow the milk jugs to stand at least an inch off the bottom of the container.

Soil mixture:
I used Mel's Mix, the mixture recommended in "The Square Foot Gardener." It consists of 1/3 peat moss, 1/3 coarse vermiculite, and 1/3 mixed compost, with the mixed compost coming from at least 6 different sources. I've heard lots of people bash peat moss and vermiculite's sustainability (not to mention vermiculite's obscenely-high price), so definitely explore your options here. As I understand it, you want something w/:
-lots of plant nutrients (the mixed compost)
-water retention (peat moss / vermiculite)
-'fluffiness:' soil should be light so plants can easily grow their roots through and you can easily remove plants from it (vermiculite / peat moss)

Tools / Miscellaneous
Multimeter
Wire stripper
Solder
Electrical tape
3 ~10k-ohm resistors
1 ~210-ohm resistor (for the LED)
several feet 22-gauge wire
1 Arduino (in my case a Duemanilove, but any should work)
1 Protoshield (Ladyada's model)
1 mini circuit board
Hot glue gun, with glue

Step 2: Sprout Your Plants

Get your plants going by sprouting them. There are lots of guides and devices to help you do this, so I'll just mention that you can use the vermiculite watered regularly and placed in a windowsill as an ultra-basic sprouting setup. Here is my favorite sprouting setup, and here's a useful chart on sprouting times for a bunch of different plants. Make sure you remember to rinse the sprouts regularly, or they can get moldy and gross.

If you're smarter than me, you'll label your seed grid so that you can remember what is growing in the different areas of your sprouter. Below is my attempt at this, rendered useless when I planted the plants in random disorder.

Step 3: Build Your Relays

This was a lot more difficult before Sparkfun released their guide; y'all have it easy now:)

I used Omron G5LE-1 relays, attaching wires with solder for the electrical connections and then adding hot glue around them for some structural integrity.

As per this guide, you should make sure to run the white wire directly to the outlet / end of extension cord and the black wire through the relay. For this to be useful, you'll also need to make sure you plug your creation into the wall corectly: black wire to small slot...

See photo 3 for a view of how you place the diode.

Obviously, you're now dealing with more potential to hurt yourself: AC does not feel good!

Oh, and there's no reason you can't use outlets or extension cords for both of these. I just switched it up for variety:)

Step 4: Build Your Moisture Sensor

Your moisture sensor consists of galvanized nails some distance apart from each other in the same milk jug of soil. When the soil is more moist, the sensor will report a lower resistance.

Solder a wire to the head of each nail, and be generous: this will be a structural connection as well as electrical. One nail wire gets connected to +5v on the Arduino, and the other goes to both an analog input and a resistor (then ground)

Step 5: Add Temperature and Light Sensors

The temperature and light sensors are easy: connect one end of each sensor to +5v on the arduino and the other end to both an analog i/o on the arduino and a 10k resistor. Then, connect the other end of the resistor to arduino ground and revel in your sensor-building skills.

Step 6: Make and Populate Your Soil and Planters

Let your creativity run wild here, with a little advice:
-Your inner pots (in my case, the milk jugs) should allow water to drain out and rest on top of bricks to provide space below them. I nearly killed some lettuce because of over-watering and a lack of drainage... thanks to ~20 nail holes on the bottom of the jug, the lettuce is now recovering nicely
-Your outer planter should not leak, unless you really want water all over your house

The soil I used is the Mel's Mix described in step 1. Mix all ingredients well to a consistent soil.

Planting's basically a matter of burying the bottom half of your sprout in the dirt and hoping for the best. Be sure not to plant too densely (like I probably have); you can get recommendations on planting density via the back of your seed packets.

Step 7: Test and Calibrate Your Sensors

I loaded this code onto my Arduino to read sensors connected to analog pins 0, 1, and 2 and output values to screen:

int moistureSensor = 0;
int lightSensor = 1;
int tempSensor = 2;
int moisture_val;
int light_val;
int temp_val;

void setup() {
Serial.begin(9600); //open serial port

}

void loop() {
moisture_val = analogRead(moistureSensor); // read the value from the moisture-sensing probes
Serial.print("moisture sensor reads ");
Serial.println( moisture_val );
delay(500);
light_val = analogRead(lightSensor); // read the value from the photosensor
Serial.print("light sensor reads ");
Serial.println( light_val );
delay(500);
temp_val = analogRead(tempSensor);
Serial.print("temp sensor reads ");
Serial.println( temp_val );
delay(1000);

}

Here are some values I maintained from my sensors:
moisture (nails fully into soil at opposite ends of milk jug:
nails touching each other: 985
nails in air, not touching: 0
soil that seems too wet: 889
soil that's totally dried out: 0
soil that's starting to seem too dry: 707
soil that seems about right: 826

light:
indirect sun: 949
ambient indoor light at night: 658
ambient indoor light at night, hand casting shadow over sensor: 343
~2 feet from grow light, at night: 832
~2 feet from grow light, at night, hand casting shadow over sensor: 797

temperature (used temperature lead on multimeter to calibrate):
61 degrees Fahrenheit = 901
90F = 949
51F = 877
32F = 796

On soil moisture, it's kind of guesswork unless you get a fancy probe to compare its values to what your Garduino is outputting. Or, you could add a fixed amount of water to a known quantity of soil to figure out how resistance value varies with changes in water added... if you do, you'll want to mount the nails some fixed distance from each other (with some nonconductive material, obviously). Let me know if you do this!

Step 8: Make Your Sensors Control Your Relays

Based on the values you obtained in step 6, we're going to make our Arduino flip a relay on and off depending on light intensity. Here's the code I used:

int moistureSensor = 0;
int lightSensor = 1;
int tempSensor = 2;
int moisture_val;
int light_val;
int temp_val;

void setup() {
Serial.begin(9600); //open serial port
pinMode (2, OUTPUT);
pinMode (7, OUTPUT);
pinMode (8, OUTPUT);
digitalWrite (2, LOW);
digitalWrite (7, LOW);
digitalWrite (8, LOW);
}

void loop() {

moisture_val = analogRead(moistureSensor); // read the value from the moisture sensor
Serial.print("moisture sensor reads ");
Serial.println( moisture_val );
if (moisture_val < 850)
{
Serial.println("turning on pump");
digitalWrite (7, HIGH);
delay(2000);
}
if (moisture_val > 850)
{
Serial.println("turning off pump");
digitalWrite (7, LOW);
delay(2000);
}

light_val = analogRead(lightSensor); // read the value from the photosensor
Serial.print("light sensor reads ");
Serial.println( light_val );
if (light_val < 850)
{
Serial.println("turning on lights");
digitalWrite (8, HIGH);
delay(2000);
}
if (light_val > 850)
{
Serial.println("turning off lights");
digitalWrite (8, LOW);
delay(2000);
}

temp_val = analogRead(tempSensor);
Serial.print("temp sensor reads ");
Serial.println( temp_val );
if (temp_val < 920)
{
Serial.println("turning on low-temperature LED");
digitalWrite (2, HIGH);
delay(2000);
}
if (temp_val > 920)
{
Serial.println("turning off low-temperature LED");
digitalWrite (2, LOW);
delay(2000);
}
}

For my particular setup, here's the responses I received:
-moisture-probe nails separated --> relay connected to output pin 7 flips, turning on anything plugged in to that plug. Relay should turn off when nails are touched together
-light sensor: turns on relay connected to output pin 8 when shaded, off when bright light / indirect sunlight shining on sensor
-temperature LED: turns off when you touch it for a few seconds or breathe steadily on it

I hooked up LEDs to test the relay without blowing out my fluorescent bulbs by switching them on and off too quickly...

Step 9: Setup Your Lighting System

An easy step here: after checking your light's working, plug it into the relay that will control it. I rested the light fixture on top of the outer plant container, but feel free to get fancy. Optimum distance from these fluorescents for the light intensity you want is just a few inches, so make sure you get them up close, personal, and adjustable as the plants grow

Step 10: Create a Self-Watering Setup

You've got a wide variety of options here. Here's how mine works:
-pump is activated by relay; relay is controlled by moisture sensors
-pump moves water from 5-gallon bucket to chunk of milk carton
-gravity moves water from chunk of milk carton down bike tubes directly to plants

If you do a setup like this, be sure to elevate the bucket on a crate or something else: moving water a few inches vs. several feet vertically will greatly reduce the strain on your pump.

I initially tried just using a sprinkler valve mounted to the bottom of a bucket, but gravity wasn't providing enough pressure for the water to flow beyond the slightest trickle. I thought about connecting the sprinkler valve right into my plumbing, but I worried the chlorine content of water straight from the faucet would be bad for my plants (chlorine evaporates from water within something like 24 hours).

A better version of this would use 2 buckets, with water coming from sprinkler valve connected to house plumbing into one bucket, being held there 24+ hours, and then moving into the 2nd, plant-feeding bucket.

The best version I can think of would use greywater and a little aquarium pump to make compost tea... have at it!

Step 11: Give Garduino Control

Now that you've got everything built, it's time to let Garduino loose on your plant friends. Here's the code I used:

//include the datetime library, so our garduino can keep track of how long the lights are on
#include <DateTime.h>

//define analog inputs to which we have connected our sensors
int moistureSensor = 0;
int lightSensor = 1;
int tempSensor = 2;

//define digital outputs to which we have connecte our relays (water and light) and LED (temperature)
int waterPump = 7;
int lightSwitch = 8;
int tempLed = 2;

//define variables to store moisture, light, and temperature values
int moisture_val;
int light_val;
int temp_val;

//decide how many hours of light your plants should get daily
float hours_light_daily_desired = 14;

//calculate desired hours of light total and supplemental daily based on above values
float proportion_to_light = hours_light_daily_desired / 24;
float seconds_light = 0;
float proportion_lit;

//setup a variable to store seconds since arduino switched on
float start_time;
float seconds_elapsed;
float seconds_elapsed_total;
float seconds_for_this_cycle;

void setup() {
//open serial port
Serial.begin(9600);
//set the water, light, and temperature pins as outputs that are turned off
pinMode (waterPump, OUTPUT);
pinMode (lightSwitch, OUTPUT);
pinMode (tempLed, OUTPUT);
digitalWrite (waterPump, LOW);
digitalWrite (lightSwitch, LOW);
digitalWrite (tempLed, LOW);

//establish start time
start_time = DateTime.now();
seconds_elapsed_total = 0;

}
void loop() {
// read the value from the moisture-sensing probes, print it to screen, and wait a second
moisture_val = analogRead(moistureSensor);
Serial.print("moisture sensor reads ");
Serial.println( moisture_val );
delay(1000);
// read the value from the photosensor, print it to screen, and wait a second
light_val = analogRead(lightSensor);
Serial.print("light sensor reads ");
Serial.println( light_val );
delay(1000);
// read the value from the temperature sensor, print it to screen, and wait a second
temp_val = analogRead(tempSensor);
Serial.print("temp sensor reads ");
Serial.println( temp_val );
delay(1000);
Serial.print("seconds total = ");
Serial.println( seconds_elapsed_total );
delay(1000);
Serial.print("seconds lit = ");
Serial.println( seconds_light);
delay(1000);
Serial.print("proportion desired = ");
Serial.println( proportion_to_light);
delay(1000);
Serial.print("proportion achieved = ");
Serial.println( proportion_lit);
delay(1000);

//turn water on when soil is dry, and delay until soil is wet
if (moisture_val < 850)
{
digitalWrite(waterPump, HIGH);
}

while (moisture_val < 850)
{
delay(10000);
//thanks to JoshTW for the following, important correction
moisture_val = analogRead(moistureSensor);
}

digitalWrite(waterPump, LOW);

//update time, and increment seconds_light if the lights are on
seconds_for_this_cycle = DateTime.now() - seconds_elapsed_total;
seconds_elapsed_total = DateTime.now() - start_time;
if (light_val > 900)
{
seconds_light = seconds_light + seconds_for_this_cycle;
}

//cloudy days that get sunny again: turn lights back off if light_val exceeds 900. this works b/c the supplemental lights aren't as bright as the sun:)
if (light_val > 900)
{
digitalWrite (lightSwitch, LOW);
}

//turn off lights if proportion_lit>proportion_to_light, and then wait 5 minutes
if (proportion_lit > proportion_to_light)
{
digitalWrite (lightSwitch, LOW);
delay (300000);
}

//figure out what proportion of time lights have been on
proportion_lit = seconds_light/seconds_elapsed_total;

//turn lights on if light_val is less than 900 and plants have light for less than desired proportion of time, then wait 10 seconds
if (light_val < 900 and proportion_lit < proportion_to_light)
{
digitalWrite(lightSwitch, HIGH);
delay(10000);
}

//turn on temp alarm light if temp_val is less than 850 (approximately 50 degrees Fahrenheit)
if (temp_val < 850)
{
digitalWrite(tempLed, HIGH);
}

}

Note the inclusion of the datetime library, which you can install from here. Place the contents of the file in the libraries directory of the arduino folder and you should be good to go.  See the readme in the download if you run into problems.

Monitoring needs to be greatly improved, as Garduino should sit there doing nothing most of the time when it's working properly. You should be able to pull the moisture sensors from the soil and have them turn on within a few seconds (air = 0 conductivity between them), but you can't do this with the light sensor: it's just trying to turn on for 16 hours every 24 hours. Currently, connecting your Arduino to your computer and then monitoring the serial port will give you some meaningful feedback. But, this is resetting the time counter to 0, so you don't get any useful historical data unless you leave the Garduino with a computer connected during the period you want to monitor...

Step 12: Reap Your Harvest

Check your seed packets (you saved them, right?) to see when your plants should be mature, and harvest them by that date. But, don't be surprised if you've got them ready to go sooner!

Save your bounty's seeds to replant, if you didn't plant some weird hybrid that doesn't produce viable seeds...

Step 13: Share Your Results

What excites me most about this project is the ability to trade information about growing things with conditions more controlled than is typical for gardening. So, please: participate! Build a better version of this, or buy it from somebody else, and let me know how it's working. Most importantly, let me know what settings or improvements produce greater yields for you!

Step 14: Improve Away!

I mentioned some planned improvements in the introduction, and I'm sure you can think of a bunch more. Let me know what you build or want built! Happy planting!

Craftsman Workshop of the Future Contest

Participated in the
Craftsman Workshop of the Future Contest