Arduino Controlled Grow and PC Program - Work In Progress

AdvancedNewbie

Well-Known Member
Hey everybody, first post, first ever grow. I have a simple ebb and flow setup, and everything is going great. While buying everything necessary for the grow, and having some background in controllers, programming and computers in general; when I found that 24 hour / 15 minute interval timer costs me about $20, a thermostat with 120V plug costs ~$70, a pH/PPM meter and all this stuff that didn't talk to each other and say 'hey, mix some new nutrients, and start the fan it's too hot in here!' I thought to myself, "Really???"

So I bought 2 timers, a pH pen, a pump, a rubbermaid container, a cheap plastic table and a 1000W ballast with a HPS bulb; just to get me started.

Well, all I can say is everything's great - my babies are beautiful and my setup is VERY analog and yet VERY simple. ( I like simple - but something can be made that's just as reliable and does a better job... )
Grow.jpgGrow 2.jpg

But, still - I wanted to later on upgrade my system with time, and that just means forking out the money on the control units, etc, right? WRONG.

If you've never heard of an Arduino, it's basically a C++ based development platform, but is VERY comparable to a 'PLC'.
From Wikipedia, the free encyclopedia:
"A programmable logic controller (PLC) or programmable controller is a digital computer used for automation of electromechanical processes, such as control of machinery on factory assembly lines, amusement rides, or light fixtures. PLCs are used in many industries and machines. Unlike general-purpose computers, the PLC is designed for multiple inputs and output arrangements, extended temperature ranges, immunity to electrical noise, and resistance to vibration and impact. Programs to control machine operation are typically stored in battery-backed-up or non-volatile memory."

- I'm using an Arduino Duemilanove for this project - with 5 Analog Pins and 13 digital pins - 2 of which are needed for communication
- The PC Program is coded in VB.NET

So let's compare some costs of some hardware, starting with the consumer available product first, then compared to the Arduino route (5v PLC, basically):
120V 24-hour / 15 minute timer: $24
25A SOLID STATE RELAY 4-32VDC INPUT 48-660VAC: $15

4 Timers: 4 * $24 = $96
4 Channel DC30V 10A AC250V 10A: $12

Temperature/Humidity Display: ~$15
I got 5 temperature/humidty Sensors on ebay for: $1.57 (the value from this can be used to control a 120V or up to 660VAC - thereby eliminating the cost of a $70 120V thermostat)

pH pen: ~$30
pH sensor: $20, and Adapter: $15 - a little over the price of the pen here, but does the pen log the data? Can it turn on and off anything? Tested: I got it to match the value of my pH pen +/- 0.03

Ethernet Shield for Arduino: $15

Wireless (up to ~100m): 2 for $6 (one to transmit, one to receive)

5V (control) 120V (operation) Solenoid Valves: $5 - $45 (probably best go with a reliable one)

Submersible Pump: ~$25

Yadda, yadda, yadda...

Anyways, I've loaded my Arduino up with the Firmata example sketch ( comes with arduino software = no coding for me ); although I did change the code just a little bit to get the analog I/Os working.
Next I started coding up a VB.NET that I've dubbed, "ArduinoFirmata_Lab" - originally it was "ArduinoFirmata_Grow", but I thought I might be able to use this for controlling other things later on, and didn't want the program to be associated with "growing" <--- You guys are lucky however to see the growing part associated with the project...

The control software, right now, can control all pins and get all analog raw data (0V - 5V reading computer reads as 0 - 4096 (I think) ) so the raw data gets punched though a calculation (which can be calibrated) and output anything you want (if it's a pH sensor, then use the pH calculation).

What works so far:
1) all readings from sensors (analog i/o)
2) all digital outputs (to control 5V pin off of controller, which in turn could run anything you can think of; in this case a relay to control something that is 120V or 240V or what-ever...)
3) all graphs / guages
4) all water timers (with any interval you want ---> think 15 minute water cycle is too much? Customize!)
5) light timer
6) history log - really an alarm log, I guess (pH too high, pH too low, High Humidty, Low Humidity, High Temp, Low Temp, and anything else you can think of - reservoir temp, plant temp, lumens, whatever!)

Currently working on (Busy right now - give me a week and a half :P)
1) pin configuration (add/remove sensor, relay, etc or change pin)
2) user log
3) Customizable interface ---> add a tab for each room and the associated stuff you want to control in that room. - right now you can add an image or button and move them anywhere you want and label the button anything you want it to and, instead of adding individual images, you could just take a picture of your whole room and load it as a background and just add buttons on top of that image
4) Still can't save settings / extra pages / button, image locations
5) Email Alert
6) Maybe I'll add webcam support - but there's already so many apps that already do this and probably more securely.
7) Waiting for my ethernet module and wireless modules to arrive
8) Might need to add an SD card for a log / settings - ~$15
9) I'll add wifi later when I need it (maybe a couple years down the road when I have the setup I really want - I don't want to go overkill on a simple ebb and flow setup for now; just set myself up for what I really want later...) <-- Range? Up to you really - repeaters, internet, etc....
10) Maybe a phone web interface? We'll see, a little overkill right now.

So there you have it, a look inside my brain a little bit. I'm still waiting on most of the parts, so I'll keep you guys posted as the work continues (a little busy right now). The "to-do-list" is pretty easy stuff and half programmed already - won't take long at all... The next thing I'm going to do though, is update the arduino code so the arduino does not need the PC to run, but rather use the PC to connect up to the arduino and change its settings (then you won't need to run your PC all the time) - also, while not being fed with a 9V wall adapter, it can use a 9V battery as backup power - thereby never losing its settings.

Pics:

pH Sensor and Arduino.jpgOutlet.jpg
Screenshot1.jpgScreenshot2.jpgScreenshot3.jpgScreenshot4.jpgScreenshot5.jpg
 

rmx

Member
Hey AdvancedNewbie,

That looks amazing! Major kudos on your work so far, and coming up with the idea in the first place! I dabble in programming and software development, but nothing as advanced as this. Brilliant stuff. I've not done a search, but is there anything similar out there? If not, you could be onto something here! This seems like it could be universally handy for all sorts of indoor growing, not just the mj scene. Huge potential audience out there if you were to release this as 'shareware' - I hope your idea comes to fruition, very cool! Will definitely keep an eye on this.

Great lookin' green there too ;)
 

psari

Well-Known Member
sub'd

Curious on how you'll keep the PH measurements actually in check over time etc. Should be interesting if you're willing to keep this thread up to pace with the progress.

Thanks in advance for the efforts.
 

AdvancedNewbie

Well-Known Member
Well, so far I've tested different water samples with pH up and pH down added, and compared the values to a pH pen I had bought... But I have ordered some buffered pH solution to calibrate with later on. But the sensor does seem to be agreeing with the pen. In the last screenshot, there is a calibrate column and in each cell there's a button so you can put in your formula (in a new window). I looked on the datasheet for the sensor (just googled it) and found there was a suggested formula to use when converting the raw signal value into a useable value. This is common with other sensors too, like thermistors, etc. I did however find that I needed to tweek the formula a little, but got it working pretty quick using their forumla as a general baseline.

@ rmx: I haven't found anything as cheap as this just some updates I want to straighten out first and I'll probably post the code somewhere... But I did find a program (and hardware) called, 'Growtronix'... It's a pretty similar design concept as what I'm buidling, but I'm trying to stay free and open source... I think people should have the right to add a feature if they think of something that's missing... and that missing thing is usually different for every user.
 

psari

Well-Known Member
... but I'm trying to stay free and open source... I think people should have the right to add a feature if they think of something that's missing... and that missing thing is usually different for every user.
On the PH its more sensor drift over time. Obviously this isn't a leave it for 60 days approach or anything. Just figuring it will suffer the same slings and arrows all the pens do with needing calibration/drifting/etc.

And of course, I cant double rep you for this alone. I'll just make sure that when I can I do. I spend time on that side of the fence as well so I'm really looking forward to this. Especially since I hate origin work. :)

"
  • You must spread some Reputation around before giving it to AdvancedNewbie again.




 

AdvancedNewbie

Well-Known Member
If you were to leave for 60 days, you could re-mix nutes automatically and compare the pH value to what it usually is after a remix? That would let you know approx. how much the pH value is off (if your concerned while monitoring remotely), other than that calibration is always a necessity. - No real plans to have a robotic arm or something dip into calibration pH buffered solution or anything like that though....

As I posted on another thread:
View attachment 2124524

Edit: You would need a one way valve comming off that pump so when the pump turns off the nutes don't backflush through the pump.
 

The Scooby Master

Active Member
Sweet. I was just looking through the forums to see if anyone had experimented with this in the past. It is nice to come across an active thread that is just beginning.

In building a new grow room, I was thinking about putting together an arduino based data collection system and using a Rainbird sprinkler controller to control hvac. But now I am thinking I will build exactly what you did. Consider me subscribed and when you are ready for "beta-testing" keep me in mind.
 

AdvancedNewbie

Well-Known Member
You bet Scoob', I just finished the e-mail alert function, cleaned up the 'design-your-own-interface' code up a little bit too, and everything seems to be working great. What kind of arduino do you have? I'm interested to see if the code's compatible with more than my Duemilanove.

I'm hoping to release a beta here pretty quick.
 

The Scooby Master

Active Member
You bet Scoob', I just finished the e-mail alert function, cleaned up the 'design-your-own-interface' code up a little bit too, and everything seems to be working great. What kind of arduino do you have? I'm interested to see if the code's compatible with more than my Duemilanove.

I'm hoping to release a beta here pretty quick.
Havent bought anything yet. What would you recommend and from where?
 

AdvancedNewbie

Well-Known Member
I just received some relays off eBay, one rated for 30A 240VAC that I was going to use to control two 120V outlets (should be good for up to 2 ballasts - approx 2 x 8.5A) The problem with these relays, I've heard, is that the voltage spike when the light turns on can cause the contact to stick in the relay like a tack-weld so to avoid this from happening you need a relay with zero voltage turn-on, where it waits until the AC wave goes to zero, then switches. So I have ordered another relay that's not so 'cheap' but still fairly inexpensive. Just look for a solid state relay with zero voltage turn-on that has an switching voltage in the range of 5v... Mine has an 4-32VDC input, 48-660VAC 25A output for $16. I also bought a 4-channel relay module as well - this was also bought on eBay; just look up, "Arduino relay" and you'll see the boards. Keep in mind though, these are fairly cheap relays, but should work fine for things like pumps, oscillating fans, etc. However, the lights and exhaust fans might need a zero voltage turn on depending on the initial spike in voltage. Keep in mind you can wire up more that 1 plug to 1 relay, as long as you keep your relay's capacity in mind. pH sensor was off eBay "ph replacement probe" <--- they're blue from Hong Kong... hah - cheap, but what the hell, we'll see how it works, my tests in solution were pretty good. The connection from the pH sensor has a BNC plug which requires a module to interface with the arduino, I got the Phidget ORP/pH Adapter from some 'robot' store online a couple years back, so I couldn't tell you where from exactly. All of the electrical parts including the plastic outlet box was bought at home depot. Make sure you get the right electrical cable for the job, and keep all plugs and cables within their limitations. I bought regular wall electrical cable rated up to 300V - but I'm only running 120V - everything is three plug with ground. Temperature/Humidity sensors are Hong Kong specials too - eBay... hah, what the hell, with electronics stuff their eBay stuff usually works... My search was "Temperature Humidity sensor". I haven't messed around with solenoid valves and doubt I will, but you could make modifications to the program to auto-mix nutrients or anything else you wanted to do... Just a matter of setting up a sequence of events with 'stopwatches'...

EDIT: I bought my Arduino off SparkFun a few years back, but I wouldn't necessarily recommend SparkFun; I find their prices a little high. I'm developing this project for my Arduino Duemilanove, so I guess you could search for it somewhere, but eventually I'd like to maybe get a Netduino or something similar, but I'll stick to what I have I guess.

Anyways, alpha 6 is up and I changed some stuff around, a bit easier to understand the code now - I think... Still working on it.
 
I've been planning on setting up a Arduino controlled grow, but haven't really gotten started yet. So need less to say I was very excited to see that you are working on doing the same thing. I'd like to be able to control; lights, ebb and flow pumps, PH/PPM measurements (and eventually adjustment via dosing pumps), temperature measurement of room/reservoir/ballasts/etc, and control of room/reservoir temperature, smoke detection and fire suppression control, entry to the room via RFID tag and linear actuator, and the list goes on. I've got a little bit of experience with arduino, from building my Reprap 3D printer, but not a whole lot. My growing experience is somewhat extensive as I've played a major role in the setup and success of two indoor grows. I've got a good grip on what needs to be measured/controlled and therefore definitely see the advantage in using an arduino to handle these tasks.

Firmata is something completely new to me and I'm having a bit of trouble figuring out how to get your program to run. I've downloaded the files from your Sourceforge site, but I can't seem to figure out how to get the firmata application to run. I looked thoroughly for an executable file to run, but found nothing. What do I need to do to get the program to run?

I would like to help contribute to the project in any way possible. My first contribution will be trying to run in on an Arduino Mega 2560 as I ordered one of those off ebay for $31 and it should be here early next week.
 

AdvancedNewbie

Well-Known Member
The program is coded in VB.NET 2008 - if you downloaded the code and want to change it you'll need VB.NET 2008; I have Visual Studio 2008. The zip that's available for download also includes a folder called 'Arduino Source' inside that folder is a file called, "StandardFirmata_Modified_ALL.ino" That file, you'll have to open with the Arduino Development Environment. (http://arduino.cc/hu/Main/Software). From in the Arduino IDE program, you'll have to upload the modified firmata code onto the arduino. As for all the ideas you have in mind are very much possible; I have a RFID reader right now that I haven't used in a while and I found it to be a little bit a work to get it working... But none the less, it worked. I have also seen some cheap magnetic door locks good for up to 1200lbs, and ones stronger than that even, and they require 5v to activate them. But if you know of any cheap linear actuator style locks, I think I'd be more interested in those as they don't rely on magnets. (even though when the power is off to a magnetic door lock they stay locked) The RFID reader I got was off eBay, "Arduino RFID module Kit 13.56 Mhz with Tags" I had no trouble modifying their sample code to get to work. I have not messed around with it in respect to getting it to talk through the Arduino and then to the PC, but it should be possible. The code would have to be re-written for the arduino to accomidate the reader, as (if I recall correctly) the RFID reader uses a UART style transfer method and I can't really picture that working without rewriting the arduino code... Hmm, but you got me thinking. I was thinking it would be easier to use your phone to unlock as this could be code on the PC code, but it would suck to be locked out of your room because your phone's not charged, or the Internet > PC > Arduino > Lock 'hops' didn't work out somewhere along the way... If I knew the mega's were that cheap on eBay I probably would have waited for on of those to arrive to play with it instead. Please let me know if you're able to get up and running. I'd like to support all Arduinos. I might also incorporate shift registers to get more outputs, but this would take some rewriting of arduino code too.

Edit: If you want to try out the compiled binary, you'll have to dig deep... In the zip: ArduinoFirmataVBExtended > bin > Release > ArduinoFirmataVBLab.exe
 
This looks like a cool app you've got going here. I've got a copy of Visual Studio 2008 Professional Edition and my Dad is a wiz with programing of all sorts, so he should be able to offer some help with this project. Only problem is that Dad knows very little about Arduino or electronics in general, he's purely a software guy. Myself on the other hand, I'm a hardware guy so in therory we should make a great team.

I also found the Arduino sketch, but have yet to upload it. The Arduino Mega 2560 (compatible, A.K.A. Knock-off) arrived in the mail today. Here's the link to the one that I bought off Ebay, the seller ID is wadirect, they didn't have the cheapest price @ $31.90, but they were the closest seller to my house, I ordered it on Friday and it arrived Monday, so it was definitely worth the extra $6 not to have to wait for one to be shipped from China.

I started playing with it a little bit and got some of my Dallas (DS18B20) temperature sensors to work with the example code provided with the "Dallas Temperature Control Library".

After doing some research today, I'm not convinced that FirmataVB is compatible with the Mega 2560. Luckily I've got an old Duemilanove laying around that will definitely be compatible with firmata and the program the you've written. Although I am going to dig a little bit deeper and test to see if I can get firmata to work with the new Mega 2560.

Do you think that I will be able to get the DS18B20 (One-wire) Temp sensors to work with Arduino Firmata VB Lab?

I've also been looking at getting an Atlas Scientific pH kit which communicates with the Arduino via the UART (RS232 Rx/Tx Pins) and seams like it would be much easier to calibrate than the Phidgets unit, because it has all the calibration features built in and you just send commands to it via the serial monitor. Atlas Scientific also makes a Conductivity Kit which measures E.C., T.D.S., and Salinity. Which could be used to measure PPM of the nutrients. The conductivity kit also communicates via UART (RS232). Granted these are probably not the cheapest solution to measuring PH and PPM, but it seams like they might be the easiest to setup, configure, and calibrate.

Do you think that it will be possible to get these Atlas Scientific sensors to work with Arduino Firmata VB Lab, without too much trouble? One issue that I see might be a problem is that the Duemilanove has only one set of Rx/Tx pins (the Mega 2560 has 3 sets). I'm not sure if it is possible to assign some of the other digital pins to function as UART (RS232 Rx/Tx) or if you are stuck with just the two digital pins 0 and 1, labeled Rx and Tx.
 

AdvancedNewbie

Well-Known Member
I looked up some info on those one-wire devices. It seems that each one has an address, and multiple sensors can be ran with having one master and the rest run as slave. I found some example code on the arduino website (http://arduino.cc/playground/Learning/OneWire). I don't think I'll be doing this, just because everything is setup for a 3 wire right now and there are enough pins on the Arduino to not require assigning more addresses. Keep in mind though that with a three wire system you can run a everything off the same ground and everything off the same 5V source (check current draw to make sure you don't exceed whatever your Arduino is rate for) but have each output signal go to a serperate pin on the Arduino. It would be neat if you could search for all the sensors by searching through the addresses for responses though. I might incorporate shift registers a little later which increases the total number of outputs and, if I'm not mistaken, every sensor gets its own address as well. (The three wire sensors have to be cheaper as they are just the sensing circuit minus the send/recieve/multiple address circuit that is required to run them). Maybe there is something else I do not know about them... After getting the program GUI a little nicer, I think I'm going to end up changing the Arduino code to do all the timers and alerts for me so the Arduino can become independent and think on its own. I would like my program to 'come up' with the new Arduino code, then upload the code to the Arduino and still have it controllable through the PC (but not necessary). But that's a little later. I like those Atlas-Scientific sensors though; they look pretty professional. Conductivity is next for me; everything on that site looks like a BNC connector; those BNC breakout boards are cheap and work good (that's what I'm using for my pH probe). One of these days it'll be my random $100 purchase of the month.

Update: Alpha 7 now up
What works so far:
1) All Readings from sensors (analog i/o)
2) All Digital Outputs (to control 5V pin off of controller, which in turn could run anything you can think of; in this case a relay to control something that is 120V or 240V or what-ever...)
3) All Graphs / Gauges
4) All Water timers (with any interval you want ---> think 15 minute water cycle is too much? Customize!)
5) Light Timer
6) Alarm Log (pH too high, pH too low, High Humidty, Low Humidity, High Temp, Low Temp, and anything else you can think of - reservoir temp, plant temp, lumens, whatever!)
7) Pin Configuration (add/remove sensor, relay, etc or change pin) - including device calibration formula - ex: 1.728x^2 + 0.85x + 10 --> program subs in raw analog value for x
8) Email Alert
9) Customizable Interface ---> add a tab for each room and the associated stuff you want to control in that room. - can add Button, Label, StatusLabel, Gauge, Graph, Image
10) Can Import a new tab now, working on the export ---> 4/25/2010 (save a page with gauges, buttons, etc and open later, or by default)

11) Relay/Interface Box done - might add some acrylic to make it look special

Currently working on

1) User log
2) Maybe I'll add webcam support - but there's already so many apps that already do this and probably more securely.
3) Waiting for my ethernet module and wireless modules to arrive
4) Might need to add an SD card for a log / settings - ~$15
5) I'll add wifi later when I need it
6) Maybe a smart-phone web interface? We'll see, a little overkill right now.
7) Independent Arduino Code
8) Manage Events (Add,Remove,Create)?
9) Export Tab - save the layout of all controls
 

AdvancedNewbie

Well-Known Member
Alpha 9 is now available for download

Seems like we're getting pretty close to the beta stages here now, all timers are working great;
You can choose On Time / Off Time Timer, On Time / For Duration Timer (and set which days each timer is active)
There are setpoints now, if you setup a temperature sensor for example, then you you could set 'if the temperature goes above 27 degrees Celsius, turn on a pin' (which could be a fan)
All alerts with email are working - they are based on StatusLabels MinValue/MaxValue.
Importing Tabs is easy, and everything is stored in an Access Database which can be 'hacked' at will. (There's an included example for Ebb and Flow)

https://sourceforge.net/projects/arduinovblab/

1.jpg2.jpg3.jpg4.jpg5.jpg6.jpg7.jpg
 

AdvancedNewbie

Well-Known Member
Do you think that I will be able to get the DS18B20 (One-wire) Temp sensors to work with Arduino Firmata VB Lab?

I've also been looking at getting an Atlas Scientific pH kit which communicates with the Arduino via the UART (RS232 Rx/Tx Pins) and seams like it would be much easier to calibrate than the Phidgets unit, because it has all the calibration features built in and you just send commands to it via the serial monitor. Atlas Scientific also makes a Conductivity Kit which measures E.C., T.D.S., and Salinity. Which could be used to measure PPM of the nutrients. The conductivity kit also communicates via UART (RS232). Granted these are probably not the cheapest solution to measuring PH and PPM, but it seams like they might be the easiest to setup, configure, and calibrate.

Do you think that it will be possible to get these Atlas Scientific sensors to work with Arduino Firmata VB Lab, without too much trouble? One issue that I see might be a problem is that the Duemilanove has only one set of Rx/Tx pins (the Mega 2560 has 3 sets). I'm not sure if it is possible to assign some of the other digital pins to function as UART (RS232 Rx/Tx) or if you are stuck with just the two digital pins 0 and 1, labeled Rx and Tx.
I just found some information regarding UART on any pin, one wire addresses, and shift register addresses, all is possible - but you have to designate your pins in the arduino code.
 
Top