Introduction: Garduino: Gardening + Arduino

Picture of Garduino: Gardening + Arduino

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

Picture of 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:
Omron G5LE-1 relays]
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

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
Wire stripper
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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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 );
light_val = analogRead(lightSensor); // read the value from the photosensor
Serial.print("light sensor reads ");
Serial.println( light_val );
temp_val = analogRead(tempSensor);
Serial.print("temp sensor reads ");
Serial.println( temp_val );


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

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

Picture of 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);
if (moisture_val > 850)
Serial.println("turning off pump");
digitalWrite (7, LOW);

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);
if (light_val > 850)
Serial.println("turning off lights");
digitalWrite (8, LOW);

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);
if (temp_val > 920)
Serial.println("turning off low-temperature LED");
digitalWrite (2, LOW);

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

Picture of 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

Picture of 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

Picture of 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
//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 =;
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 );
// 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 );
// 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 );
Serial.print("seconds total = ");
Serial.println( seconds_elapsed_total );
Serial.print("seconds lit = ");
Serial.println( seconds_light);
Serial.print("proportion desired = ");
Serial.println( proportion_to_light);
Serial.print("proportion achieved = ");
Serial.println( proportion_lit);

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

while (moisture_val < 850)
//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 = - seconds_elapsed_total;
seconds_elapsed_total = - 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);

//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

Picture of 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

Picture of 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!

Picture of 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!


ArranC2 (author)2016-09-17

Using the probes that directly contact with the soil and pass a current through it to measure moisture content it a pretty poor setup long term.

The probes tend to corrode really badly (mine lasted a little over a month), and they don't give reliable or stable voltage readings.

Either of the capacitive sensors here:


- or here

Will do a much better job. I use the dfrobot ones in my setup, with one of these boards

They give a range between 0-1v (1v is open air), and the voltage decreases as moisture content increases.

So far they work pretty well, and read pretty consistently uncalibrated, as in two sensors will give about the same value if placed in the same location in one of the planters.

The one thing i've found which throws them off is variances in the resistance of the solder joins in the sensor cables... Considering replacing them with the I2C sensors for that reason. But the non-I2C probes are considerably cheaper, even with the ADC board, when you've got a bunch of planters to monitor.

My setup is bigger than the one here, with seven planters, and 20 gallons of water storage. Water is pumped directly to the plants using a 12v diaphragm pump, with 12v solenoid valves to control distribution, and soaker hose buried in the planters. Controller is a raspberry Pi, with code written in C.

ArranC2 (author)ArranC22016-09-17

Ah, and for anyone thinking of using a diaphragm pump directly into soaker hose, I highly recommend some sort of expansion vessel. Even a 1.5l pop bottle half full of air will do.

Running the pump directly into soaker hose, is a recipe for busted pipes/pumps, found that out the hard way :)

Also tried a gravity feed, where the water was pumped up, about 2M above the planters, and fed back down, but there wasn't enough pressure to make it efficient.

Now I have an expansion vessel, and just blip the pump for 2 seconds, leaving the valve on the planter open for 15. The air in the expansion vessel is compressed by the pump, and then forces the water through the soaker hose for the period the valve is open. Works well, and the pump doesn't seem to mind the short duty cycles.

liseman (author)ArranC22016-09-18

this is helpful; thanks! any chance you can add photos of your setup?

ArranC2 made it! (author)liseman2016-09-18

I can post some in a few weeks. Away for the month... That's actually the primary reason for automating the watering :)

Here's one pre-automation. I added another long planter to that.

ArranC2 made it! (author)ArranC22016-09-20

Here's some basic ones... will send some more detailed ones when i'm actually there, and not photoing by proxy.

boulayl made it! (author)2017-06-03

I made this for my high school senior project. It took a lot of effort, and three months worth of weekend building sessions, but it got there! I had to substitute a few of the materials for things I thought would work better, like a more official moisture sensor, and I put it on a wagon to keep it mobile.

mad_jack34 (author)2017-01-19

Because DateTime library is outdated and won't work with current version of arduino IDE, now what? Does anyone have any working code that will run on current versions of Arduino IDE? I do have a DS3231 RTC or could get what ever is needed if it is needed.

Darkced (author)2016-09-22

can we use g5led-1-vd relay?

if we use grove, how do we connect it in our system?

can we contact you through email?

Darkced (author)2016-09-11

Hey. Would it be possible to use another relay other than Omron G5LE-1 coz it isn't available in my country. Been looking everywhere for it...

liseman (author)Darkced2016-09-12

modules from sparkfun or seeed should work too; just make sure they're able to handle the amperage of your pump. example:

Qbovv (author)2016-07-27

I've also been thinking about the nails corroding becouse I'm also making my own version of garduino. It will be in soil, so non hydro. A few things I'll try to do: only measure once in about 3 hours. I will not feed the + nail with Vcc but with a digital-out pin, so most of the time there will be no current flowing so i guess the nails will corrode slower. First set the pin HIGH, a few seconds before the readings. Take an average of about 1000 samples. Then code 'if less then' or 'if higher then' to enable the pump if nessecary. (still haven't written a single line of code, I'm in the thinking process :) ). Set pin LOW, wait a few HOURS. Loop to begin (set high a few seconds before...) and so on...

guidokritz (author)2016-06-19

Hi! The link you provided to the water pump doesn't seem to be working (or maybe it's out of stock). Can you please share the specs on the water pump? Thanks!

notflip (author)2014-10-30

How do you use a nail to measure humidity? I don't really understand the concept. Thanks!

AlexanderC73 (author)notflip2016-04-04

The idea is to drive current into one nail and see how many electrons jump over to the second nail. The higher the moisture content of the soil, the higher the electron count moving through it. Moisture improves conductivity. In essence you are measuring the resistance of the soil.

ZRandal (author)2015-06-24

Noticed that you used two nails. Unfortunately, I have had my fair share of trying to build sensors out of nails, but they all corrode very quickly (in one case it corroded in less than a week). One solution that i have seen was using gypsum, but that can get painfully annoying at times. Would it be possible to fully insulate it like this soil moisture sensor? If so, I might consider building another sensor and giving it a go... Just don't want to have to deal with another corroding sensor...

Gustavo Forster (author)ZRandal2015-08-20

Hi. I had the same problem. But my solution was quite simple. I used two stainless screws with also stainless bolts. The copper wires were crimped in terminals, so they don´t get in touch with the soil. I also used the same method to make a sensor inside a water tank. So my garduino works only this sensor says there water in the tank.

Best Regards

steve8428 (author)2014-05-08

I made the same as this but with some alterations, its currently reading the vegetable garden and turns a pump on when it needs watering and a valve, I have two sensors and two valves so they are individually controlled by the same Arduino. The water is passed through leaky hoses to water the garden. I also take 10 reading 3 seconds apart and divide this by 10 to get the average reading, This prevents spurious readings causing the system to start watering for no reason. My soil readings are uploaded to a web site at

I am still testing the resistors as I would like it more sensitive, at the moment I am using a 5 Meg resistor.

My probes are made from 8mm copper tubing which are flattened and tinned which have so far been all ok but this is a new project.

I will hopefully update an instructable once i have it all working ok. Great to see you one up and running. I will post my code on the web site soon

coltronc (author)steve84282015-06-29

Any chance you still have the code? I'd love to have a look at it.

áaryal (author)steve84282014-06-05

Could be please explain the working mechanism for the soil moisture sensor. As you are using copper probes what is the working principle for it. Please reply, my professor is asking for it as i have proposed the same system to him.

diy_bloke (author)áaryal2014-10-11

it might be too late for your professor, but here is the answer... just in case someone else is wondering.
the moisture sensor is nothing more than 2 probes that together with the sol in between form a resistor. If the soil is wet the resistance goes down.
That resistor is then put in a voltage divider (i.e. another transistor is put in series) and the voltage of the junction of the 'real' resistor and the 'soil' resistor is measured.
In reality the sensor doesn't measure true moisture but ion concentration in th ewater

ngwpower (author)2015-05-25

Really like seeing growing and technology in the same place.

1. Can this be used to open and close a Linear actuator for the roof vent?

2. Turn on & off a gable vent fan??

Chanio (author)2015-04-12

Sorry, but Jameco diode link is down, found this:

Ardutronico (author)2014-12-24

I'm going to make it, and I'll put some improvements. Per example, I'll use an AtTiny and connect it to the Arduino by RF, which will have the Ethernet Shield or put the Garduino a Wi-Fi Module to connect to the Internet, making an IOT Garden controller. I'll call it the Gardtiny.

davidbarcomb (author)2014-11-26

Very nice project. Thanks for sharing

shea.lombardo (author)2014-08-26

This is an awesome tutorial. When I first created my moisture sensors they were reading values in the 600-700 range, which seemed okay to me. I picked the system back up about a month later when I moved somewhere where I actually have sun, and now they will only read values between 1-50. I tried replacing the nails and double checked the circuit but I can't seem to find a fix. Any ideas what the problem might be?

crackopl (author)2014-07-06


see my -large- project :

Akin Yildiz (author)2014-05-03

hello again, i also have couple of additions/ideas if you don't mind... assuming we have changed the lights to high power led.s, everything running thru arduino, FIRST suggestion is to bring back the gravity idea for watering, i think the water pump is unnecessary electricity and taking up outlet space, noisy and too big, we are already adding water to the tank manually, so the placement of a miniature water tower above the plants and using arduino to manually open a faucet or chamber - using aquarium tubing only probably. i feel like this will be a safer design. we should also add SECOND suggestion here; a smoke detector that shuts off everything instantly. mixing gardening and all these electronics could easily be lethal but cheaply fixable just thru smart designing. i know you put it together very fast and i know you are more than careful, but not everyone will be...

also check out my almost finished 7W custom LED plant arm, a newer addition, i'm just learning to use arduino, thanks to you very fastly. especially for what I need

love & peace

Akin Yildiz (author)2014-04-28

liseman, a great project once again. may I suggest using a different setup for the lights? check it out; i'm in the process of combining the two technologies...

nblyumberg (author)2014-02-04

I was reading your Instructable as I am working on a similar project. Just wanted to let you know there is a very minor logic error when you do your sensor comparisons. For example, if you run through your code with light value of exactly 850 you'll see that scenario does not match any condition. Simple fix to add an = comparison to one of the other scenarios.

manoellemos (author)2013-11-22

Hi, I'm writing a blog post about cool Arduino based projects and your's is going to be there. Do you allow me to use one or two of your pictures in the post? I'm linking the references to the project back to this page.

Thanks in advance!

Manoel Lemos

liseman (author)manoellemos2013-11-24

Hi Manoel,

Feel Free to reuse however you'd like!


diy_bloke (author)2013-10-22

great. as regarding the reading of yr moisture sensors, what i have done in a similar case is to measure the resistance of the earth via my spikes in my plant bed when it was moist enough and calculated a voltage from that which told me the reading I was going to get from the arduino. used that as an irrigate or not threshold in my program. Worked well.
Keep in mind that two spikes in the earth, also give off a small voltage that can innfluence yr settings :-)

TXTCLA55 (author)2011-03-04


//establish start time
start_time =;
seconds_elapsed_total = 0;

Wont comply as "DateTime" was not declared in this scope.

Even though i added the file to arduino complier.

aldorr (author)TXTCLA552013-09-28

For anyone who's trying to do this and has had the same problem. I followed these steps to solve it:
1. Download the Time library:
Put it in your libraries folder. On my setup, Lubuntu, is in home/#username#/sketchbook/libraries. (You may have to create the folder.)
2. Change the "#include " to "#include " (without quotes)
3. Change 3 instances of "" to "now()" (again no quotes)
Should compile now.
Hope this helps.

jmarnocha (author)TXTCLA552011-03-23

i am having the exact same issue. any thoughts????

liseman (author)jmarnocha2011-03-24

please double-check that you can run separate, simpler datetime functions to confirm you have the datetime file in the correct folder. if that doesn't work (or does), let me know!

TXTCLA55 (author)liseman2011-03-25

Lisemsan, how do i do that? I haven't really done much work with my arduino since i bought it and i am not to found of programming...

durgenflabbit (author)2011-12-14

hey liseman,

From what I can tell, excellent tutorial. I am kind of new to arduino but I really want to try this one out, I figure Im a fast learner.

But the 2nd link on your materials list is broken, or at least doesn't link me to a product that still exists. Just wanted to make sure I got the right diodes. If you could point me in the right direction I'd appreciate it. But then again, I dont even see where you used them, unless I missed something. Thanks again.

daley045 (author)durgenflabbit2012-02-12

I am working on replicating a similar project and have spent most of the day getting the water pump figured out. This is where you need the diodes. I am setting up a drip hydroponic system that turns the pump on and off with a set time interval. What I understand is that when the motor turns off it sends a high voltage shock through the system. I have unfortunaly / naively been using only a 50v diode which was not enough to protect the system from the voltage generated by the 120 volt water pump. I am new to electrical systems. Does anyone know what diode I should be using.

cgosh (author)daley0452013-01-03

When you put DC on the wire coil in a relay, solenoid, motor, etc., it creates a magnetic field that pulls the armature or plunger, spins the motor, etc. When your control circuit switches the DC off, the magnetic field that's still in the coil collapses into the coil, turns its energy back into electricity and sends a very brief, reverse-biased, high-voltage pulse back down the wire (reverse EMF, or Electro-Magnetic Field).

The diode must be reverse-biased (positive lead on the negative supply wire, negative lead/band on the positive wire) to short this pulse out. If you don't do this, the reverse EMF can blow up the low-voltage semiconductor that's controlling the solenoid or motor. If you connect the diode "the way you'd expect" it simply shorts the control voltage (very bad). The diode should be as close to the coil as possible for maximum effectiveness. 1N4004 (400 Volts @ 1 amp) diodes are cheap and plentiful, motor controllers are not.

If you're ordering a relay, you may find that you can get one with a built-in diode on the coil. If you're powering your motor or other coil with a mechanical switch (like metal relay contacts) instead of a semiconductor device, you don't need the diode.

daley045 (author)daley0452012-02-14

Never mind. A 1N4004 diode should be good for 400v.

forsey (author)2012-09-20

Here's my effort - it only does the watering side of things, but includes code to provide live monitoring via a web based graph.

ben.chapman (author)2012-06-11

You should post this on, It's a community of DIY farming and gardening technologies!

diy_bloke (author)ben.chapman2012-09-07 is a domain for sale at godaddy. would you mean

LeskoIam (author)2012-07-23

I was wandering if someone already tried to calibrate moisture sensors like you proposed? Yes, and did someone use similar system for hydroponics?
I'm just starting to build my own system and but I will probably switch to hydroponics. Really cool idea and implementation!

marcuantonio (author)2012-06-29


Im bringing garduino back to life, I want to play with the ethernet shield.

However, Im getting an error, saying 'DateTime' was not declared in this scope.

Would you know how to fix this?


ReagenWard (author)2009-10-25

How's it working over time?  Almost everyone tries nails first, then moves to gypsum or the like, and if they want accuracy, they end up with a tensiometer.

Also, DC is known to be a problem for moisture sensors over time - have you considered AC or are you just replacing your probes often?

liseman (author)ReagenWard2009-11-10

Hi ReagenWard,

I'd recommend checking all components of the system every ~month, or if you notice anything odd.  Using galvanized nails seems to help things and, if you really want to play it safer, you can modify the code to only set the pin to the moisture sensors high when you're reading the moisture value.

Hope this helps,

typomaniac (author)liseman2011-05-17

sounds like a good idea. Do you have an idea how to modify the code to achieve this? I am not very experience with arduino yet..

thank you so much!

About This Instructable




Bio: bicycles, gardening, and other important stuff
More by liseman:3D Print A SplintDIY FactoryHow To Get A Shipping Container
Add instructable to: