How to make a grow box controller

021

While my existing system was working I decided to make an upgrade to the electronics on my old grow box controller specifically to have a much more industrial strength version that will run without problems for decades to come.  This version also is much safer…still probably not quite to a building code but much less worries to burning my garage down in the middle of the night.  Finally it is modular if there are problems in the future I can easily switch out electronics or sensors.

Well now I have attempted to justify my reasons this is what I used to put the whole thing together:

Parts List

If we had lawyers, they probably would want us to say this:
WARNING: I am not an electrician and do not pretend to be one.  I do not know the specific building electrical codes of your area, so please be sure your wiring is completed under the proper safety code for your area. As always, using high voltage electricity can result in self-electrocution or burn down your house if not done safely so if you are not comfortable doing this wiring please contact a qualified professional.

Putting it all together

On the electronics side overall the circuits are actually pretty simple and if using a breadboard definitely something that could be tackled by a beginner.  Though on the other side since this project is dealing with AC current I definitely would recommend caution (no hands unless power is unplugged) or have someone a little more comfortable with 120/220V help you out.

The Brains


I will be the first to admit that using an Arduino for this application is complete overkill for this application but it gives plenty of room for additions in the future.  For all intents and purpose you could have your grow box completely controlled from the Arduino own processing power though on my case the software and UI is more interesting part to me.  For this reason the Arduino code is actually very “dumb” basically just taking commands via the build in serial through USB and setting digital outputs to HIGH/LOW or reading analog inputs.

Here is the code for your grow box controller:

   1: /*

 

   2:  * GrowBox Arduino Interface

 

   3:  *

 

   4:  * Descriptions: Simple interface to digital and analog controls by passing serial inputs

 

   5:  *               For example: 

 

   6:  *                  "A1" to read analog value on pin 1

 

   7:  *                  "D1H" to set digital pin 1 to HIGH

 

   8:  */

 

   9: #include <OneWire.h>

 

  10:

 

  11: //1-wire

 

  12: OneWire  ds(8);  // on pin 8

 

  13: #define BADTEMP -1000

 

  14:

 

  15: //define unique sensor serial code

 

  16: byte temperature[8];

 

  17:

 

  19: #define PIN_VALUE 1          // numeric pin value (0 through 9) for digital output or analog input

 

  18: #define ACTION_TYPE 0        // 'D' for digtal write, 'A' for analog read

 

  20: #define DIGITAL_SET_VALUE 2  // Value to write (only used for digital, ignored for analog)

 

  21:

 

  22: int NUM_OF_ANALOG_READS = 2;

 

  23: char commandString[20];

 

  24:

 

  25: void setup()

 

  26: {

 

  27:   Serial.begin(9600);

 

  28:

 

  29:   setOneWireHex();

 

  30:

 

  31:   // Power control

 

  32:   for(int i=0; i<=7; i++)

 

  33:   {

 

  34:     pinMode(i, OUTPUT);        // sets the digital pins as output

 

  35:     digitalWrite(i, LOW);      // turn everything off

 

  36:   }

 

  37: }

 

  38:

 

  39: void loop()

 

  40: {

 

  41:   readStringFromSerial();

 

  42:

 

  43:   if (commandString[ACTION_TYPE] != 0)   {

 

  44:     int pinValue = commandString[PIN_VALUE] - '0';  // Convert char to int

 

  45:

 

  46:     if(commandString[ACTION_TYPE] == 'A')

 

  47:       Serial.println(analogRead(pinValue));

 

  48:     else if(commandString[ACTION_TYPE] == 'D') {

 

  49:       if(commandString[DIGITAL_SET_VALUE] == 'H')

 

  50:         digitalWrite(pinValue, HIGH);

 

  51:       else if(commandString[DIGITAL_SET_VALUE] == 'L')

 

  52:         digitalWrite(pinValue, LOW);

 

  53:

 

  54:       Serial.println("OK");

 

  55:     }

 

  56:     else if(commandString[ACTION_TYPE] == 'T') {

 

  57:       float temp = get_temp(temperature);

 

  58:

 

  59:       Serial.print(temp);

 

  60:       Serial.println("C");

 

  61:     }

 

  62:     else if(commandString[ACTION_TYPE] == '1') {

 

  63:       printOneWireHex();

 

  64:     }

 

  65:     else if(commandString[ACTION_TYPE] == 'V')   {

 

  66:       Serial.println("VERSION_1_0_0_0");

 

  67:     }

 

  68:     else if(commandString[ACTION_TYPE] == 'P') {

 

  69:       Serial.println("PONG");

 

  70:     }

 

  71:

 

  72:     // Clean Array

 

  73:     for (int i=0; i <= 20; i++)

 

  74:       commandString[i]=0;

 

  75:   }

 

  76:

 

  77:   delay(100);  // wait a little time

 

  78: }

 

  79:

 

  80:

 

  81: void readStringFromSerial() {

 

  82:   int i = 0;

 

  83:   if(Serial.available()) {

 

  84:     while (Serial.available()) {

 

  85:       commandString[i] = Serial.read();

 

  86:       i++;

 

  87:     }

 

  88:   }

 

  89: }

 

  90:

 

  91: void setOneWireHex() {

 

  92:     ds.reset_search();

 

  93:     ds.search(temperature);

 

  94: }

 

  95:

 

  96: void printOneWireHex() {

 

  97:   ds.reset_search();

 

  98:   if ( !ds.search(temperature)) {

 

  99:     Serial.print("NONE\n");

 

 100:   }

 

 101:   else {

 

 102:     ds.reset_search();

 

 103:

 

 104:     int sensor = 0;

 

 105:     while(ds.search(temperature))

 

 106:     {

 

 107:       Serial.print("S");

 

 108:       Serial.print(sensor);

 

 109:       Serial.print("=");

 

 110:       for(int i = 0; i < 8; i++) {

 

 111:         Serial.print(temperature[i], HEX);

 

 112:         Serial.print(".");

 

 113:       }

 

 114:       Serial.println();

 

 115:     }

 

 116:   }

 

 117:

 

 118:   ds.reset_search();

 

 119: }

 

 120:

 

 121: float get_temp(byte* addr)

 

 122: {

 

 123:   byte present = 0;

 

 124:   byte i;

 

 125:   byte data[12];

 

 126:

 

 127:   ds.reset();

 

 128:   ds.select(addr);

 

 129:   ds.write(0x44,1);         // start conversion, with parasite power on at the end

 

 130:

 

 131:   delay(1000);     // maybe 750ms is enough, maybe not

 

 132:   // we might do a ds.depower() here, but the reset will take care of it.

 

 133:

 

 134:   present = ds.reset();

 

 135:   ds.select(addr);

 

 136:   ds.write(0xBE);         // Read Scratchpad

 

 137:

 

 138:   for ( i = 0; i < 9; i++) { // we need 9 bytes

 

 139:     data[i] = ds.read();

 

 140:   }

 

 141:

 

 142:   int temp;

 

 143:   float ftemp;

 

 144:   temp = data[0];      // load all 8 bits of the LSB

 

 145:

 

 146:   if (data[1] > 0x80){  // sign bit set, temp is negative

 

 147:     temp = !temp + 1; //two's complement adjustment

 

 148:     temp = temp * -1; //flip value negative.

 

 149:   }

 

 150:

 

 151:   //get hi-rez data

 

 152:   int cpc;

 

 153:   int cr = data[6];

 

 154:   cpc = data[7];

 

 155:

 

 156:   if (cpc == 0)

 

 157:     return BADTEMP;

 

 158:

 

 159:   temp = temp >> 1;  // Truncate by dropping bit zero for hi-rez forumua

 

 160:   ftemp = temp - (float)0.25 + (cpc - cr)/(float)cpc;

 

 161:   //end hi-rez data

 

 162: //  ftemp = ((ftemp * 9) / 5.0) + 32; //C -> F

 

 163:

 

 164:   return ftemp;

 

 165: }

Copy and paste the above code into your Arduino software.   For the code above I used the OneHire.h library which is free to use and can be downloaded from here. To be able to use this library simply copy the contents to C:\arduino\hardware\libraries\OneWire. Now you should be able to Compile (CTRL+R) and upload the code to the board (CTRL+U)

Now with the software uploaded you can send some simple serial commands via its built in USB to serial adapter to interact with it.  The interface is are broken up into 1 to 4 character commands, which I will detail below

Command Description
T Returns temperature from One Wire component
D4H Sets digital pin 4 to HIGH (ON) (replace 4 for alternate pin)
D4L Sets digital pin 4 to LOW (OFF) (replace 4 for alternate pin)
A1 Reads analog value from pin 1 (replace 1 for alternate pin)
PING Returns PONG which is used to confirmed controller is online
V Returns version which is some forethought into the PC application being able to support different versions of controller software

Using the build in serial monitor tool in Arduino.exe, my application, or you should be able to control your Arduino with this very simple command based interface

Now you can hook up some LEDs and watch them blink which is fun for a little while but if you want to add some grow box components read on….

Temperature Sensor

As you can see I have fully embraced the circuit schema on the back of a napkin idea.  These are the actual diagrams I crumpled up and stuffed in my pocket with several trips to the garage for some final soldering of various joints until everything was solid.

Below is the simple circuit required to get your 1Wire temperature sensor working.  I would recommend checking your documentation (if not labels on the chip) for the orientation to have 1 and 3 correct, if you have it wrong you should get some complete unrealistic number.  Hook ground up to pin1 on the DS18S20 and pin 2 hooked up to the digital input pin 8 on the Arduino with 5V with a 4.7K resister in between to step down the voltage.

If everything is hooked up correctly you should get the current room temperature in Celsius by sending command “T” to your Arduino.  If you prefer Fahrenheit uncomment line 162 and recompile and upload your changes, though if using my software I support both degree types and do the conversion in the the software.  To make sure everything working (or just to play with your new toy) put your fingers on the chip for a couple seconds and take another measurement unless you keep your house very warm the temperature should go up a couple of degrees

1WireSensorDiagram

Turning things on and off (Relays)

If you were smart enough to check the current requirements of your Solid State Relays (SSR) before you bought them you may be able to skip this whole circuit and simply hook the digital outputs to the 5V positive side and ground to the negative side of the SSR.

Unfortunately if you are like me and bought some SSRs that require more current draw than the Arduino (or any other IC chip) of 40mA then you will need to create the simple circuit below.

image

Basic idea is pretty simple, you are using the output from the digital pins to switch of the transistor which then allows the ground to complete the circuit with the thus turning on the relay.  As you can see there is a 1K resistor between the base (middle pin) of the transistor.  If you are not using a SSR relay (though recommend you do) you should add a 1N4004 diode between the positive/negative which protects the transistor from being damaged in case of a high voltage spike which can occur for a fraction of a second when the transistor switched off, this is also known as a back-EMF diode or fly back diode.

Now here you have a couple options.  If you are confident of our wiring skills you can do like I did and take a couple of sockets and hook up the neutral and ground in parallel.  Two save space and since I really didn’t need two separate plug-ins (nor its own plug) for each relay I removed the little metal bar between the two sockets so they could be switched on independently.  Now simply hook up hot to the left side of all your relays in parallel and then connect a wire from the right side of the relay to its own plug on the two sockets.

Now a less wiring intensive method is to simply take a 6 foot (small if you can find them) and cut the hot wire (usually the one with non-smooth wire) and attach each end of the wire to both sides of the relay.

Moisture Sensor

When it comes to a moisture sensor there are a few options.  First is the classic two galvanized nails, second is the cheap gypsum soil moisture sensor which I have written up in the provided link.

If you are using the other options you will need the simple circuit below.  Technically it is a voltage divider, but that doesn’t really matter.  Just hook up one end of your sensor to 5V and other sensor to ground with 10K resistor and also connected to analog pin 0.

SoilSensorDiagram

My custom PCB solution

378

I actually started the work to create my own PCB at least a few years back.  Played with if it off and on and finally pulled the trigger to get some boards printed up which I must say was very rewarding and pretty fun experience for just $20-30 of out of pocket cost.  This provides all the circuits I mention above with a bonus circuit to let me know when my water reservoir is running low.  I also installed a Ethernet socket not

I designed this to be an Ardunio which plugs directly on top of the Arduino.  In theory I could stack more functionality on top of if but haven’t though of anything cool to do here yet.

Don’t want to spend 10-20 hours creating your own PCB and then wait 2-3 weeks for it to arrive from Hong Kong?  Well you can do the same thing with a bread board which I show below.

Virtual breadboard layout

VirtualBreadboard

If you are new to soldering or have no interest in learning I would definitely recommend this option.  Simply place the components in the holes and make connections with 18 gauge solid copper wire.  You should be able to pick a small breadboard for less than $7.

Various applications

Of course for my application, I am using this to integrate with my custom software solution to control my grow box.  Specifically soil sensor, temperature measurement, heater, lights, exhaust fan, and water pump.  So using the circuit mentioned above I ran the hot wire through each SSR with the remaining wires connected to the plug and eventually gets plugged into the wall.  Then simply hooked up the wire from the Ethernet cables to the low voltage side to turn the switches on/off.  So I would say this is a bit of an improvement over my last attempt…

Before

IMG_3777

After

019

Last I hooked the arduino up to my PC and used my custom software to control the temperature, water, and provide cool graphs as you can see below.

GrowBoxView

Sometimes life can get busy and you have limited time to keep an eye on your plants, for these times I also integrated with a custom Windows Phone 8 application which allows me to check the current state of the grow box using life tiles, water remotely (turn on/off lights/heater/fan as well), or even check out a current feed inside the grow box.

007 008

009011  010

Looks at the actual actual grow box…

003

008

41 Responses to “How to make a grow box controller”

  1. Tom Says:

    Hey, Awsome.
    I’ve been looking for someone to make one of these. They’re really expensive. I’ve been wanting to do this for a few years, but i suck at programming.

    THANKS!

    If U have time i’d like some help w/ this, my hydro system is too much matenance & if this works…it means $$$.


  2. john Says:

    do you have the software program that is shown in this write up you stated the there will be a private and public beta out i am horrible at programming any help would be appreciative ty john


  3. The Cheap Vegetable Gardener Says:

    Tom/John, currently I am falling into the classic software development trap of scope creep. I continually keep adding features as I want them. Recently it is adding a hydroponic mode for my latest hydroponic project, though I feel things are starting to wind down.

    I have also completed a Grow Box controller shield PCB for Arduino, which I still have to test the pH controller circuit, but hopefully I can get a run of these out and sell some of the extras from the run.

    If you guys (or anyone else) is interested in a PCB, complete grow box controller kit, or if you want to go the breadboard route and use the software go ahead and send me an email using the contact info above and I can provide some more information.


  4. john Says:

    I have tried to send and email but the contact link seems to be no function correct what is you contact email plz


  5. Tom Says:

    Hell ya, I didn’t think anyone realy responded to these things…lol..

    My e-mail is xxxxxxx@hotmail.com

    If your smart enough to add a PH meter, THEN,
    You are the MAN.

    We’ve gotta talk, if you feel like calling im at xxx-xxx-xxxx


  6. Tom Says:

    tj_oneel
    509
    270
    6747
    will that do it?


  7. Automated plant growing « MM3 Group 6 – "Product for Vegtable gardners Says:

    […] http://www.cheapvegetablegardener.com/2009/09/how-to-make-grow-box-controller.html Posted by Ray O'Neill Filed in Uncategorized Leave a Comment » […]


  8. Chris Says:

    I would love to try out your custom software as I am attempting to emulate this system I sent you an email hope we can arrange something thanks.


  9. Rob Says:

    cool project. I was just telling someone that the scanned circuit diagrams give credibility to your writeup. I would have preferred food stained napkins though. I too would be interested in the pH setup.


  10. Mike Says:

    I made some sensors last night using headers similar to this DigiKey Part. I cut the strip into pairs, soldered the leads, then put them in the plaster per your instructions above. The plastic carrier helps insure alignment. The gold will hopefully resist corrosion for a while. Thought you’d like to see another option to the galvanized nails.

    Thanks for the webpage. Do you have Arduino control software available. I don’t plan to use a PC for my fairly simple application.


  11. The Cheap Vegetable Gardener Says:

    Mike, that is a great idea. I need to buy some pins for an arduino shield project should order a couple extra and try it out as well. Though gypsum may corrode before even gavenlized does… AS for software should be everything you need in the post for ardunio software.


  12. Warren Says:

    I’d really like to see this expanded to include CO2 sensing and control interlocked with the exhaust fan control. Multiple temp sensing and electronic humidity sensing. Adding multiple timers for lighting control and possible hydroponics pump control. Lots of features one could put in a grow room controller.

    I like this.


  13. IndoorGrower Says:

    As other have stated, for any hydro growers there *must* be ph and TDS/EC/TDS metering as well for this to be a solution.

    having that in an affordable, customizable and computer controlled package would be awesome.

    Nicely done.


  14. The Cheap Vegetable Gardener Says:

    I would agree I really need some time to play with these curcuits and come up with an inexpensive option for probes 🙂


  15. Just2fast24 Says:

    Hey i just wanted to now if i follow all these directions closely will i avoid burning my house down? Im mainly concerned with the placement of everything and the wiring. Im down to try it out =) how long have you been using it and have you ran into any problems?


  16. The Cheap Vegetable Gardener Says:

    just2fast24, I haven’t had any problems or close calls on my side. At least in my area if you ise the same gauge wire for low and high voltage and an approved electrical box, this would actually be under code.


  17. todd Says:

    i really want this system to work can you send me schematics ?


  18. The Cheap Vegetable Gardener Says:

    todd, the schematics are in the post…let me know if you have additional questions on those


  19. Luke Says:

    Hey,

    I want to set up a similar system and although microcontroller and EE side will not be a problem for me, I’m wondering how you developed the software to interface with the micro. Is there a development environment? Do you communicate with micro using UART?

    Thanks.


  20. Tom Says:

    Hey guys…
    Europe uses 240v.
    Look what I found!: http://www.sigma-shop.com/product/63/eight-relay-board-ready-for-your-pic-avr-project-5v.html

    IT’S 5v,30mA. (ARDUINO READY)

    NO PCB!!! and able to handle 1000W lights!

    I PRAY you guys keep UPDATEING
    sofware for the Sensors… I suck at it:P.

    Co2 Sensors that read PPM R F%^$KING OUTRAGOUS!!!


  21. Tom Says:

    ALSO,,,
    can you e-mail me a copy of your beta software solution?

    Is that a part of the arduino programing software?

    It looks smooth, Great Work.
    Hope to hear from U soon.


  22. Dave Says:

    This is exactly the sort of system I am hoping to get set up with. I would like to know what you have in mind for prices on the sheild and the program to monitor the system. Your the man for sure….this system is everything I have been looking forward to. I do have a question regarding the shield though…would you leave room for expansion and a little customization for future growth maybe?
    Thanks in advance for any information!!


  23. Jeff Says:

    i was wondering if you would like to sell your growbox.


  24. Alex Says:

    Hey, I have been looking for a DIY grow controller and keep coming back to your site. I am not the greatest programmer and don’t really have a lot of free time on my hands to try to program a UI for this project. With that being said I was wondering if you had a little UI kit (with some readme’s, that fancy UI you have a picture of and some Arduino scripts) that you could post up for all of us programing inept people out there that want to use your set-up? Thanks


  25. Building of an indoor computerized growbox Says:

    […] growing environment for my seedlings and plants by using a pretty simple software program, an arduino prototyping board for the electronics, and a few solid state relays I was able to achieve pretty consistent temperature in the grow […]


  26. Dave joseph Gutierrez Says:

    sir I’ve been looking forward for you UI. But i have some question in my mind. is this possible of planting 3 different kind of plants? and how about the UI? is it controllable using PC?

    Very thankful for your respond.


  27. RG Says:

    WOW!!
    Is it possible to have software?
    I would like to start to grow also and this is what i can´t make to my self.

    Good vibrations to you!!
    http://www.youtube.com/watch?v=YpZXc1uwz98&feature=share

    – RG


  28. Homemade waterproof digital thermometer - The Cheap Vegetable Gardener Says:

    […] I am planning on using this with my grow box controller, I will show how to use this with arduino to get some numbers.  You could look at my arduino code […]


  29. Computer controlled grow box - Part 2 - The Cheap Vegetable Gardener Says:

    […] I have made some significant changes to the grow box controller, the actual grow box has undergone some minor but important changes over the past few […]


  30. Building of an indoor computerized growbox - The Cheap Vegetable Gardener Says:

    […] growing environment for my seedlings and plants by using a pretty simple software program, an arduino prototyping board for the electronics, and a few solid state relays I was able to achieve pretty consistent temperature in the grow […]


  31. Update: Grow controller rebuilt to last Says:

    […] happy with it and knows that he’ll be using it for years, maybe even decades to come. He just finished overhauling the grow controller design to help make sure he doesn’t burn down his garage one day. You have to admit, without knowing […]


  32. Update: Grow controller rebuilt to last - RaspberryPiBoards Says:

    […] happy with it and knows that he’ll be using it for years, maybe even decades to come. He just finished overhauling the grow controller design to help make sure he doesn’t burn down his garage one day. You have to admit, without knowing […]


  33. Update: Grow controller rebuilt to last | Daily IT News on IT BlogIT Blog Says:

    […] happy with it and knows that he’ll be using it for years, maybe even decades to come. He just finished overhauling the grow controller design to help make sure he doesn’t burn down his garage one day. You have to admit, without knowing […]


  34. rndm(mod) » Update: Grow controller rebuilt to last Says:

    […] happy with it and knows that he’ll be using it for years, maybe even decades to come. He just finished overhauling the grow controller design to help make sure he doesn’t burn down his garage one day. You have to admit, without knowing […]


  35. Update: Grow controller rebuilt to last | Orange Claymore Red Slime Says:

    […] happy with it and knows that he’ll be using it for years, maybe even decades to come. He just finished overhauling the grow controller design to help make sure he doesn’t burn down his garage one day. You have to admit, without knowing […]


  36. Update: Grow controller rebuilt to last | Ed Hagopian Says:

    […] happy with it and knows that he’ll be using it for years, maybe even decades to come. He just finished overhauling the grow controller design to help make sure he doesn’t burn down his garage one day. You have to admit, without knowing […]


  37. Elephant Staircase » How to make a grow box controller – The Cheap Vegetable Gardener Says:

    […] How to make a grow box controller – The Cheap Vegetable Gardener. […]


  38. Update: Grow controller rebuilt to last | Make, Electronics projects, electronic Circuits, DIY projects, Microcontroller Projects - makeelectronic.com Says:

    […] distinguishs that he’ll be using it for years, perhaps unvarying decades to happen. He valid done overhauling the extend controller plan to contribute accomplish firm he doesn’t smolder dejected hellos garage person period. You […]


  39. Update: Grow controller rebuilt to last Via Hack a Day | reDDstaGG Says:

    […] happy with it and knows that he’ll be using it for years, maybe even decades to come. He just finished overhauling the grow controller design to help make sure he doesn’t burn down his garage one day. You have to admit, without knowing […]


  40. Andrew Says:

    Hey any links to the software to run on the PC? It looks nice and I’d like to use it as well.
    Thanks, great work!


  41. Simple and cheap homemade ebb and flow hydroponics system - The Cheap Vegetable Gardener Says:

    […] Lastly attach the 1/2 plastic tube to your pump and place everything on top of your 18 gallon Rubbermaid tub (which fits perfectly and is very sturdy)  Fill with water nutrients and hook up your water pump to a 24 hour timer (or grow box controller) […]


Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

IKE