Vol. 18: The Garduino Garden Controller
Geeked-out gardening: use a microcontroller and simple sensors to give plants exactly the water and light they need.
By Luke Iseman
Photos by Luke Iseman, Michael T. Carter, Ed Troxell
Illustrations by Gerry Arrington, Timmy Kucynda
Digital Edition
SUBSCRIBERS:Read this article now in your digital edition!
Get Make:
Subscribe to MAKE and get the best rate!
+ Downloads & Extras:
Most Recent Run-Time Code (updated May 2, 2009)
//include the datetime library, so our garduino can keep track of how long the lights are on #include//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); } 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); } }
+ LINKS
Garduino Garden Controller on Make: Projects
Arduino Duemilanove
ProtoShield (Circuit Board for Arduino)
Omron Relays
1N4004 Diode
220 resistor (sold in bags of 100, or just buy a few at RadioShack)
LED (or try RadioShack)
Photocell
10k thermistor
22-gauge solid-core wire (100' roll, or buy assorted colors at RadioShack)
10k resistors (sold in bags of 100, or just buy a few at RadioShack)
Parts list
Mikey Sklars version of a grow light made from red and blue LEDs
Arduino development application
Arduino Tutorial
Harbor Freight
Jameco
Maker Shed
» MAKE: NOISE — Discuss this article
You must be logged in to post a talkback.[ Display main threads only] [ Oldest First]
Showing messages 1 through 32 of 32.
- It Works!
You must be logged in to reply.
I have built this project for a science fair and it works great! Instead of using several extension cords I wired the buses of an extension cord to work the same way. It keeps it very neat and I also added an uninterrupted plug in the cord for the arduino so I don't have to use batteries or find another outlet. Thanks for the idea Luke! (I also added a heat lamp to maintain temperature.)
Thanks a ton,
Eric B.Posted by robot452 on January 28, 2011 at 19:18:39 Pacific Time
- It Works!
You must be logged in to reply.
Sorry when I said extension cord I meant to say power strip. My bad.
Eric B.Posted by robot452 on January 28, 2011 at 19:19:36 Pacific Time
- Relay trips GFCI
You must be logged in to reply.
Hi,
I set up the circuit as shown, and when my two nails are apart (below 850) the pump runs, then when I touch the nails together and the value goes above 850 the relay shuts the circuit off and the pump stops. However, when that happens the GFCI trips and when I pull nails apart the pump doesn't begin again.
Can anyone provide guidance as to why this might be happening.
Right now I'm running the setup dry, with no water to test (if this burns out my $10 pump, so be it, it can be replaced).
Any help appreciated, thanks.
-RPosted by Gorpomon on June 14, 2010 at 07:28:28 Pacific Time
- Relay trips GFCI
You must be logged in to reply.
Really doesn't sound good if you're tripping the GFCI. You might have connections set up wrong (we all do it) or a short. And that can be really dangerous. I'd bust out the trusty multimeter and see what's wrong. Just use the "continuity tester" to make sure there are no shorts between the various wires connected to the relay. Then, with the household power to the pump unplugged, check to make sure the switch is running properly and is closing and holding the circuit closed when the Arduino tells it to. Just hook up leads on either side of the switch and check that the beeps come and go when they should.Posted by guiganol on July 27, 2010 at 11:07:48 Pacific Time
- Relay trips GFCI
You must be logged in to reply.
Also, if you're using one of those garden fountain pumps, I'd put it in some water while testing. Those things really shouldn't be run without water and it may be the stress on the motor that's triggering the interrupt.Posted by guiganol on July 27, 2010 at 11:21:40 Pacific Time
- Relay trips GFCI
You must be logged in to reply.
Hello Gorpomon,
I'm not sure why that's happening. Please try without a GFCI outlet and let me know what result you see.
Thanks,
LukePosted by liseman on June 28, 2010 at 23:52:26 Pacific Time
- Moister value stops code
You must be logged in to reply.
I'm having the same problem as JoshTW (Posted by JoshTW on January 03, 2010 at 23:59:58 Pacific Time). If the moisture reading goes below the set value the code stops running. I tried the JoshTW's fix; but either I've applied it incorrectly, or it doesn't work. Can anyone help? Thanks in advance for helping a newbie--this is my first foray into programming & electronics.Posted by AwnMan on January 24, 2010 at 07:09:26 Pacific Time
- Watering code error
You must be logged in to reply.
During testing it was getting stuck in the watering "while" loop. It can't tell when the soil gets wet because the moisture_val is not being updated with-in the "while (moisture_val < 850)" loop. I just changed the if and while statements to contain "analogRead(moistureSensor)" instead of "moisture_val". Another option would be to put a "moisture_val = analogRead(moistureSensor);" statment inside the while loop. Please update the code.
This is the code I am referring to:
// read the value from the moisture-sensing probes, print it to screen, and wait a second
moisture_val = analogRead(moistureSensor);
//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);
}
digitalWrite(waterPump, LOW);
Change the while loop to:
while (moisture_val < 850)
{
delay(10000);
moisture_val = analogRead(moistureSensor);
}
Posted by JoshTW on January 03, 2010 at 23:59:58 Pacific Time
- Watering code error
You must be logged in to reply.
Thanks JoshTW; I've made the correction to the Instructable and will ask Make to add a note above the comments on this page!Posted by liseman on February 05, 2010 at 01:13:19 Pacific Time
- my flourecent light won't turn on!!
You must be logged in to reply.
i am trying this system as a component for a science fair project (testing if a plant would grow better in a human controlled garden vs. an arduino powered one) I am using an array of springs as my circuit board, i wired every thing correctly, but when i test my control over my florescent light, it doesn't turn on! i need to start working soon and am running out of ideas.Posted by circuit dude on November 08, 2009 at 15:01:55 Pacific Time
- my flourecent light won't turn on!!
You must be logged in to reply.
Hey guys. (And Luke, nice write up. Built my own version which is more simple but it's nice checking out yours.) Anyway... I think your problem is that the Arduino isn't putting out enough juice to trigger the relay. Actually, for the beefier relays that would be capable of closing a household line, you'll need more current than the 40-50mA that the output pin provides. Check out this for using relays with an Arduino: http://www.arduino.cc/playground/uploads/Main/relays.pdf
The data sheet on the g5LE you're using shows a coil rating of 79.5 mA so you'll need a transistor to boost the current. It ain't too difficult to set up, but you'll have to check the specs to try and get things set up so you won't need an external power supply to power the relay. ('Course you can also piggyback off your 9 volt supply if you need some extra power).
My relay runs on about 45mA but I'm just switching on a 3 volt pump (but I still used the transistor to make sure everything is solid).
If you're into learning even more, here's a great tutorial on using transistors with relays (scroll down): http://www.kpsec.freeuk.com/trancirc.htmPosted by guiganol on July 27, 2010 at 10:51:40 Pacific Time
- my flourecent light won't turn on!!
You must be logged in to reply.
hi circuit dude,
how are you testing the fluorescent light?
thanks,
lukePosted by liseman on November 10, 2009 at 10:23:50 Pacific Time
- my flourecent light won't turn on!!
You must be logged in to reply.
i have already given up on the light, but my water pump is experiencing the same problem, would it make any difference that i used a different relay?
i'm testing it using a code that sends out charge from digital i/o 7 for 5 seconds and then stopsPosted by circuit dude on November 11, 2009 at 06:42:49 Pacific Time
- my flourecent light won't turn on!!
You must be logged in to reply.
that is very likely to be the culprit. you can get the exact relay i used here: http://mouser.com/Search/ProductDetail.aspx?R=G5LE-14-DC5virtualkey65300000virtualkey653-G5LE-14-DC5
. good luck, and let me know if it works!Posted by liseman on November 11, 2009 at 09:22:21 Pacific Time
- Aquaponics
You must be logged in to reply.
Hi,
Anyone tried to use the garduino as part of a hydroponics system. I am contemplating doing this and would appreciate any advice.
ThanksPosted by RonanOD on October 24, 2009 at 16:25:40 Pacific Time
- Aquaponics
You must be logged in to reply.
hi,
i've started experimenting with this, but haven't finished anything yet. particularly, i think it could be cool to integrate with a window farm: http://www.windowfarms.org .
good luck,
lukePosted by liseman on November 10, 2009 at 10:23:01 Pacific Time
- "First green"!
You must be logged in to reply.
Here is a link to my "build diary" on YT:
http://www.youtube.com/watch?v=PjwHKSD9ww8
This is the more interesting second entry. I've got basil shoots!Posted by morrildl on July 30, 2009 at 20:15:10 Pacific Time
- Earthbox?
You must be logged in to reply.
Anyone tried this with an Earthbox? It seems like it might be just as easy to keep the Earthbox full, as the feeder bucket. And then you can make do with only the photodiode and grow-light relay...Posted by morrildl on June 29, 2009 at 21:44:09 Pacific Time
- Earthbox?
You must be logged in to reply.
hi,
i haven't tried using this with an earthbox, but i like the idea. especially if you wire to a sprinkler solenoid as i did here: http://voltaicsystems.com/diy/solar-powered-automated-garden/ .
thanks,
lukePosted by liseman on July 09, 2009 at 02:53:59 Pacific Time
- Earthbox?
You must be logged in to reply.
Hmm, Earthboxes have a water overflow outlet that prevents overfilling, so it should be possible to have the Arduino turn on a sprinkler valve every 12 hours, and leave it on until a sensor detects water coming out the overflow outlet.
The question is: how would you build a water-detection sensor+circuit? This exceeds my electronics knowledge. :)Posted by morrildl on July 22, 2009 at 20:59:18 Pacific Time
- Nails
You must be logged in to reply.
how far apart are people putting their nails to get the correct resistance?Posted by esqueleto on June 20, 2009 at 11:37:10 Pacific Time
- Nails
You must be logged in to reply.
hi esqueleto,
i placed the nails on opposite corners of a milk jug for my readings. if you're using different containers and/or different soil, you can set your own calibrations.
for more advanced watering accuracy, borrow a water meter (here's one: http://www.growerssupply.com/farm/supplies/prod1;gs1_greenhouse_lighting-gs1_light_meters;pg105067.html )from a local gardening store and calibrate your sensor readings based on the water meter's readings at different levels of soil moisture.
-lukePosted by liseman on June 24, 2009 at 11:44:35 Pacific Time
- I think the wiring diagrams are wrong
You must be logged in to reply.
Step 3 (Page 95) has the two left-most columns on the breadboard connected to 5V and GND. Steps 5 and later have them connected to GND and VIN.
I haven't actually tried the circuit yet, but I the the setup in Step 3 is the correct one; looks like the later ones are an error, since they differ from Step 3 and also seem to differ from what the text is telling you to connect.Posted by morrildl on June 14, 2009 at 14:42:55 Pacific Time
- I think the wiring diagrams are wrong
You must be logged in to reply.
hello morrildl,
you're absolutely right: the illustaration on p. 95 shows the correct connection of ground to breadboard - and 5V to breadboard +, and the illustrations on 97 and 99 then show the incorrect connection. follow the text description and the picture on p. 95, and you'll get it right.
thanks!
-lukePosted by liseman on June 24, 2009 at 11:37:31 Pacific Time
- Light problem
You must be logged in to reply.
Any idea why my lights would turn on during a digitalwWrite(light, LOW);??And then turn off with a HIGH? I have changed the Relay pins, and not sure what is going on. Ideas? Thanks.Posted by mtnbiker on June 11, 2009 at 21:16:09 Pacific Time
- Light problem
You must be logged in to reply.
hi mtnbiker,
this means you have the relay connected incorrectly. there should only be one connection per relay you need to change: looking at the relay with the pins down, the extension cord's output (the end to which you'll connect the lights) should be connected to the bottom right pin of the relay. if you turn the relay over, there will be a small number '4' written next to the correct pin.
-lukePosted by liseman on June 24, 2009 at 11:33:47 Pacific Time
- Light problem
You must be logged in to reply.
Actually I think the original poster is correct. According to the data sheet for the part you specified (Omron G5LE-1 DC5V), pin 4 is normally-closed; pin 3 is normally-open. So indeed, if you use pin 4, AC is connected until you apply voltage across the coil pins, meaning the light is on.
I just wired it up to pin 3, and it works as expected.
Not that this is that big a deal, you can always just do a simply logical NOT in the Arduino code.Posted by morrildl on July 04, 2009 at 12:40:33 Pacific Time
- Light problem
You must be logged in to reply.
glad to hear you've got it working; please link to pictures when your plants start growing!
-lukePosted by liseman on July 09, 2009 at 02:52:17 Pacific Time
- Light problem
You must be logged in to reply.
Definitely! I am putting a video build diary on YouTube; I need to get a microphone for the next installment though.Posted by morrildl on July 22, 2009 at 20:48:55 Pacific Time
- DateTime Library
You must be logged in to reply.
You need to download the DateTime library and extract the contents of the zip file into the hardware\libraries folder, then use
#include <DateTime.h>Posted by mtnbiker on June 11, 2009 at 21:01:27 Pacific Time
- relay pins
You must be logged in to reply.
page 99 the relay pins are mixed upPosted by xboogerx on May 26, 2009 at 19:00:51 Pacific Time
- relay pins
You must be logged in to reply.
the relay connection is one of the most difficult parts of the project. the diagram on page 99 is correct; here's a step-by-step guide to connecting them: http://garduino.dirtnail.com/makemag/stepbystep.html . also, here's step-by-step with video for the protoshield version: http://garduino.dirtnail.com/run1/ .
-lukePosted by liseman on June 24, 2009 at 11:31:04 Pacific Time
|
Showing messages 1 through 32 of 32. |
Join the conversation -- every MAKE article has an online page that includes a place for discussion. We've made these RSS and Atom feeds to help you watch the discussions: subscribe.










