# Hunter X's Arduino Whole Tank Controller (52K Warning)



## NYCaqua

Very well done. Its nice to see hobbyist use dosing pumps for planted tanks. Nice woodwork as well


----------



## HunterX

NYCaqua said:


> Very well done. Its nice to see hobbyist use dosing pumps for planted tanks. Nice woodwork as well


Thank you! I can't wait to get it home and see how it performs!


----------



## scapegoat

this is great! can we get a parts list, schematics?

I've been wanting to build one with one of the raspberry pi's I have here.

I'm rather new to electronics, so i've been having trouble figuring out what components to purchase. But, I'd be surprised if we don't have the same pumps.

gorgeous work all around.


----------



## Fluffles

Agree with scapegoat above. Can we get a parts list, schematics, and maybe where you ordered the parts from?
This is an awesome project and I'm looking at building something like this myself.


----------



## mistergreen

Nice work! Makes me want to get back to finishing up an aquarium web controller. I'm starting to see limitations though, so the Rasberry PI might be a route.


----------



## paronaram

Fantastic!!!
Very nice, clean setup!


----------



## HunterX

scapegoat said:


> this is great! can we get a parts list, schematics?
> 
> I've been wanting to build one with one of the raspberry pi's I have here.
> 
> I'm rather new to electronics, so i've been having trouble figuring out what components to purchase. But, I'd be surprised if we don't have the same pumps.
> 
> gorgeous work all around.


 
Thank you everyone! I should be able to do a parts list realitively easy. I think I have all the packing list that came with the parts. I schematic may be a little harder....



mistergreen said:


> Nice work! Makes me want to get back to finishing up an aquarium web controller. I'm starting to see limitations though, so the Rasberry PI might be a route.


I was looking at adding WEB Control to mine as well. I'm curious as to what limitations you see. Thank you in advance for your reply!


----------



## magnum

That's impressive, I've been brushing up on my programming because I have an Arduino on the way and I plan to build my own tank controller. I'm sure I'll find quite a bit of inspiration from this thread.


----------



## HunterX

magnum said:


> That's impressive, I've been brushing up on my programming because I have an Arduino on the way and I plan to build my own tank controller. I'm sure I'll find quite a bit of inspiration from this thread.


Thanks for the kind words. I wanted to share it for just that reason. Let me know if you have any questions.


----------



## magnum

HunterX said:


> Thanks for the kind words. I wanted to share it for just that reason. Let me know if you have any questions.


Thanks I'm sure I will. It'll take some time however I plan on testing each feature independently before I put it all together. It's been even longer since I messed with hardware than coding. 

The primary feature I want is to automate a small water change daily. I already wrote the basics for my own random lightning storm. We'll see what happens I hope to have at least 6-7 other features. I'll probably need a mega board in the future haha.


----------



## HunterX

magnum said:


> Thanks I'm sure I will. It'll take some time however I plan on testing each feature independently before I put it all together. It's been even longer since I messed with hardware than coding.
> 
> The primary feature I want is to automate a small water change daily. I already wrote the basics for my own random lightning storm. We'll see what happens I hope to have at least 6-7 other features. I'll probably need a mega board in the future haha.


Automating the water change should be pretty easy. I still have to write the code for my lighting. I'd love to see your code  HINT HINT. I would highly recommend the mega. Specially if you want to control the whole tank. I'm working on my parts list now so should have that up in a few hours.


----------



## HunterX

See Attached PDF for Parts List.


----------



## scapegoat

HunterX said:


> See Attached PDF for Parts List.


Man you are fantastic!

I've been really debating between getting an neptune apex or rolling my own solution. I've got two raspberry pi's here just waiting to be abused. I've been trying to decide between going the respectable, but obvious, route of using python. Or taking the plunge with node.js, well more specifically meteor.js; which is a web sockets based library that uses node.

I'm intending on a fully web based GUI for the controller so i'm really thinking i'd lean towards meteor, with one of the handful of node gpio libraries. meteor js code is shared by the front and back end, with the ability to have front/back specific code that isn't seen.

thanks for your shopping list. hardware is a bit confusing for me as I've really no experience there. :thumbsup:


----------



## HunterX

scapegoat said:


> Man you are fantastic!
> 
> I've been really debating between getting an neptune apex or rolling my own solution. I've got two raspberry pi's here just waiting to be abused. I've been trying to decide between going the respectable, but obvious, route of using python. Or taking the plunge with node.js, well more specifically meteor.js; which is a web sockets based library that uses node.
> 
> I'm intending on a fully web based GUI for the controller so i'm really thinking i'd lean towards meteor, with one of the handful of node gpio libraries. meteor js code is shared by the front and back end, with the ability to have front/back specific code that isn't seen.
> 
> thanks for your shopping list. hardware is a bit confusing for me as I've really no experience there. :thumbsup:


No problem at all. If I can do anything to help let me know.


----------



## magnum

HunterX said:


> Automating the water change should be pretty easy. I still have to write the code for my lighting. I'd love to see your code  HINT HINT. I would highly recommend the mega. Specially if you want to control the whole tank. I'm working on my parts list now so should have that up in a few hours.


I'll be looking forward to the mega, but until then I get to enjoy finding individual projects that I'll put in the final controller. Once the code is gone over with a fine toothed comb for efficient and bugs, I'll be sure to post it around the forum. (Surely to continue to be hacked up by the professionals haha)


----------



## paronaram

HunterX said:


> See Attached PDF for Parts List.


HunterX, thanks for the parts list.
Are you avoiding fleabay fundamentally? Or whatever store comes first on Internet you got it from them?
Price of your list can be slashed in half if not more, if the parts are purchased from electronic parts wholesalers from fleabay. Just my 5c :smile:
Unless money is not an issue 

Aram


----------



## HunterX

paronaram said:


> HunterX, thanks for the parts list.
> Are you avoiding fleabay fundamentally? Or whatever store comes first on Internet you got it from them?
> Price of your list can be slashed in half if not more, if the parts are purchased from electronic parts wholesalers from fleabay. Just my 5c :smile:
> Unless money is not an issue
> 
> Aram


I'm currently deployed to Kuwait. As a result I had to go with supplies that I knew would ship to an APO address before I purchased an item. Let me reassure you, price is always an issue! LOL Thanks for looking.


----------



## HunterX

magnum said:


> I'll be looking forward to the mega, but until then I get to enjoy finding individual projects that I'll put in the final controller. Once the code is gone over with a fine toothed comb for efficient and bugs, I'll be sure to post it around the forum. (Surely to continue to be hacked up by the professionals haha)


 I know what you mean. Notice I haven't posted my code on the forum. I don't want to be embarrassed LOL!


----------



## scapegoat

HunterX said:


> I know what you mean. Notice I haven't posted my code on the forum. I don't want to be embarrassed LOL!


don't be embarrassed.

load it up on github and let people help you make it better.

some of the best pieces of software out there are written by one or two people, bug checked and updated by thousands. If we could actually get a bunch of programmers united on a single project then I'm sure we could come up with something that rivals any of the commercial examples.

the biggest problem we have with the DIY aquarium controller right now is folks not sharing what they've done, not working together, or even letting their ego get in the way of collaboration.

I've actually purchased a domain name in order to share some DIY/open sourced aquarium stuff. but haven't had the time to devote to "wiring it up" and getting it going. it was meant to be more of an open wiki so folks can add their own content in.

I'd be more inclined if I could get a small group of like minded folks invested into the idea and willing to spend some time helping to get it rolling.


----------



## salman

scapegoat said:


> don't be embarrassed.
> 
> load it up on github and let people help you make it better.
> 
> some of the best pieces of software out there are written by one or two people, bug checked and updated by thousands. If we could actually get a bunch of programmers united on a single project then I'm sure we could come up with something that rivals any of the commercial examples.
> 
> the biggest problem we have with the DIY aquarium controller right now is folks not sharing what they've done, not working together, or even letting their ego get in the way of collaboration.
> 
> I've actually purchased a domain name in order to share some DIY/open sourced aquarium stuff. but haven't had the time to devote to "wiring it up" and getting it going. it was meant to be more of an open wiki so folks can add their own content in.
> 
> I'd be more inclined if I could get a small group of like minded folks invested into the idea and willing to spend some time helping to get it rolling.


Very well said sir. I do have lot of hardware and some software experience so i'll be sure to help any way i can. Haven't done any project since i finished college(approx. 4 years) lol.


----------



## HunterX

scapegoat said:


> don't be embarrassed.
> 
> load it up on github and let people help you make it better.
> 
> some of the best pieces of software out there are written by one or two people, bug checked and updated by thousands. If we could actually get a bunch of programmers united on a single project then I'm sure we could come up with something that rivals any of the commercial examples.
> 
> the biggest problem we have with the DIY aquarium controller right now is folks not sharing what they've done, not working together, or even letting their ego get in the way of collaboration.
> 
> I've actually purchased a domain name in order to share some DIY/open sourced aquarium stuff. but haven't had the time to devote to "wiring it up" and getting it going. it was meant to be more of an open wiki so folks can add their own content in.
> 
> I'd be more inclined if I could get a small group of like minded folks invested into the idea and willing to spend some time helping to get it rolling.


I will end up posting it. I have a couple of bugs to work out before I do though. I hope a few people take interest in it and help me develop it and make it better! 

I did get my AC to DC converter installed last night. It works like a champ. I'm at work now but when I get off I will post some pictures of it!


----------



## paronaram

HunterX said:


> I'm currently deployed to Kuwait. As a result I had to go with supplies that I knew would ship to an APO address before I purchased an item. Let me reassure you, price is always an issue! LOL Thanks for looking.


Darrin, great kudos for pulling such a project by being in Kuwait!
Man I never knew that this can be possible there :confused1: 
Again, awesome job!!!

Aram


----------



## HunterX

paronaram said:


> Darrin, great kudos for pulling such a project by being in Kuwait!
> Man I never knew that this can be possible there :confused1:
> Again, awesome job!!!
> 
> Aram


Thank you for the kind compliment. Lucky for me it gave me something to do during my down time besides miss my life back home! Come on MAY!


----------



## shift

You did a beautiful job! It looks like you took my auto doser to a while new level


----------



## HunterX

shift said:


> You did a beautiful job! It looks like you took my auto doser to a while new level


Thanks Shift. I appreciate that!


----------



## HunterX

My AC to DC Convert finally came in. (Don't mind the sloppy wire job. I haven't cleaned that up yet). It works like a charm. It holds @ 12.05 volts on the money. The DC to DC converters hold on their set voltage perfectly as well. I'm really happy how the power management has turned out. I'm now able to plug the box into the wall (110 or 220V) and it runs just as planned. Now it's time to start working on the LED Light controls.


----------



## scapegoat

are each of the dc to dc step up/down and power FET switch, for the motors, all attached to the ac to dc converter?

which ac to dc converter did you get?

I just noticed in your previous pictures that those set up/down units weren't even powered, so you've been waiting for the converter right?


----------



## HunterX

scapegoat said:


> are each of the dc to dc step up/down and power FET switch, for the motors, all attached to the ac to dc converter?
> 
> which ac to dc converter did you get?
> 
> I just noticed in your previous pictures that those set up/down units weren't even powered, so you've been waiting for the converter right?


The AC to DC converter does supply all of the DC current for the box. 12v straight from it to the power FET. Then from the converter to the step up/down, in my case step down, to the Arduino (9v), the Relay Board (5v) and the Sensor Shield (5v). 

I got the AC to DC converter from www.jameco.com. This one is the same specs as mine. I couldn't find the one I got. 

http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_323300_-1

Yea I was waiting for the converter. Its all running now!


----------



## Fluffles

Wow, this is looking great!
Thanks so much for the parts list. I've had an Arduino Mega controlling my LED lights for about a year now and wanted to expand it to a complete aquarium controller but never knew how to approach this. Your thread has given me a clear path on how to get things started.
I actually ordered most of the components already and it looks like I'll be building a clone of your project. Thanks again!

Btw, I see that your dosing pumps and fan are connected to the 4 channel MOSFET board. Did you consider placing a diode in parallel to each pump/fan to protect your transistors from flyback?
http://en.wikipedia.org/wiki/Flyback_diode
I think Shift's dosing pump project has some of these installed, but it seems like the transistors are pretty beefy though so it might not be necessary at all. Maybe someone here with electrical experience might be able to offer some advice.


----------



## benjaf

> Btw, I see that your dosing pumps and fan are connected to the 4 channel MOSFET board. Did you consider placing a diode in parallel to each pump/fan to protect your transistors from flyback?
> http://en.wikipedia.org/wiki/Flyback_diode
> I think Shift's dosing pump project has some of these installed, but it seems like the transistors are pretty beefy though so it might not be necessary at all. Maybe someone here with electrical experience might be able to offer some advice.


Yes, there should be a flyback diode across each of the motors. They are not included in most MOSFET boards, but when driving motors you should always use one to protect the rest of the components.


----------



## HunterX

benjaf said:


> Yes, there should be a flyback diode across each of the motors. They are not included in most MOSFET boards, but when driving motors you should always use one to protect the rest of the components.


Even though it's OPTO-ISOLATED? There shouldn't be a need for the diode?


----------



## Fluffles

From what I understand, the opto-isolation will protect the Arduino side of things so the Arduino will be fine, but there is still a possibility that the opto-isolator or the IRF540 MOSFET might be damaged by flyback current/voltage. Looking at the circuit for this board, I'm not entirely sure how it would react immediately after the MOSFET cuts power to the motor, but having a flyback diode would be the safest way to go. Again, I'm not very experienced with this so there is still the possibility that the MOSFETS this board uses are beefy enough that you won't need any diodes.

I'm more concerned about the fan than the 3 dosing pumps. I think the pumps don't pull much current, but a fan that size probably runs around 12V @ 1A. Immediately after shutting the fan off, you might see very large voltage changes on this side or the circuit.


----------



## benjaf

While not quite as important, I would still include them to protect the MOSFETs from the voltage spike. However - since the pump motors are not that large and aren't exactly 'freewheeling' when turned off, you *may* be fine without diodes. 
It is simply a good idea to include them any time you drive motors or solenoids unless you know for sure that the reverse voltage will cause no damage. :thumbsup:


----------



## bigd603

benjaf said:


> While not quite as important, I would still include them to protect the MOSFETs from the voltage spike. However - since the pump motors are not that large and aren't exactly 'freewheeling' when turned off, you *may* be fine without diodes.
> It is simply a good idea to include them any time you drive motors or solenoids unless you know for sure that the reverse voltage will cause no damage. :thumbsup:


Especially considering how cheap diodes are, its definitely well worth the dollar or two to protect your investment. 

Sent from my Galaxy Nexus using Tapatalk


----------



## benjaf

Fluffles said:


> I'm more concerned about the fan than the 3 dosing pumps. I think the pumps don't pull much current, but a fan that size probably runs around 12V @ 1A. Immediately after shutting the fan off, you might see very large voltage changes on this side or the circuit.


Completely forgot about the fan - flyback diodes all around then!

And as *bigd* points out - they are a LOT cheaper than the 4-channel MOSFET board.


----------



## HunterX

Good input everyone. I looked at the schematic for the board as well. Why the diodes are not included in the design is beyond me. I already have the diodes and will incorporate them into my plans. Thanks everyone!


----------



## pianofish

Man, this thread is golden. I've been looking at doing exactly what you are doing with my tank. I've been looking at getting the arduino duemilanove which is the next step up after the mega. I eventually plan on doing an actual LCD display on mine, with options to edit the dosing schedule via toggles and buttons.

But for now, my main goals are basically, auto top off, water changes, DIY LEd ligthing, along with ph probes, and temp probes. 

How long did it take you to familiarize yourself with the necessary components?
I'm a sophomore in Elec. Eng, lots of background in coding, but less so with the hardware.

Looking forward to where this thread goes,
Joshua


----------



## HunterX

pianofish said:


> Man, this thread is golden. I've been looking at doing exactly what you are doing with my tank. I've been looking at getting the arduino duemilanove which is the next step up after the mega. I eventually plan on doing an actual LCD display on mine, with options to edit the dosing schedule via toggles and buttons.
> 
> But for now, my main goals are basically, auto top off, water changes, DIY LEd ligthing, along with ph probes, and temp probes.
> 
> How long did it take you to familiarize yourself with the necessary components?
> I'm a sophomore in Elec. Eng, lots of background in coding, but less so with the hardware.
> 
> Looking forward to where this thread goes,
> Joshua


To be honest, with all of the information on the web, it doesn't take long to become familiar with any of the components. I stumbled across most of it while studying other components for my build. I would like to add ph probes as well but I'm slowly running out of inputs/outputs because of the buttons and LEDs. Having the buttons makes the programming much easier. But one solution would be to use a touch screen LCD and build "buttons" within the touch screen programming. I'm not at that level yet. My design does have an LCD display but it is not a touch screen. It’s the 20x4.
Another added benefit is that my code is only 19,000 bytes. So it's relatively small compared to some of the other full tank codes. Granted, I haven't added the LED code yet. I expect it to almost double in size when I do that.


----------



## bigd603

pianofish said:


> Man, this thread is golden. I've been looking at doing exactly what you are doing with my tank. I've been looking at getting the arduino duemilanove which is the next step up after the mega. I eventually plan on doing an actual LCD display on mine, with options to edit the dosing schedule via toggles and buttons.
> 
> But for now, my main goals are basically, auto top off, water changes, DIY LEd ligthing, along with ph probes, and temp probes.
> 
> How long did it take you to familiarize yourself with the necessary components?
> I'm a sophomore in Elec. Eng, lots of background in coding, but less so with the hardware.
> 
> Looking forward to where this thread goes,
> Joshua


Pianofish, if you're not already familiar with it, try googling Jarduino. Its an Arduino aquarium controller that uses a 3.2" LCD touchscreen. It was made for reef tanks, but its a great starting place and allows you to see what's involved in adding the LCD. 

Hunter, I didn't say it before but let me go ahead and say great work on this. This thread will really help a lot of us out, even those already experienced with Arduino. Next logical step, get that thing connected to the web. I found a service called Xively ( www.vively.com ) that allows you to easily track and graph pretty much any data point. Super easy to insert the code, they even provide you with the necessary Arduino sketch, then it tracks anything online. I don't believe you can control anything remotely, but you can have the system send you alerts when it gets to certain conditions (temp too high/low, etc). Really neat service and they do it free. 

Sent from my Galaxy Nexus using Tapatalk


----------



## HunterX

bigd603 said:


> Pianofish, if you're not already familiar with it, try googling Jarduino. Its an Arduino aquarium controller that uses a 3.2" LCD touchscreen. It was made for reef tanks, but its a great starting place and allows you to see what's involved in adding the LCD.
> 
> Hunter, I didn't say it before but let me go ahead and say great work on this. This thread will really help a lot of us out, even those already experienced with Arduino. Next logical step, get that thing connected to the web. I found a service called Xively ( www.vively.com ) that allows you to easily track and graph pretty much any data point. Super easy to insert the code, they even provide you with the necessary Arduino sketch, then it tracks anything online. I don't believe you can control anything remotely, but you can have the system send you alerts when it gets to certain conditions (temp too high/low, etc). Really neat service and they do it free.
> 
> Sent from my Galaxy Nexus using Tapatalk


 BigD,

I defiantly want to add the ability for the Arduino to report to the NET. My only issue right now is that I don't have an RJ45 internet connection close to my controller and the wifi boards are a bit pricy yet. If the come down some, I will defiantly add that to it. 

I'm still going to check out the hosting service you were talking about. It sounds perfect.. Thanks for your input!


----------



## HunterX

Fluffles said:


> Wow, this is looking great!
> Thanks so much for the parts list. I've had an Arduino Mega controlling my LED lights for about a year now and wanted to expand it to a complete aquarium controller but never knew how to approach this. Your thread has given me a clear path on how to get things started.
> I actually ordered most of the components already and it looks like I'll be building a clone of your project. Thanks again!
> 
> Btw, I see that your dosing pumps and fan are connected to the 4 channel MOSFET board. Did you consider placing a diode in parallel to each pump/fan to protect your transistors from flyback?
> http://en.wikipedia.org/wiki/Flyback_diode
> I think Shift's dosing pump project has some of these installed, but it seems like the transistors are pretty beefy though so it might not be necessary at all. Maybe someone here with electrical experience might be able to offer some advice.


 As I got pulled into the diode conversation I didn't thank for your kind comment. Thank you!!  Please feel free to use any of the design you would like. I only ask in return to post anything you come up with so we all can share and better what we have. Thanks again!

Question? You mentioned you use the MEGA to control your LEDs already? Do you do any fading or just off and on?


----------



## pianofish

Do any of you use any type of surge protection for your system. Further more, would it be possible to add an uniteruptable power supply to this setup? Set it up so that in the event of a power failure, a power switch with an air pump would oxegenate sump filter material and the tank. I guess you would need a dc to ac converter as well... 

I love EE so many possibilities lol.


----------



## benjaf

*Hunter*
Never added my compliments! It's a beautiful build, really looking forward to see it working. And I can't wait to see your light unit and code. If you want storms and clouds I think reef forums are a good bet - it seems they are more into that stuff  I have been too lazy to write that sort of fancy stuff myself!


----------



## bigd603

HunterX said:


> BigD,
> 
> I defiantly want to add the ability for the Arduino to report to the NET. My only issue right now is that I don't have an RJ45 internet connection close to my controller and the wifi boards are a bit pricy yet. If the come down some, I will defiantly add that to it.
> 
> I'm still going to check out the hosting service you were talking about. It sounds perfect.. Thanks for your input!


Check this out: 
 http://www.newegg.com/Product/Product.aspx?Item=N82E16833704134 

Its a tiny WiFi router, smaller than a credit card, that will run in client mode. Basically its a WiFi shield, but its only $25 and it will easily fit into your box. I've seen a lot of people have great success connecting these to their arduinos at a fraction of the cost of a WiFi shield. I'm gonna pick one up in the next couple days and play around with it. I'll let you know what I think. 

Sent from my Galaxy Nexus using Tapatalk


----------



## HunterX

pianofish said:


> Do any of you use any type of surge protection for your system. Further more, would it be possible to add an uniteruptable power supply to this setup? Set it up so that in the event of a power failure, a power switch with an air pump would oxegenate sump filter material and the tank. I guess you would need a dc to ac converter as well...
> 
> I love EE so many possibilities lol.


Yea I was thinking about doing something along those lines but in the 3 or 4 years I have had my tanks up and running, I have never had a power outage. Because of that, it really isn't a priority for me. A surge protector is always a good idea. I do also use a line conditioner on my box in order to keep the signal clean.



benjaf said:


> *Hunter*
> Never added my compliments! It's a beautiful build, really looking forward to see it working. And I can't wait to see your light unit and code. If you want storms and clouds I think reef forums are a good bet - it seems they are more into that stuff  I have been too lazy to write that sort of fancy stuff myself!


Thank you! I have had it running without anything connected to it for the last couple of days to run the schedules through the paces and to make sure nothing funny happens. So far so good! 

I do want to have the storms and what not during my light cycle but I have a lot of programming to do first. Thanks for your input. 



bigd603 said:


> Check this out:
> http://www.newegg.com/Product/Product.aspx?Item=N82E16833704134
> 
> Its a tiny WiFi router, smaller than a credit card, that will run in client mode. Basically its a WiFi shield, but its only $25 and it will easily fit into your box. I've seen a lot of people have great success connecting these to their arduinos at a fraction of the cost of a WiFi shield. I'm gonna pick one up in the next couple days and play around with it. I'll let you know what I think.
> 
> Sent from my Galaxy Nexus using Tapatalk


Please do! If you can get that to work I'm in. It was actually $19 today!

Keep all of the ideas comming!


----------



## Fluffles

HunterX said:


> I only ask in return to post anything you come up with so we all can share and better what we have. Thanks again!


That's a deal!



HunterX said:


> Question? You mentioned you use the MEGA to control your LEDs already? Do you do any fading or just off and on?


I have a small 10G tank and bought the AquaRay Mini LED 400 about a year ago. It was advertised as 'dimmable' but I found out too late that I needed to buy their $160 controller just to be able to control dimming. At first I thought it was going to be way too bright for my tank. I did some research and found that their controller basically used PWM to turn the light on and off very quickly and control dimming that way. 

One of my co-workers (and electrical engineer) helped me design a simple circuit to achieve this with the Arduino. Ended up costing about $60 total and I ended up with an Arduino Mega. I slowly ramp up the lights in the morning and back down at night using also using an RTC. No crazy thunderstorms though, this fixture only has white 6500K LEDs. If you want any more details, let me know!


----------



## HunterX

Fluffles said:


> That's a deal!
> 
> 
> 
> I have a small 10G tank and bought the AquaRay Mini LED 400 about a year ago. It was advertised as 'dimmable' but I found out too late that I needed to buy their $160 controller just to be able to control dimming. At first I thought it was going to be way too bright for my tank. I did some research and found that their controller basically used PWM to turn the light on and off very quickly and control dimming that way.
> 
> One of my co-workers (and electrical engineer) helped me design a simple circuit to achieve this with the Arduino. Ended up costing about $60 total and I ended up with an Arduino Mega. I slowly ramp up the lights in the morning and back down at night using also using an RTC. No crazy thunderstorms though, this fixture only has white 6500K LEDs. If you want any more details, let me know!


Any chace you could share your code? Oh pretty please!


----------



## scapegoat

I'm dying over here. My truck just got a flat tire and I'm waiting till the weekend to see if it can be patched or not. if not it's a $400 run flat... if it can be patched I'll be placing orders for components.


----------



## HunterX

I got the DINs installed in the box. The will be for the Tank Temp Probe, controls for the tank lights (LED), fan control for the tank light LEDs, and one extra for future upgrades. Hopefully a PH probe!

I was bummed how the hole came out. My drilled slipped on me and they are a little out of line. GRRRR at least the will be at the back of the box. It still drives me nuts.


----------



## HunterX

scapegoat said:


> I'm dying over here. My truck just got a flat tire and I'm waiting till the weekend to see if it can be patched or not. if not it's a $400 run flat... if it can be patched I'll be placing orders for components.


 Dang the bad luck!


----------



## benjaf

HunterX said:


> I do want to have the storms and what not during my light cycle but I have a lot of programming to do first.


Do help yourself to any parts my lighting code you find useful! It should be pretty simple to include in an existing sketch. It doesn't do storms etc but is otherwise pretty flexible.
http://www.plantedtank.net/forums/showthread.php?t=213234


----------



## scapegoat

could that 4 channel FET switch board be replaced with a general 4 channel switch?

yourduino.com's shipping prices are ridiculously high and i'm not having luck finding a similar item on amazon

nevermind. found it on ebay for the same price and free shipping item #: 261125619383


----------



## HunterX

scapegoat said:


> could that 4 channel FET switch board be replaced with a general 4 channel switch?
> 
> yourduino.com's shipping prices are ridiculously high and i'm not having luck finding a similar item on amazon
> 
> nevermind. found it on ebay for the same price and free shipping item #: 261125619383


 Hey Scape. technically yes it would work but it would be some serious over kill. The relay board is designed to control high voltage electronics using a low voltage control. Did you look on amazon for the FET Board. I found it on there as well. It cost a little more.

EDIT: I guess you did look on Amazon! LOL I didn't see that when I originally read your post!

EDIT 2: I found the FET board on Amazon: Amazon.com: 4 Route MOSFET Button IRF540 V2.0+: Everything Else


----------



## HunterX

benjaf said:


> Do help yourself to any parts my lighting code you find useful! It should be pretty simple to include in an existing sketch. It doesn't do storms etc but is otherwise pretty flexible.
> http://www.plantedtank.net/forums/showthread.php?t=213234


Thanks Ben! I will have a look at it.


----------



## scapegoat

HunterX said:


> Hey Scape. technically yes it would work but it would be some serious over kill. The relay board is designed to control high voltage electronics using a low voltage control. Did you look on amazon for the FET Board. I found it on there as well. It cost a little more.


I found it on amazon for $27ish... plus shipping would've made it ~$30

the ebay item i posted is the item at $18 and free shipping. jumped on that... aaand order stuff from jameco... and amazon.

Also, what do you think of Amazon.com : DROK Adjustable 4.0-40V to 1.25-37V 5/12V DC LM2596 Voltage Regulator Experimental Power Buck Converter+LED Voltmeter : Electronics over those DC to DC step up/down boards?


----------



## pianofish

Hey, so I just noticed that you have 9 plugs and only 8 green buttons. Do you plan on having 1 hot at all times. (I noticed in your initial pic, the bottom left plug wasn't wired up to hot)

Also, say I wanted to control 4 or more pumps. Would I need an additional MOSFET board? Or just another model that incorporates more than 3 items? What about this Mosfet board? http://www.adafruit.com/products/1438#Description

Also, what would you say is more important? Faster processor speed on the arduino or more PWM ports? I've been researching and apparently, the Arduino Due has a much faster processor, however only 6 pwm ports, whereas the arduino mega2560 has 14 pwm ports but a little bit slower of a processor.


----------



## scapegoat

what gauge wires did you use for everything? what is that clip called that attaches the wire to the motor? trying to place orders for those items as well but don't know the terminology


----------



## HunterX

pianofish said:


> Hey, so I just noticed that you have 9 plugs and only 8 green buttons. Do you plan on having 1 hot at all times. (I noticed in your initial pic, the bottom left plug wasn't wired up to hot)
> 
> Also, say I wanted to control 4 or more pumps. Would I need an additional MOSFET board? Or just another model that incorporates more than 3 items? What about this Mosfet board? http://www.adafruit.com/products/1438#Description
> 
> Also, what would you say is more important? Faster processor speed on the arduino or more PWM ports? I've been researching and apparently, the Arduino Due has a much faster processor, however only 6 pwm ports, whereas the arduino mega2560 has 14 pwm ports but a little bit slower of a processor.


 Wow great eye. Like you said, the last plug is wired directly to the power strips and will remain "hot" the entire time. I figured this would be easy to add a power strip or something if need be. Might plug the power for the Fish Tank lights in here as well. I'm surprised you caught that! 

I just want to be clear, when you say "pumps", are you talking about dosing pumps (12v) or larger (120v) pumps? That motor controller looks like a great controller but unfortunately it isn't designed to work with the MEGA. It's also a stackable design which would mean you couldn't use a sensor shield which really makes the wiring much cleaner and easier in my opinion. The FET Board I'm using controls 4 DC motors though. IF you needed to control 4 dosing pumps one option would be to not use the fan in the box. I think the box would be ok with just vent holes. 

If you want a "whole tank" controller, to me it is way more important to have more input/outputs to work with. The smaller boards are going to seriously limit you to what you can control. The mega is running all my code with no issues what so ever. I'm very please with the speed. I just don't think the Due would have enough inputs/outputs for you to control everything. If you just want to control one aspect of the tank you will be fine with the due.


----------



## HunterX

scapegoat said:


> what gauge wires did you use for everything? what is that clip called that attaches the wire to the motor? trying to place orders for those items as well but don't know the terminology


 Unfortunately, I bought the wire on the economy here in Kuwait. It isn't measured the same as back in the states. Just google HOME 110v wire size. I think you will be fine with 18gauge. The runs are very short. 

The connectors are standard #6 Spade Terminal connectors. Be sure to get ones that fit the wire size you want to use. Mine were designed for 16-22 gauge wire. Here is a link to the ones I used on Jameco: 
http://www.jameco.com/webapp/wcs/st...Id=10001&ddkey=http:StoreCatalogDrillDownView

Those DC controllers you posted should work fine as well. I was looking at them when I built mine. The only think I didn't like about them is that they do not step the voltage up. The input v has to be at least 1v higher then the output voltage. Which if you are using a 12 AC to DC converter you should well above the required 1v.


----------



## scapegoat

HunterX said:


> Unfortunately, I bought the wire on the economy here in Kuwait. It isn't measured the same as back in the states. Just google HOME 110v wire size. I think you will be fine with 18gauge. The runs are very short.
> 
> The connectors are standard #6 Spade Terminal connectors. Be sure to get ones that fit the wire size you want to use. Mine were designed for 16-22 gauge wire. Here is a link to the ones I used on Jameco:
> http://www.jameco.com/webapp/wcs/st...Id=10001&ddkey=http:StoreCatalogDrillDownView


those are definitely useful to know. I hadn't even thought of those. but what about the ones that connect to the peristaltic pumps?

nevermind, i found them. female spade quick connect terminals


----------



## pianofish

HunterX said:


> Wow great eye. Like you said, the last plug is wired directly to the power strips and will remain "hot" the entire time. I figured this would be easy to add a power strip or something if need be. Might plug the power for the Fish Tank lights in here as well. I'm surprised you caught that!
> 
> I just want to be clear, when you say "pumps", are you talking about dosing pumps (12v) or larger (120v) pumps? That motor controller looks like a great controller but unfortunately it isn't designed to work with the MEGA. It's also a stackable design which would mean you couldn't use a sensor shield which really makes the wiring much cleaner and easier in my opinion. The FET Board I'm using controls 4 DC motors though. IF you needed to control 4 dosing pumps one option would be to not use the fan in the box. I think the box would be ok with just vent holes.
> 
> If you want a "whole tank" controller, to me it is way more important to have more input/outputs to work with. The smaller boards are going to seriously limit you to what you can control. The mega is running all my code with no issues what so ever. I'm very please with the speed. I just don't think the Due would have enough inputs/outputs for you to control everything. If you just want to control one aspect of the tank you will be fine with the due.


I am talking about dosing pumps. My short term goal is to get the Mega and whatever I need to start autodosing immediately, while still leaving room to add on the diy led fixtures, auto top off, auto water change, etc. 
Would it be possible to add two of those fet boards that you have, 1 to control the 4 dosing pumps and 1 to control fans both on the box itself and then future fans on the LEDs? 

I think i'm gonna go Mega. And lastly what purpose does the sensor shield serve? Just a nicer way to organize things?
Joshua


----------



## bigd603

Hey guys, I just found these little guys over at Sparkfun, Little tiny mosfet boards for like $4 a piece:

https://www.sparkfun.com/products/10256

Each one controls one motor, but just buy as many as you need and they're small enough to put wherever you need them in the build. Shipping with USPS is only a few bucks too, and they ship from Colorado. Only downside is each board will need it's own 12v power line.


----------



## scapegoat

just ordered a bunch of components. it'll be time to get my website back online and start documenting the build process and programming. exciting times!


----------



## HunterX

scapegoat said:


> those are definitely useful to know. I hadn't even thought of those. but what about the ones that connect to the peristaltic pumps?
> 
> nevermind, i found them. female spade quick connect terminals


Sorry about that. I didn't realize you were talking about the female connectors on the pumps. 



pianofish said:


> I am talking about dosing pumps. My short term goal is to get the Mega and whatever I need to start autodosing immediately, while still leaving room to add on the diy led fixtures, auto top off, auto water change, etc.
> Would it be possible to add two of those fet boards that you have, 1 to control the 4 dosing pumps and 1 to control fans both on the box itself and then future fans on the LEDs?
> 
> I think i'm gonna go Mega. And lastly what purpose does the sensor shield serve? Just a nicer way to organize things?
> Joshua


Yup you could use as many FET boards as you want. Just make sure you don't exceed the amperage or wattage of whatever converter is providing your 12v to the boards. I need to do some checking to gather all the details but I think I have a better salutation for controlling the fans on your LED. I will get back to you tomorrow about that! 

The sensor shield is great. It makes all the wiring much easier and cleaner. If you get the premade wires with the female ends on both ends, its as easy as plugging into the sensor shield and then plugging in to your relays or what ever else you have. Below is a link that explains it better then I can. Check out the link about the sensor shield on that page as well. 

http://arduino-info.wikispaces.com/Cables


----------



## benjaf

bigd603 said:


> Hey guys, I just found these little guys over at Sparkfun, Little tiny mosfet boards for like $4 a piece:
> 
> https://www.sparkfun.com/products/10256
> 
> Each one controls one motor, but just buy as many as you need and they're small enough to put wherever you need them in the build. Shipping with USPS is only a few bucks too, and they ship from Colorado. Only downside is each board will need it's own 12v power line.


Please note that these boards have no current limiting resistor between the arduino and the mosfet. You will need to add one to avoid long term damage to your arduino!

EDIT: If you are swithing it once a day you may not see damage any time soon. But if you do PWM it is very important!


----------



## bigd603

benjaf said:


> Please note that these boards have no current limiting resistor between the arduino and the mosfet. You will need to add one to avoid long term damage to your arduino!


Good catch!


----------



## bigd603

So I picked up that nano router yesterday, and holy smokes it is TINY. Smaller than an Arduino Uno and probably about as thick as a stack of 5 quarters. I had it working, but then when I upgraded the firmware it just died completely...I knew I shouldn't have tried the beta firmware...So, back to Fry's tonight for a replacement :-/ I'll give you guys more updates once I have the replacement up and running.


----------



## HunterX

bigd603 said:


> So I picked up that nano router yesterday, and holy smokes it is TINY. Smaller than an Arduino Uno and probably about as thick as a stack of 5 quarters. I had it working, but then when I upgraded the firmware it just died completely...I knew I shouldn't have tried the beta firmware...So, back to Fry's tonight for a replacement :-/ I'll give you guys more updates once I have the replacement up and running.


 That is such a bummer! I can't wait to see what you get going? As soon as you give me the thumbs up I'll be buying one.


----------



## Fluffles

HunterX said:


> Any chace you could share your code? Oh pretty please!


After looking at benjaf's lighting code, I would recommend you use his code to get you started. My code is a complete hack job that I got up and running in 30min as I was rushed to get my lights working ASAP. It's only 10 lines and barely does its job. Unless you want something extremely simple, go with benjaf's code as it is MUCH better and more robust. Once I get the new controller built, I'm thinking of starting off with some of his stuff (btw, excellent work Benjaf).


----------



## benjaf

Fluffles said:


> (btw, excellent work Benjaf).


Thanks mate!


----------



## HunterX

Fluffles said:


> After looking at benjaf's lighting code, I would recommend you use his code to get you started. My code is a complete hack job that I got up and running in 30min as I was rushed to get my lights working ASAP. It's only 10 lines and barely does its job. Unless you want something extremely simple, go with benjaf's code as it is MUCH better and more robust. Once I get the new controller built, I'm thinking of starting off with some of his stuff (btw, excellent work Benjaf).


Roger that! I have been so busy at work that I haven't had a chance to check out his code yet. But it's promising to know you're pretty excited about it. 



benjaf said:


> Thanks mate!


Thanks for the addition. With all of us working together, we may just come up with something pretty decent!


----------



## bigd603

Hey everyone, I got the replacement nano router, and finally got it up and running. It is working really well! I put together a quick little sketch with Xively's service to read a DS18B20 temp sensor. You can check out the feed here: https://xively.com/feeds/835109294 

I gotta say, I'm pretty impressed. The nano router was super easy to setup, and Xively has tons of examples so it was easy to put together a working test. Being able to graph and access my data from anywhere is really cool. I read that you can supposedly turn things on and off through Xively, but I haven't figured that out yet. 

Hunter, I know you were pretty excited to hear my thoughts on the nano, and so far its obviously a big thumbs up, but I just wanted to make sure you know that you also need an ethernet shield, or another way to connect the arduino to ethernet (something like this will work too: http://www.robotshop.com/en/w5100-ethernet-network-module.html). I didn't make that clear when I first mentioned it. If you already have one, then perfect, get the router. I was lucky enough to get it on sale for like $15. If you don't already have one check out Adafruit's wifi shield for $40:
http://www.adafruit.com/products/1491

They also have a low cost breakout board for $35:
http://www.adafruit.com/products/1469

If I didn't have the ethernet shield already, I would go for one of those. However, I don't know if they ship to APOs.


----------



## bigd603

Here's the sketch if anyone wants to put together something similar to test out. It's based off of Xively's wifi tutorial, so there's instructions in there for connecting a wifi shield, too, if anyone has one.



Code:


/*
##Xively WiFi Sensor Tutorial##
This sketch is designed to take sensors (from photocell) and upload the values to Xively
at consistant intervals. At the same time it gets a setable value from Xively to adjust the brigthness
of an LED. This sketch is reusable and can be adapted for use with many different sensors.
Derived from Xively Ardino Sensor Client by Sam Mulube.
 
By Calum Barnes 3-4-2013
BSD 3-Clause License - [http://opensource.org/licenses/BSD-3-Clause]
Copyright (c) 2013 Calum Barnes
*/
#include <SPI.h>
#include <WiFi.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <HttpClient.h>
#include <Xively.h>

//Uncomment this section if using ethernet shield
// MAC address for your Ethernet shield
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x26, 0x4E };
IPAddress ip(192,168,0,10); //<<< ENTER YOUR IP ADDRESS HERE!!!

//This line may not be neccessary, comment out if having trouble
EthernetServer server(80);

/*Uncomment this section if using WiFi shield 
char ssid[] = "SSID_HERE"; //  your network SSID (name) 
char pass[] = "PASS_HERE";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)
 
int status = WL_IDLE_STATUS;
 */
 
#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
 

 
// Your Xively key to let you upload data
char xivelyKey[] = "8Ot0JKtOfqg7yLaG9QhNN5s3HSqbPl9WnO7c4wrBptpiq6ER";
//your xively feed ID
#define xivelyFeed 835109294
//datastreams
char sensorID[] = "Temperature";
//char ledID[] = "LED_CHANNEL";

 
// Define the strings for our datastream IDs
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorID, strlen(sensorID), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(xivelyFeed, datastreams, 1 /* number of datastreams */);
 
EthernetClient client;
XivelyClient xivelyclient(client);
 
 /*Uncomment this section if using WiFi Shield
void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());
 
  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);
 
  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm \n");
}
*/




void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  ///Ethernet connection setup
  Ethernet.begin(mac, ip);
  server.begin();
  
  
  
  
  Serial.println("Starting single datastream upload to Xively...");
  Serial.println();
 
 /*Uncomment this section if using WiFi Shield
  // attempt to connect to Wifi network:
  while ( status != WL_CONNECTED) { 
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, keyIndex, pass);
    // wait 10 seconds for connection:
    delay(10000);
  } 
  Serial.println("Connected to wifi");
  printWifiStatus();
}
 */
 }
void loop() {
  sensors.requestTemperatures();//send command to retrieve temperature
  
///////////////////////////////////////////////////////
  //read sensor values
  int sensorValue = sensors.getTempFByIndex(0);
  datastreams[0].setFloat(sensorValue);
  
  /*
  //print the sensor valye
  Serial.print("Read sensor value ");
  Serial.println(datastreams[0].getFloat());
 */
  //send value to xively
  Serial.println("Uploading it to Xively");
  int ret = xivelyclient.put(feed, xivelyKey);

  
  
  //delay between calls
  delay(1000);
}


----------



## shift

Is they wifi shield worth getting? I still have a nano and a mega board to play with


----------



## bigd603

shift said:


> Is they wifi shield worth getting? I still have a nano and a mega board to play with


I don't have any experience with the WiFi shield, so I can't really say. I just went with the TP Link nano router because I already had the Ethernet shield. 

Sent from my Galaxy Nexus using Tapatalk


----------



## HunterX

bigd603 said:


> Hey everyone, I got the replacement nano router, and finally got it up and running. It is working really well! I put together a quick little sketch with Xively's service to read a DS18B20 temp sensor. You can check out the feed here: https://xively.com/feeds/835109294
> 
> I gotta say, I'm pretty impressed. The nano router was super easy to setup, and Xively has tons of examples so it was easy to put together a working test. Being able to graph and access my data from anywhere is really cool. I read that you can supposedly turn things on and off through Xively, but I haven't figured that out yet.
> 
> Hunter, I know you were pretty excited to hear my thoughts on the nano, and so far its obviously a big thumbs up, but I just wanted to make sure you know that you also need an ethernet shield, or another way to connect the arduino to ethernet (something like this will work too: http://www.robotshop.com/en/w5100-ethernet-network-module.html). I didn't make that clear when I first mentioned it. If you already have one, then perfect, get the router. I was lucky enough to get it on sale for like $15. If you don't already have one check out Adafruit's wifi shield for $40:
> http://www.adafruit.com/products/1491
> 
> They also have a low cost breakout board for $35:
> http://www.adafruit.com/products/1469
> 
> If I didn't have the ethernet shield already, I would go for one of those. However, I don't know if they ship to APOs.


 I love it brother. I especially liked how the Xively sight tracks that data in a graph format as well. I went ahead and ordered the breakout board. I can['t wait to get it up and running. Thank you very much for taking the time to research and then post your findings. Also for posting where to purchase the parts I needed. Very Cool!


----------



## HunterX

It response to the great advice, I got the diodes installed to prevent any voltage spikes while any of the motors are "coasting"! Cycled them through a few times and everything appears to be working as expected. I did have to move put the controls for the motors on a different set of outputs. I need the outputs the motors were connected to for the new wifi breakout board. Thanks to BigD I'm now anxiously waiting for another shipment.  Thanks BigD!


----------



## scapegoat

how did you install them? I actually got flyback diodes in the mail yesterday. friday was a handful of things from amazon; but nothing I can really start with... i suppose the fun starts when the ac to dc power supply comes in.


----------



## HunterX

I soldered them between the wire connections running to the motors. The side of the DIOD with the black line should be soldered to the positive wire. Have you started any "code" yet?


----------



## scapegoat

I haven't started any programming yet. Still research the handful of node gpio libraries out there. it's looking like I'll need to figure a mix between python and javascript to get mine to work.

i'm trying to plan the programming out a bit more in order to have an easier time of adding/removing/moving things around. such as a way to register components to gpio pins; with probably a plain text config file.

I might get started on some preliminary stuff to cut my teeth on tonight. something simple... turning an LED on/off lol. that'll go far though, controlling a gpio pin. pretty much the basis for everything.


----------



## bigd603

HunterX said:


> It response to the great advice, I got the diodes installed to prevent any voltage spikes while any of the motors are "coasting"! Cycled them through a few times and everything appears to be working as expected. I did have to move put the controls for the motors on a different set of outputs. I need the outputs the motors were connected to for the new wifi breakout board. Thanks to BigD I'm now anxiously waiting for another shipment.  Thanks BigD!


No problem, man, glad I could help. I've had an autodoser based off of Shift's work that I have been wanting to expand to an all out controller. I had already done a bunch of research into components but never really did anything. This thread has really inspired me to finally get moving on it, so thank you Hunter. This stuff is a lot of fun, and this collective work is really what arduino is all about. It will be fun to see what all of us here put together.

Scapegoat, you said you need to find some code to program the GPIO pins. Are you using something other than Arduino? Raspberry Pi or Beaglebone?


----------



## scapegoat

Hey. Yeah, I'm using a raspberry pi. I wanted a gui from the start. And being a web developer I've decided to go with nodejs to program the controller. More specifically meteorjs, a websocket based framework. So I'll end up with a web based guide accessible on my home network that'll be used to set my timing and view data like temps.

And not really find. There are a handful of node gpio libraries out there, it's just deciding on which one


----------



## bigd603

scapegoat said:


> Hey. Yeah, I'm using a raspberry pi. I wanted a gui from the start. And being a web developer I've decided to go with nodejs to program the controller. More specifically meteorjs, a websocket based framework. So I'll end up with a web based guide accessible on my home network that'll be used to set my timing and view data like temps.
> 
> And not really find. There are a handful of node gpio libraries out there, it's just deciding on which one


That's pretty cool, can't wait to see how that turns out too. 

Sent from my Galaxy Nexus using Tapatalk


----------



## bigd603

Hunter, is there a fuse built into that power entry module?


----------



## HunterX

bigd603 said:


> Hunter, is there a fuse built into that power entry module?


 bigd,

No the one I have does have a line conditioner built into but not a fuse. It would be a great idea to have a fuse built into the high voltage side. I would also recommend a power switch built into the power entry module. They were on back order when I ordered mine so I bought the plain version.


----------



## HunterX

*BOX Plan*

I was asked what the dimensions of the box were so I thought I would upload the plan in case anyone else was curious. It's drawn to scale so I knew everything would fit. It did change some but that is to be expected.


----------



## bigd603

It might not be a bad idea to add a second fan into the box on the opposite side, so one is blowing in and the other is blowing out. With just one blowing out you will have negative pressure, and essentially create a vacuum inside the case. You could also relieve this issue just by drilling some holes into the case, but if it does get really hot in there a second fan would really help.


----------



## HunterX

bigd603 said:


> It might not be a bad idea to add a second fan into the box on the opposite side, so one is blowing in and the other is blowing out. With just one blowing out you will have negative pressure, and essentially create a vacuum inside the case. You could also relieve this issue just by drilling some holes into the case, but if it does get really hot in there a second fan would really help.


Sorry I didn't make that more clear. Yes you have to have some way for air to get into the box when the fan is on. For me, I made sure the lid doesn't seal all the way. There is about a 1/16 gap along the back edge to allow air in. Too be honest, the box just doesn't get that hot. My room stays about 63F and the box stays at about 74F. The fan doesn't even kick on until it gets 78. So in my current conditions, it hardly ever comes on.


----------



## scapegoat

bigd603 said:


> That's pretty cool, can't wait to see how that turns out too.
> 
> Sent from my Galaxy Nexus using Tapatalk


you and me both... I haven't started anything, but I expect to get a bunch more stuff in throughout the week. Though I won't be getting the FET board until later in the month.

So i'll take that time to start drawing up schematics and planning the layout of the gpio and writing some requirements.

It's also looking like I need a way to raise the 3v3 from the raspi gpio's to 5v. at least for the main relay.

I also have a gertboard i'm trying to figure out how to incorporate: such as using the open collector driver to power the channel relays? it looks like I can control up to 6 devices with the OCD, I just have to connect a 5v power supply to it. I might be getting to the point that I need to start my own thread here for relevant assistance.


----------



## pianofish

I've decided to do this via pic micro controller and a raspberry pi instead of arduino, I'll let yall know how it comes out. Gives me more options than arduino, although a bit more research will be required. 
Joshua


----------



## scapegoat

nevermind


----------



## scapegoat

Looks like i'll be sharing some things sometime this weekend.

I believe I have all my major components except for that FET board. I've been using a 12v AC adapter for prototyping. I've currently got the Pi set up to read, and display, temps from probes, on a web page hosted by itself. 

Further, I am capable of turning 6 of the 8 outlets on and off via that same web page. Last night I started work on the scheduling code. I'll be able to set the schedule from the GUI, and save it. Right now it'll accept military time in the following format 00:00. on and off each day. I may change that to just be a daily on/off, instead of doing it by the day. that'll be easier, and makes more sense since it's really just lights on/off and co2 on/off.

The next part of that, though, is having the option to set the outlet based on a data from probes. in this version, just the temp.

I'm debating on wiring up 2 of the pins to control 2 outlets each, so all 8 are controlled as 4x1 and 2x2, or keeping 2 always on. I need to consider what i have need for. I do have 2 heaters.

Once the FET board comes in i'll handle the pumps and their schedules. I've just been using a breadboard on my desk to do this, but i'm thinking it's time to slice off a piece of plywood to mount everything to in order to produce a full prototype that doesn't have to be put away in parts each night. (2 year olds and electronics laying around don't mix)

I've some ideas for way down the line, but i have a second Pi for developing more things. I need to go through and clean out code and move some code off to their own files for easier maintenance. this was a lot easier than I thought. 

Many thanks to Hunter for providing a beautifully laid out controller that was easy to follow. Much inspiration was had by all!


----------



## HunterX

I just bought a 120 gallon tank for $450. Let me know if you think I got a good deal on it. 

http://springfield.craigslist.org/for/4292091129.html

Scape,

That is awesome. I haven't dealt wit the Pi's at all but it sounds like you're all over it. I wish I was able to control my controller from the net as well. I have to travel all the time because of the Army and that would be a very convenient feature to have. I can't wait to see what you have come up with!


----------



## scapegoat

HunterX said:


> I just bought a 120 gallon tank for $450. Let me know if you think I got a good deal on it.
> 
> http://springfield.craigslist.org/for/4292091129.html
> 
> Scape,
> 
> That is awesome. I haven't dealt wit the Pi's at all but it sounds like you're all over it. I wish I was able to control mine controller from the net as well. I have to travel all the time because of the Army and that would be a very convenient feature to have. I can't wait to see what you have come up with!


It's been a bit of a trial and error... it isn't secure enough to be accessed outside the network. It wouldn't be difficult to add in some authentication, which i plan to do. My biggest concern is that I've been unable to run it outside of being root user; which is a huge security hole for this project. the GPIO pins require root access, and i've tried some plugins that are supposed to give me that access. I might have to just change ownership of the gpio files to the pi user.

I do want to, eventually, make it live so folks can go to the url and see parameters. that would be even more useful if you're away and you've got a number of probes set up.

Once things started coming together, making things happen was easy. figuring out the best way to make the system configurable outside code is a little more difficult.

I've got a database that is getting pinged every minute for outlets w/ an on or off of the current time. The temperature sensor file, on the other hand, is being read every second. though, I figure I can probably change that to once a minute as well.

I want to get a pH probe hooked up soon to graph co2 introduction and pH drop, to control when the co2 gets turned on/off while the lights are on.

I think the end product will be neat. using some libraries out there, it'd been a rather trivial project, so I'm excited to share.


----------



## bigd603

scapegoat said:


> It's been a bit of a trial and error... it isn't secure enough to be accessed outside the network. It wouldn't be difficult to add in some authentication, which i plan to do. My biggest concern is that I've been unable to run it outside of being root user; which is a huge security hole for this project. the GPIO pins require root access, and i've tried some plugins that are supposed to give me that access. I might have to just change ownership of the gpio files to the pi user.
> 
> I do want to, eventually, make it live so folks can go to the url and see parameters. that would be even more useful if you're away and you've got a number of probes set up.
> 
> Once things started coming together, making things happen was easy. figuring out the best way to make the system configurable outside code is a little more difficult.
> 
> I've got a database that is getting pinged every minute for outlets w/ an on or off of the current time. The temperature sensor file, on the other hand, is being read every second. though, I figure I can probably change that to once a minute as well.
> 
> I want to get a pH probe hooked up soon to graph co2 introduction and pH drop, to control when the co2 gets turned on/off while the lights are on.
> 
> I think the end product will be neat. using some libraries out there, it'd been a rather trivial project, so I'm excited to share.


Scapegoat, I'm really excited to see what you've done with the Pi. I've been using Arduino for a while now, but just recently got a raspberry pi. Keep plugging along and let us know what you come up with!

Sent from my Galaxy Nexus using Tapatalk


----------



## HunterX

Good stuff everyone. I'm so glad to see all the input everyone is providing. 

I have never used the Pi or read anything about it. Anyone care to detail the major differences between the Pi and Arduino?


----------



## benjaf

The Raspberry Pi is actually a small ARM based computer, complete with USB, Ethernet and the ability to run a normal Linux. Unlike most other micro computers it also has a number of I/O pins that allow you to control hardware directly much like an Arduino.


----------



## scapegoat

bigd603 said:


> Scapegoat, I'm really excited to see what you've done with the Pi. I've been using Arduino for a while now, but just recently got a raspberry pi. Keep plugging along and let us know what you come up with!
> 
> Sent from my Galaxy Nexus using Tapatalk


thanks. i'm super excited about it to. I just got my FET board in and need to research how to wire it. I'm hoping to get the rough time scheduling system down for the relays tonight and start my own thread w/ a video of it in action. I need to get the thermometer reattached to the prototype and play with scheduling the relays based on data tonight as well.

once i get the FET board wired up it'll be time to throw together a full working prototype though, and get it going on my tank. Once some freelance checks come in I'll be ordering all the components a second time to work on a second prototype while the first is running my tank.



HunterX said:


> Good stuff everyone. I'm so glad to see all the input everyone is providing.
> 
> I have never used the Pi or read anything about it. Anyone care to detail the major differences between the Pi and Arduino?





benjaf said:


> The Raspberry Pi is actually a small ARM based computer, complete with USB, Ethernet and the ability to run a normal Linux. Unlike most other micro computers it also has a number of I/O pins that allow you to control hardware directly much like an Arduino.


yeah, the Pi is pretty sweet. It's a full blown computer the size of a credit card (dimensions anyway). 

I've the model b w/ 512mb ram, 2 usb, ethernet, hdmi and audio out. the entire operating system is kept on a 4gb SD card. I chose the Pi because I wanted to decide my programming language. That makes things a little bit more difficult as I had to further research libraries to get things going.

I'll explain myself even more once i get a thread going.


----------



## benjaf

scapegoat said:


> I'll explain myself even more once i get a thread going.


Looking forward to that, I plan to eventually replace (or at least supplement) my arduino controller with a Pi. Just itching to implement lighting and logging in a more advanced programming language!


----------



## HunterX

I recieved my Adafruit CC3000 WiFi breakout board today. I can't wait to get off of work and get it hooked up.


----------



## HunterX

Fluffles said:


> Wow, this is looking great!
> Thanks so much for the parts list. I've had an Arduino Mega controlling my LED lights for about a year now and wanted to expand it to a complete aquarium controller but never knew how to approach this. Your thread has given me a clear path on how to get things started.
> I actually ordered most of the components already and it looks like I'll be building a clone of your project. Thanks again!
> 
> Btw, I see that your dosing pumps and fan are connected to the 4 channel MOSFET board. Did you consider placing a diode in parallel to each pump/fan to protect your transistors from flyback?
> http://en.wikipedia.org/wiki/Flyback_diode
> I think Shift's dosing pump project has some of these installed, but it seems like the transistors are pretty beefy though so it might not be necessary at all. Maybe someone here with electrical experience might be able to offer some advice.


Fluffles,
Did you get started on your project yet? 


My wifi board is hooked up and passed the test sketch. I'm now working on adding the required code to my sketch. It's been pretty busy over here lately so I haven't had any time to work on it. I have tomorrow off so I should be able to get my controller "online" by tomorrow afternoon.


----------



## HunterX

My controller is "online" Here is the link if you want to check it out. 

https://xively.com/feeds/76312450

I am concerned about the code used to connect the CC3000 (WiFi board) to the net. It has several "while" commands in it. This causes the whole project to become unresponsive while the CC3000 is connecting and doing it's thing. Even worse, if the CC3000 is trying to connect and a connection is not available, it will hang in the "while" loop causing the controller to be rendered useless. It could be a major issue if the controller hangs while the heater is on. The heater would stay on and boil the tank. Same scenario with any number of the connected devices. 

Any one out there willing to take a look at the code and see if I could substitute the "while" commands with something else? Below is a link to the code I used from Adafruit's website. 

http://learn.adafruit.com/adafruit-cc3000-wifi-and-xively/arduino-sketch


----------



## Fluffles

HunterX said:


> Fluffles,
> Did you get started on your project yet?


Most of the parts are in, but I'm still missing the 8-channel relay board, 4x24 LCD, and the 10P terminal blocks. They are coming in from China so it still might be 1-3 weeks from now. Also, I ordered a wood box for the project since I don't have any woodworking skills or tools. That's still about 2 weeks away from arrival. I don't think I'll really be able to start before getting the box.

Here's a quick pic of where everything stands:









This will be very similar to your project except I have less space to fit everything in so it will be a bit of a challenge.

I will be adding an in-line fuse for the AC line before the terminal blocks just to be safe.
Also, I'll have a second LCD screen inside the box (above the power supply). The screen has pushbuttons so I was thinking of making the second screen a menu that will allow me to select LED brightness, morning ramp-up time, nightime, time set, and fan speed.

I kinda decided not to do temperature or PH readings from the tank. My tank is a small 10G rimless tank, and I'd like to minimize the amount of wires going in and out. I won't be doing any sort of ethernet/wireless communication since I don't see the point with my specific setup, it also keeps things simple.

I think the biggest thing for me is that I'll be able to control relays, LEDs, and dosing pumps from the same RTC module. Right now I have 3 different timers in my tank and already had several accidents happen while I'm on a trip. Also, with pushbuttons to control the relays, it will be a breeze to disable outlets for doing maintenance.

Thanks again for posting your project up so everyone can see it. It made me take the plunge and get started on this. I'll keep you posted on any new ideas or discoveries I make while working on this.


----------



## bigd603

Hey guys, what are your thoughts about keeping the ends of the fertilizer tubes in the tank, as opposed to having them hang over the edge and dripping in? When they just drip in you have to clean the ends of the tubes every day or so, while leaving them in the water will eliminate this problem. My only concern with this is slowly leaching excessive fertilizer into the tank throughout the day. Do you think this extra amount of fertilizer wouldnt be a concern as long as I'm doing weekly water changes?


----------



## bigd603

Hunter, maybe during the while loop add in a counter, and if it attempts to connect and fails three times exit the while loop so it continues to control the tank normally. Or instead of a counter, only give it 60 seconds to connect, if that fails exit the loop.


----------



## HunterX

Fluffles said:


> Most of the parts are in, but I'm still missing the 8-channel relay board, 4x24 LCD, and the 10P terminal blocks. They are coming in from China so it still might be 1-3 weeks from now. Also, I ordered a wood box for the project since I don't have any woodworking skills or tools. That's still about 2 weeks away from arrival. I don't think I'll really be able to start before getting the box.
> 
> Here's a quick pic of where everything stands:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> This will be very similar to your project except I have less space to fit everything in so it will be a bit of a challenge.
> 
> I will be adding an in-line fuse for the AC line before the terminal blocks just to be safe.
> Also, I'll have a second LCD screen inside the box (above the power supply). The screen has pushbuttons so I was thinking of making the second screen a menu that will allow me to select LED brightness, morning ramp-up time, nightime, time set, and fan speed.
> 
> I kinda decided not to do temperature or PH readings from the tank. My tank is a small 10G rimless tank, and I'd like to minimize the amount of wires going in and out. I won't be doing any sort of ethernet/wireless communication since I don't see the point with my specific setup, it also keeps things simple.
> 
> I think the biggest thing for me is that I'll be able to control relays, LEDs, and dosing pumps from the same RTC module. Right now I have 3 different timers in my tank and already had several accidents happen while I'm on a trip. Also, with pushbuttons to control the relays, it will be a breeze to disable outlets for doing maintenance.
> 
> Thanks again for posting your project up so everyone can see it. It made me take the plunge and get started on this. I'll keep you posted on any new ideas or discoveries I make while working on this.


Everything is really looking good! Great idea to add a fuse to the high side voltage. I plan on doing the same thing. If you have the room I would recommend adding a switch to kill the high side voltage effectively turning the box off. You may discover that you really don't need the bread board in your application. Everything you have will connect directly to the Arduino unless you have an I2C LCD display and I2C RTC. In that case the bread board would make those connections cleaner and more convenient.


----------



## HunterX

bigd603 said:


> Hey guys, what are your thoughts about keeping the ends of the fertilizer tubes in the tank, as opposed to having them hang over the edge and dripping in? When they just drip in you have to clean the ends of the tubes every day or so, while leaving them in the water will eliminate this problem. My only concern with this is slowly leaching excessive fertilizer into the tank throughout the day. Do you think this extra amount of fertilizer wouldnt be a concern as long as I'm doing weekly water changes?


I haven't thought that far ahead yet. You really shouldn't get too much FERT leaking into the tank from the line though. The pumps are designed to keep the from happening. Granted as the wear out you may get some leaking into your tank. Like you stated though, I wouldn't expect it to be enough to cause a concern. 



bigd603 said:


> Hunter, maybe during the while loop add in a counter, and if it attempts to connect and fails three times exit the while loop so it continues to control the tank normally. Or instead of a counter, only give it 60 seconds to connect, if that fails exit the loop.


I was thinking along the same line. I have posted the issue on the Arduino page hoping someone may be able to come up with something to fix that issue. Wish me luck!


----------



## benjaf

HunterX said:


> My controller is "online" Here is the link if you want to check it out.
> 
> https://xively.com/feeds/76312450
> 
> I am concerned about the code used to connect the CC3000 (WiFi board) to the net. It has several "while" commands in it. This causes the whole project to become unresponsive while the CC3000 is connecting and doing it's thing. Even worse, if the CC3000 is trying to connect and a connection is not available, it will hang in the "while" loop causing the controller to be rendered useless. It could be a major issue if the controller hangs while the heater is on. The heater would stay on and boil the tank. Same scenario with any number of the connected devices.
> 
> Any one out there willing to take a look at the code and see if I could substitute the "while" commands with something else? Below is a link to the code I used from Adafruit's website.
> 
> http://learn.adafruit.com/adafruit-cc3000-wifi-and-xively/arduino-sketch


These are really 2 very different issues. 
The problems with unresponsive UI is not really something you can do much about unless it at some point waits for anything that is not going to happen. Allowing the code to do something else while waiting would require the use of software interrupts, something I don't think the Arduino supports.
The danger of 'hanging' during connection is a major problem if not handled. The easiest way to address that would be to store the time ( millis() ) at which the wait begins, and then break the loop if more than X seconds have passed.


----------



## HunterX

benjaf said:


> These are really 2 very different issues.
> The problems with unresponsive UI is not really something you can do much about unless it at some point waits for anything that is not going to happen. Allowing the code to do something else while waiting would require the use of software interrupts, something I don't think the Arduino supports.
> The danger of 'hanging' during connection is a major problem if not handled. The easiest way to address that would be to store the time ( millis() ) at which the wait begins, and then break the loop if more than X seconds have passed.


Hey Ben,

Thanks for the quick reply. I was hoping you would take a stab at it. I'll apologize in advance for my ignorance but I'm a little confused by your reply. I understand the issue to be that the "while" command is in fact waiting for a condition to be satisfied that will never be satisfied, if an internet connection is not available, causing the code to hang in that "while" statement. I understand the second part of your reply and I agree. I'm not crazy about "delay"(s) at all but I would rather use a 10 second delay with and "if" statement be used allowing the wifi to connect than for it to hang in a "while" command. What do you think?


----------



## HunterX

Below is one small piece of the code that is a problem. If the DHCP doesn't connect, it just keeps delaying (100) over and over until it does again causing the hole system to just wait until it connects. There has to be a better way. LOL. I do need to dig into the cc3000.checkDHCP() function to understand what all it is doing. Haven't got that far yet. 



Code:


while (!cc3000.checkDHCP())  
{    
delay(100); 
}


----------



## benjaf

HunterX said:


> Below is one small piece of the code that is a problem. If the DHCP doesn't connect, it just keeps delaying (100) over and over until it does again causing the hole system to just wait until it connects. There has to be a better way. LOL. I do need to dig into the cc3000.checkDHCP() function to understand what all it is doing. Haven't got that far yet.
> 
> 
> 
> Code:
> 
> 
> while (!cc3000.checkDHCP())
> {
> delay(100);
> }


Yeah, that is pretty dodgy in most real-life cases. 
What you could do is something like this:


Code:


long startTime = millis();
while (!cc3000.checkDHCP())  
{    
delay(100);
if(millis() > startTime + 10000 ) { break; }
}

This will 'give up' checking for a DHCP server after 10 seconds. You will probably have to do some additional error handling after this code if something relies on the Internet connection to work, but I hope you get the idea.


----------



## HunterX

benjaf said:


> Yeah, that is pretty dodgy in most real-life cases.
> What you could do is something like this:
> 
> 
> Code:
> 
> 
> long startTime = millis();
> while (!cc3000.checkDHCP())
> {
> delay(100);
> if(millis() > startTime + 10000 ) { break; }
> }
> 
> This will 'give up' checking for a DHCP server after 10 seconds. You will probably have to do some additional error handling after this code if something relies on the Internet connection to work, but I hope you get the idea.


 Thanks Ben. I'm going to give that try and see what happens. I understand what you're doing here. Granted, there may now be code/functions following this that depend on the connection, which doesn't exist, causing them to hang as well. Without doing any research, what do you think about using a "go to" if the code has to "break" out of the first "while" loop sending the operation to the end of the wifi code? It would then just try again the next time it's called on?


----------



## benjaf

HunterX said:


> Thanks Ben. I'm going to give that try and see what happens. I understand what you're doing here. Granted, there may now be code/functions following this that depend on the connection, which doesn't exist, causing them to hang as well. Without doing any research, what do you think about using a "go to" if the code has to "break" out of the first "while" loop sending the operation to the end of the wifi code? It would then just try again the next time it's called on?


Depending on how this function works you might be able to simply return. Whatever is done for the rest of the function probably does not apply if there is no connection?
I personally do not use goto except as an absolutely last resort (never) but it can be a very useful hack. The aversion is mainly an education thing!


----------



## HunterX

benjaf said:


> Depending on how this function works you might be able to simply return. Whatever is done for the rest of the function probably does not apply if there is no connection?
> I personally do not use goto except as an absolutely last resort (never) but it can be a very useful hack. The aversion is mainly an education thing!


Hey Ben,

With the code you supplied, it no longer hangs during the DHCP request. It is hanging here now. It's my understanding this is the part of the code waiting to get a reply back from the website confirm the data was received. How would you write the "break" here?



Code:


while (client.connected()) 
            {
              while (client.available()) 
              {
                char c = client.read();
                Serial.print(c);
              }
            }
          client.close();


----------



## benjaf

HunterX said:


> Hey Ben,
> 
> With the code you supplied, it no longer hangs during the DHCP request. It is hanging here now. It's my understanding this is the part of the code waiting to get a reply back from the website confirm the data was received. How would you write the "break" here?
> 
> 
> 
> Code:
> 
> 
> while (client.connected())
> {
> while (client.available())
> {
> char c = client.read();
> Serial.print(c);
> }
> }
> client.close();


First of all: If you have not yet put this whole 'send data' section into a function by itself, you should do so now.
If the connection to DHCP server fails, you cold then simple use 


Code:


return;

in stead of


Code:


break;

That way you don't even encounter anything that expects a connection, since everything after the DHCP request is skipped.

How have you handled the delay between data transmissions (the 10 second one at the end)? This does not have to be an actual delay, you could simply store the time at which data was last sent, and then send again when you think enough time has passed. 10 seconds seems somewhat unnecessary to me but then I don't know how much data you send. 

This section should also be escaped with a timeout like the other one, otherwise you can have an endless loop here as well:


Code:


 while (ip == 0) {
    if (! cc3000.getHostByName(WEBSITE, &ip)) {
      Serial.println(F("Couldn't resolve!"));
    }
    delay(500);
  }

I would also move the above delay inside the if() statement, there really is no reason to delay anything if the IP is resolved correctly.

Depending on how fast the WIFI board is, this should at least reduce your issues with hangs / slowdowns as delays are pretty much eliminated from you code.


----------



## HunterX

benjaf said:


> How have you handled the delay between data transmissions (the 10 second one at the end)? This does not have to be an actual delay, you could simply store the time at which data was last sent, and then send again when you think enough time has passed. 10 seconds seems somewhat unnecessary to me but then I don't know how much data you send.


As always, thank you for your reply. I really value your input. I had to go back and take a look at the original code to understand what you were talking about here. I removed the 10 second delay in my application. Instead, I use a "millis" function to run the wifi option every 5 minutes (300000 milliseconds). That part works flawlessly. 

I'm at the office now. When I get back to my room I will go over the other stuff you suggested. Thanks again!


----------



## benjaf

HunterX said:


> As always, thank you for your reply. I really value your input. I had to go back and take a look at the original code to understand what you were talking about here. I removed the 10 second delay in my application. Instead, I use a "millis" function to run the wifi option every 5 minutes (300000 milliseconds). That part works flawlessly.
> 
> I'm at the office now. When I get back to my room I will go over the other stuff you suggested. Thanks again!


You're welcome 
I figured you probably had that part covered, just wanted to be sure. When using millis you just need to be sure to take the rollover into account, otherwise you may find yourself stuck in a loop for a very long time.


----------



## HunterX

benjaf said:


> You're welcome
> I figured you probably had that part covered, just wanted to be sure. When using millis you just need to be sure to take the rollover into account, otherwise you may find yourself stuck in a loop for a very long time.


I actually found a library that takes care of that. 



Code:


<elapsedMillis.h>


----------



## HunterX

> First of all: If you have not yet put this whole 'send data' section into a function by itself, you should do so now.


I tried to do that but had an issue with the temperature floats. When I declared them globally, the code wouldn't compile. As you know if I can't declare the globally then I can't use them in a function. I'm sure there is an easy fix to this but I haven't dug too deep into it yet. 



> This section should also be escaped with a timeout like the other one, otherwise you can have an endless loop here as well:
> 
> 
> Code:
> 
> 
> while (ip == 0) {
> if (! cc3000.getHostByName(WEBSITE, &ip)) {
> Serial.println(F("Couldn't resolve!"));
> }
> delay(500);
> }



I did just that. Did I do it correctly? 



Code:


long startTime2 = millis();
          while (client.connected()) 
            {
              while (client.available()) 
              {
                char c = client.read();
                Serial.print(c);
                if(millis() > startTime2 + 10000 ) 
                   { 
                    break;                       
                   }
              }
            }





> I would also move the above delay inside the if() statement, there really is no reason to delay anything if the IP is resolved correctly.


Done!


----------



## scapegoat

how are you guys handling scheduling with the arduino? Are you running a command every so often to check time? or is there some event set up that fires off a function?


----------



## benjaf

HunterX said:


> I tried to do that but had an issue with the temperature floats. When I declared them globally, the code wouldn't compile. As you know if I can't declare the globally then I can't use them in a function. I'm sure there is an easy fix to this but I haven't dug too deep into it yet.


Well if the floats simply will not work for some reason, you can always pass them as parameters to the function. That is how you would normally do things elsewhere, global variables are often considered bad design in programming in general.



> I did just that. Did I do it correctly?


Yes, that looks just fine. But if you are using elapsedMillis the time keeping should be done a little differently, much like the example at playground.arduino.cc/


----------



## benjaf

scapegoat said:


> how are you guys handling scheduling with the arduino? Are you running a command every so often to check time? or is there some event set up that fires off a function?


Pretty much just checking every time the loop runs. That is the beauty of microcontrollers, you don't need to worry about wasting clock cycles - they have nothing better to do. If you wanted to you could use timer interrupts for some of it, but for the most part that is simply needlessly complicated.


----------



## scapegoat

benjaf said:


> Pretty much just checking every time the loop runs. That is the beauty of microcontrollers, you don't need to worry about wasting clock cycles - they have nothing better to do. If you wanted to you could use timer interrupts for some of it, but for the most part that is simply needlessly complicated.


does the entire program just run in a loop and execute procedurally (top to bottom restart loop at top)?


----------



## benjaf

scapegoat said:


> does the entire program just run in a loop and execute procedurally (top to bottom restart loop at top)?


Yes. You have a 'setup' section which is only run once, and a 'loop' section which is then executed top to bottom indefinitely. No such thing as 'idle time'!


----------



## HunterX

scapegoat said:


> how are you guys handling scheduling with the arduino? Are you running a command every so often to check time? or is there some event set up that fires off a function?


Below is the code to how I'm doing it. It has worked very well for me.



> //++++++++++++++++++ setup relay/outlet timers ++++++++++++++++++++
> //++++ Relay 1,2 will always be on and do not need a timer ++++++++
> //++++ Relay 5 is controlled by temp; does not need timer +++++++++
> if(feeding||systemInterupt||butt1) //+++++ relay1 (Filter) ++++++
> {
> digitalWrite(relay1, LOW);
> digitalWrite(buttonLed1, LOW);
> }
> else
> {
> digitalWrite(relay1, HIGH);
> digitalWrite(buttonLed1, HIGH);
> }
> if(feeding||systemInterupt||butt2) //+++++ relay2 (Filter) ++++++
> {
> digitalWrite(relay2, LOW);
> digitalWrite(buttonLed2, LOW);
> }
> else
> {
> digitalWrite(relay2, HIGH);
> digitalWrite(buttonLed2, HIGH);
> }
> if((RTC.getHours() >= 06 && RTC.getHours() <= 17)&&(!systemInterupt)&&(!feeding)&&(!butt3)) //+++++ relay3 (POWERHEAD) ++++++
> {
> digitalWrite(relay3, LOW);
> digitalWrite(buttonLed3, HIGH);
> }
> if((RTC.getHours() >=18||RTC.getHours() <=05)||(systemInterupt)||(feeding)||(butt3))
> {
> digitalWrite(relay3, HIGH);
> digitalWrite(buttonLed3, LOW);
> }
> if((RTC.getHours() >= 18 || RTC.getHours() <= 05)&&(!systemInterupt)&&(!feeding)&&(!butt4)) //+++++ relay4 (POWERHEAD) ++++++
> {
> digitalWrite(relay4, LOW);
> digitalWrite(buttonLed4, HIGH);
> }
> if((RTC.getHours()>=06 && RTC.getHours() <=17)||(systemInterupt)||(feeding)||(butt4))
> {
> digitalWrite(relay4, HIGH);
> digitalWrite(buttonLed4, LOW);
> }
> if(temperature1 < 78.00 && (!systemInterupt) && (!butt5) && (!feeding)) //+++++ relay5 (Heater) +++++++++++++
> {
> digitalWrite(relay5, LOW);
> digitalWrite(buttonLed5, HIGH);
> lcd.setCursor(12,0);
> lcd.print("HEATING");
> }
> else if(temperature1 > 79.50 || (systemInterupt) || (butt5) || (feeding))
> {
> digitalWrite(relay5, HIGH);
> digitalWrite(buttonLed5, LOW);
> lcd.setCursor(10,0);
> lcd.print(" ");
> }
> if((RTC.getHours() >= 18 || RTC.getHours() <= 06)&&(!systemInterupt)&&(!butt6)&&(!feeding)) //+++++ relay6 (Air Pump) ++++++
> {
> digitalWrite(relay6, LOW);
> digitalWrite(buttonLed6, HIGH);
> }
> else if((RTC.getHours() >= 07 || RTC.getHours() <= 17)||(systemInterupt)||(butt6)||(feeding))
> {
> digitalWrite(relay6, HIGH);
> digitalWrite(buttonLed6, LOW);
> }
> if((RTC.getHours() >= 07 && RTC.getHours() <= 16)&&(!systemInterupt)&&(!butt7)&&(!feeding)) //+++++ relay7 (CO2)++++++
> {
> digitalWrite(relay7, LOW);
> digitalWrite(buttonLed7, HIGH);
> }
> if((RTC.getHours() >= 17 || RTC.getHours() <= 06)||(systemInterupt)||(butt7)||(feeding))
> {
> digitalWrite(relay7, HIGH);
> digitalWrite(buttonLed7, LOW);
> }
> /*+++++++++ Relay 8 Currently not being used ++++++++++++++++
> if((RTC.getHours() >= 18 && RTC.getMinutes() >= 00)||(!systemInterupt)||(!butt8)) //+++++ relay8 ++++++
> {
> digitalWrite(relay8, LOW);
> digitalWrite(buttonLed8, HIGH);
> }
> if((RTC.getHours() >= 24 && RTC.getMinutes() >= 45)||(systemInterupt)||(butt8))
> {
> digitalWrite(relay8, HIGH);
> digitalWrite(buttonLed8, LOW);
> } */
> 
> //+++++++++++++++++++++ Control For Box Fan) +++++++++++++++++++++++++
> if(temperature0 > 77.00)
> {
> digitalWrite(fan4, HIGH);
> }
> else if(temperature0 < 74.00)
> {
> digitalWrite(fan4, LOW);
> }


----------



## HunterX

> Well if the floats simply will not work for some reason, you can always pass them as parameters to the function. That is how you would normally do things elsewhere, global variables are often considered bad design in programming in general.


 I took care of that by just pulling all the data again within the function. 



Code:


sensors.requestTemperatures();  // Send the command to get temperatures
  float temperature1 = sensors.getTempFByIndex(1); // Tank Temp
  float temperature0 = sensors.getTempFByIndex(0); // Box Temp  
  int temp1 = temperature1;
  int temp0 = temperature0;




> Yes, that looks just fine. But if you are using elapsedMillis the time keeping should be done a little differently, much like the example at playground.arduino.cc/


 I didn't use elapsedMillis for this just yet. I wanted to make sure it would work. Once I get it working I will use the elapsedMillis syntax. It isn't exiting the while loop in 10 seconds like it should. I'm going to keep playing with it.

I do have a question though. Now that I have the "wifi" stuff set as a function, would it be possible to exit that function, say after 120 seconds, even if its hung in a "WHILE" loop? It's my understand that if it's in the while loop it will not be looping to compare a time statement to exit if the appropriate amount of time has expired. What are you thoughts Ben?



Code:


if (timer0 > interval)
       {
         wifi();
         timer0 = 0;   //resets the time to 0 so the counting starts over 
       }


----------



## benjaf

HunterX said:


> I do have a question though. Now that I have the "wifi" stuff set as a function, would it be possible to exit that function, say after 120 seconds, even if its hung in a "WHILE" loop? It's my understand that if it's in the while loop it will not be looping to compare a time statement to exit if the appropriate amount of time has expired. What are you thoughts Ben?
> 
> 
> 
> Code:
> 
> 
> if (timer0 > interval)
> {
> wifi();
> timer0 = 0;   //resets the time to 0 so the counting starts over
> }


Unfortunately that is not going to work. Making it do something that is not part of the currently executed code, like you describe, would require a timer interrupt, and I don't think it is possible to use interrupts to interfere with the execution of other code. You will have to identify where the code could be hanging and then introduce a break condition each of those places. This is strictly single threaded execution, so that kind of 'management' is unfortunately not really possible.
The closest you get is a watchdog timer, but that will reset the device after a set amount of time without interaction..


----------



## HunterX

benjaf said:


> Unfortunately that is not going to work. Making it do something that is not part of the currently executed code, like you describe, would require a timer interrupt, and I don't think it is possible to use interrupts to interfere with the execution of other code. You will have to identify where the code could be hanging and then introduce a break condition each of those places. This is strictly single threaded execution, so that kind of 'management' is unfortunately not really possible.
> The closest you get is a watchdog timer, but that will reset the device after a set amount of time without interaction..


 
Bummer! That would be ideal if it would work. Back to the drawing board.


----------



## O2surplus

HunterX said:


> Bummer! That would be ideal if it would work. Back to the drawing board.


Please forgive my ignorance if this is all wrong, but wouldn't it be easier to use a second Micro-controller to act as a "slave" to the Mega. The slave could be programmed to handle all the WiFi connection tasks, and simply pass data to the Mega when needed? Would this be a practical solution to the problem and prevent the Mega from hanging?


----------



## benjaf

O2surplus said:


> Please forgive my ignorance if this is all wrong, but wouldn't it be easier to use a second Micro-controller to act as a "slave" to the Mega. The slave could be programmed to handle all the WiFi connection tasks, and simply pass data to the Mega when needed? Would this be a practical solution to the problem and prevent the Mega from hanging?


Actually, that is a very good idea. It is not a lot of data to transfer so soft serial is fine, and not a lot of code / pins on the slave so any cheap arduino-compatible board will do. A separate controller means you can simply command it to send the data and occasionally check if it succeeded. You could then possibly use a watchdog on the slave to make sure it is reset if it somehow enters a state it can not get out of. I like your thinking O2 (and your controllers, but that is a different matter!)


----------



## O2surplus

benjaf said:


> Actually, that is a very good idea. It is not a lot of data to transfer so soft serial is fine, and not a lot of code / pins on the slave so any cheap arduino-compatible board will do. A separate controller means you can simply command it to send the data and occasionally check if it succeeded. You could then possibly use a watchdog on the slave to make sure it is reset if it somehow enters a state it can not get out of. I like your thinking O2 (and your controllers, but that is a different matter!)


Cool- I'm happy to hear that my idea's a viable solution to the problem LOL. I can't help much with the software side of these projects but I'd love to design a "Mega-slave WiFi shield" or other hardware needed. :icon_smil Here's a "Mega Screw Shield" that I designed a few months back. I could modify this to include the WiFi bits and an extra Atmega328 to act as the "slave". All I need from you guys is a wiring diagram/arduino pinout. LOL


----------



## JoeFL77

Gentlemen,
Please pardon the interruption. I think the solution has already been found. Folks have been using the technology to control their BBQ smokers. Basically, the Arduino does the control while the RaspberryPi handles the display and Wi-Fi. It is called a HeaterMeter v4.0 for RaspberyPi / Standalone.
Here are some links:
http://tvwbb.com/showthread.php?35674-HeaterMeter-v4-0-for-RaspberyPi-Standalone
https://github.com/CapnBry/HeaterMeter/wiki
Google heatermeter 4.0
The projects are called categorized as BBQ Automatic Temperature Control (ATC). The forum in Weber has many huge threads (TVWBB).
I have a Comp Sci degree from 1979 and I love to play with hardware and software. My son is a avionics tech and helps me with hardware. I have more ideas than time or energy but I am getting better.
I hope this might help. Let me know if I can help more so you won't have to spend too much time reading and searching threads.
Joe


----------



## epicfail

benjaf said:


> Please note that these boards have no current limiting resistor between the arduino and the mosfet. You will need to add one to avoid long term damage to your arduino!
> 
> EDIT: If you are swithing it once a day you may not see damage any time soon. But if you do PWM it is very important!


If you are using Meanwell's LDD-H drivers with an Arduino do you need some sort of protection between the driver and the Arduino? If so what would it need to be?


----------



## mistergreen

O2surplus said:


> Please forgive my ignorance if this is all wrong, but wouldn't it be easier to use a second Micro-controller to act as a "slave" to the Mega. The slave could be programmed to handle all the WiFi connection tasks, and simply pass data to the Mega when needed? Would this be a practical solution to the problem and prevent the Mega from hanging?


It's better and cheaper to use a rasberry pi as the web server and use the arduino as the slave to do its thing.


Sent from my iPad using Tapatalk HD


----------



## benjaf

epicfail said:


> If you are using Meanwell's LDD-H drivers with an Arduino do you need some sort of protection between the driver and the Arduino? If so what would it need to be?


Most likely not. The thing with MOSFETs is that they act as an open drain for a moment when switched on, just like a cap. This draws considerably more current than the Arduino can safely deliver, causing long-term damage to the microcontroller.
The PWM input of the drivers are highly unlikely to behave like this, so you should be fine without protection.


----------



## benjaf

mistergreen said:


> It's better and cheaper to use a rasberry pi as the web server and use the arduino as the slave to do its thing


I agree that a natively Ethernet-capable device would be a better choice for the master. However, at this point it would mean a complete rewrite of all his controller code. Upgrading to a RasPi or BeagleBoard would be more of a version 2 thing in my opinion.


----------



## salman

HunterX said:


> I soldered them between the wire connections running to the motors. The side of the DIOD with the black line should be soldered to the positive wire. Have you started any "code" yet?


What diode are you using for fan and motors?


----------



## bigd603

Any one made any progress they would care to share?

Sent from my Galaxy Nexus using Tapatalk


----------



## HunterX

bigd603 said:


> Any one made any progress they would care to share?
> 
> Sent from my Galaxy Nexus using Tapatalk


Hey bigd,

Sorry I haven't been able to do anything with it in about a month. I redeploy back to the states in May. I have been super busy tracking and training our replacements. 

I was never able to prevent the wifi adaptor from freezing up. When I get some time that is what I will be working on. Everything else has performed as expected.


----------



## Fluffles

Hi!
I've actually made some good progress over the last 2 months. I haven't posted anything on the forums since there seems to be several Arduino projects going on and I feel I don't really have anything new to contribute. 

At this point I'm done hooking up everything and just started coding 2 days ago. This project is a clone to HunterX's project, but I have a slightly smaller box and I changed a few things to suit my needs.
Still undecided on potentially adding 5050 LEDs for sunrise, sunset, and moonlight. Unfortunately, no real space left for DIN connectors incase I decide to add more stuff in the future.










See album pictures
 
Credits:
HunterX - Original design. I would not be doing this if he didn't post his work earlier. Seems like he also inspired several other members to get started on their own controllers.
Chiefston - Posted his code on another thread and I've learned a lot from it. Probably saved me 10s of hours trying to figure out how to code for certain things (e.g. reading and writing to RTC RAM)
And everyone else in this thread

Thanks again to all those involved.


----------



## pianofish

Pretty pumped. I just finished purchasing most only parts for this build. I'll be adding on and editing the design though. Using a pic18 MCU as a slave to rasPi instead of an arduino. I'll also be adding additional temp probes, and ph probe. It will also be controlling my DIY t5ho dimmable build, and eventually my drip water changer in my sump. I'll be posting here to collaborate as my build progresses. 
Thanks everyone for the inspiration and beginning designs. 
Joshua


----------



## scapegoat

gorgeous!

my controller is sitting on my work bench. I'm still figuring out how to stuff everything into a 9" x 9" space.


----------



## bigd603

Fluffles, great job in the controller! What's the overall size of the box?

Sent from my Galaxy Nexus using Tapatalk


----------



## Fluffles

Outside dimensions for the box are 13"Lx11"Wx4"H
Inside dimensions are 12.25"Lx10.5"Wx3.5"H

It's not too much smaller than Hunter's box, but with all these components and wires inside the box, space is at a premium.


----------



## HunterX

Fluffles,

Great job on the box. It looks great. If you are interested I can send you my code. It may help out some.


----------



## drewsuf82

Wow is all I have to say....makes me want to learn lol


----------



## bigd603

drewsuf82 said:


> Wow is all I have to say....makes me want to learn lol


Do it, Drew! The beauty of Arduino is that it's so easy to learn, and there is so much help available out there. It's a really fun and rewarding hobby. 

Sent from my Galaxy Nexus using Tapatalk


----------



## Fluffles

Thanks everyone!



HunterX said:


> Fluffles,
> 
> Great job on the box. It looks great. If you are interested I can send you my code. It may help out some.


That would be great! It would be great to see how you approached buttons and LEDs, scheduling, and dosing. I can also share my code if you're interested, but it's still in very early stages.

Right now my code can only keep track of buttons status so there's not much work done with scheduling yet. I'm trying to make it so that each button has 3 states: ON-OFF-AUTO

If a button is depressed, it will turn the relay OFF and LED OFF.
If a button is pressed once, it will turn the relay ON and LED ON
When a button is pressed for a second time, it will allow the relay to enter AUTO mode and let the scheduler take over. But how do you know that relay is in AUTO? The button LED will blink on and off once a second.
In short a button will work like this: ON-OFF-AUTO-OFF-ON-OFF-AUTO...etc
It's been a pain to code, but I think I finally have it working. This should give me absolute control over each relay no matter what the scheduler is trying to do.


----------



## JoeFL77

Dear HunterX,
Could you send me the code too or post it. I am trying to do the same thing. I looked at Chad's and would like to see another approach. 
Thanks
Joe


----------



## Bryanmc1988

i would like to take a look at this code also if you dont mind sharing... i can take a look and see how this code is constructed...


----------



## HunterX

Fluffles said:


> Thanks everyone!
> 
> 
> 
> That would be great! It would be great to see how you approached buttons and LEDs, scheduling, and dosing. I can also share my code if you're interested, but it's still in very early stages.
> 
> Right now my code can only keep track of buttons status so there's not much work done with scheduling yet. I'm trying to make it so that each button has 3 states: ON-OFF-AUTO
> 
> If a button is depressed, it will turn the relay OFF and LED OFF.
> If a button is pressed once, it will turn the relay ON and LED ON
> When a button is pressed for a second time, it will allow the relay to enter AUTO mode and let the scheduler take over. But how do you know that relay is in AUTO? The button LED will blink on and off once a second.
> In short a button will work like this: ON-OFF-AUTO-OFF-ON-OFF-AUTO...etc
> It's been a pain to code, but I think I finally have it working. This should give me absolute control over each relay no matter what the scheduler is trying to do.


Sorry for not replying sooner. I have been TDY with the Army. Now I'm back to Kuwait so this evening I should be able to send my code out. It's complete with the exception of the LED controls. I don't have anything here to trouble shot that so I will wait until I get home.

Fluffles,

You are way over programming those buttons. I'll show you how simple it can be by using booleans. You are going to laugh at how much easier it will be.


----------



## HunterX

I will post my code here so everyone can take a look at it!


----------



## Bryanmc1988

what board are you using for your setup?


----------



## HunterX

Bryanmc1988 said:


> what board are you using for your setup?


Mega. The parst list in included in post #13.


----------



## HunterX

*Tank Code*

Here it is. Enjoy. 



Code:


#include <Wire.h>
#include <RealTimeClockDS1307.h> //RealTimeClock RTC;//=new RealTimeClock();
#include <LiquidCrystal_I2C.h>
#include <DallasTemperature.h>
#include <OneWire.h>
#include <elapsedMillis.h>

#define ONE_WIRE_BUS 2 // Temp Sensor Connected to Pin 2 //
#define Display_Clock_Every_N_Seconds 1
#define Display_ShortHelp_Every_N_Seconds 25
//#define TEST_Squarewave
//#define TEST_StopStart
//#define TEST_1224Switch

// Set up a oneWire instance to communicate with any OneWire device//
OneWire ourWire(ONE_WIRE_BUS);

// Tell Dallas Temperature Library to use oneWire Library //
DallasTemperature sensors(&ourWire);

// Define Address for each Tempatature Sensor//
DeviceAddress Probe01 = { 0x28, 0x54, 0xF2, 0x04, 0x05, 0x00, 0x00, 0xF2 }; //box temp address//
DeviceAddress Probe02 = { 0x28, 0x73, 0x05, 0x21, 0x05, 0x00, 0x00, 0xC7 }; //tank temp address//

int count = 0;

int relay1 = 45; // relay 1 connected to digital pin 45 FILTER
int relay2 = 44; // relay 2 connected to digital pin 44 FILTER
int relay3 = 43; // relay 3 connected to digital pin 43 POWERHEAD
int relay4 = 42; // relay 4 connected to digital pin 42 POWERHEAD
int relay5 = 41; // relay 5 connected to digital pin 41 HEATER 
int relay6 = 40; // relay 6 connected to digital pin 40 AIR PUMP
int relay7 = 39; // relay 7 connected to digital pin 39 CO2
int relay8 = 38; // relay 8 connected to digital pin 38

int buttonLed1 = 22; // button 1 LED connected to digital pin 22  All use a 220 Ohm resistor
int buttonLed2 = 23; // button 2 LED connected to digital pin 23
int buttonLed3 = 24; // button 3 LED connected to digital pin 24
int buttonLed4 = 25; // button 4 LED connected to digital pin 25
int buttonLed5 = 26; // button 5 LED connected to digital pin 26
int buttonLed6 = 27; // button 6 LED connected to digital pin 27
int buttonLed7 = 28; // button 7 LED connected to digital pin 28
int buttonLed8 = 29; // button 8 LED connected to digital pin 29
int interuptLed1 = 48; //system interupt led connected to digital pin 48
int interuptLed2 = 49; // light interupt led connected to digital pin 49

int button1 = 30; // button 1 connected to digital pin 30  All use a 10K Ohm Resistor
int button2 = 31; // button 2 connected to digital pin 31
int button3 = 32; // button 3 connected to digital pin 32
int button4 = 33; // button 4 connected to digital pin 33
int button5 = 34; // button 5 connected to digital pin 34
int button6 = 35; // button 6 connected to digital pin 35
int button7 = 36; // button 7 connected to digital pin 36
int button8 = 37; // button 8 connected to digital pin 37
int button9 = 46; // system interupt button connected to digital pin 46
int button10 = 47; // light interupt button connected to digital pin 47

int macro1 = 14;   // dc motor 1 connectd to digital pin 30 - MACRO FERTS
int micro2 = 15;   // dc motor 1 connectd to digital pin 31 - MICRO FERTS
int fe3 = 16; // dc motor 1 connectd to digital pin 32 - FE FERTS
int fan4 = 17;   // dc motor 1 connectd to digital pin 33 - BOX Cooling Fan

int led1 = 8;  //led tank lights 1 connnected to PWM pin 8   Warm White 3200K (growth spectrum)
int led2 = 9;  //led tank lights 2 connnected to PWM pin 9   Cool WHite 6500K (base white spectrum)
int led3 = 10; //led tank lights 3 connnected to PWM pin 10  Deep Red / Royal Blue (enhanced growth and color)
int led4 = 11; //led tank lights 4 connnected to PWM pin 11  Cool WHite 6500K (base white spectrum)
int led5 = 12; //led tank lights 5 connnected to PWM pin 12  Warm White 3200K (growth spectrum)

//elapsedMillis timer0;
//#define interval 30000

char formatted[] = "00-00-00 00:00:00x";
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

boolean feeding = false;         // boolean used to tell system if feeding or not
boolean systemInterupt = false;  // boolean used to tell if system interupt button is pressed
boolean lightInterupt = false;   // boolean used to tell if light interupt button is pressed
boolean butt1 = false;           // boolean used to tell if button 1 is pressed
boolean butt2 = false;           // boolean used to tell if button 2 is pressed
boolean butt3 = false;           // boolean used to tell if button 3 is pressed 
boolean butt4 = false;           // boolean used to tell if button 4 is pressed
boolean butt5 = false;           // boolean used to tell if button 5 is pressed
boolean butt6 = false;           // boolean used to tell if button 6 is pressed
boolean butt7 = false;           // boolean used to tell if button 7 is pressed
boolean butt8 = false;           // boolean used to tell if button 8 is pressed

////////////////////////////////////////////////
//                SETUP BEGINS                //
////////////////////////////////////////////////

void setup()
{
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  pinMode(relay3, OUTPUT);
  pinMode(relay4, OUTPUT);
  pinMode(relay5, OUTPUT);
  pinMode(relay6, OUTPUT);
  pinMode(relay7, OUTPUT);
  pinMode(relay8, OUTPUT); 
  
  pinMode(macro1, OUTPUT);
  pinMode(micro2, OUTPUT);
  pinMode(fe3, OUTPUT);
  pinMode(fan4, OUTPUT); 
  
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  
  pinMode(buttonLed1, OUTPUT);
  pinMode(buttonLed2, OUTPUT);
  pinMode(buttonLed3, OUTPUT);
  pinMode(buttonLed4, OUTPUT);
  pinMode(buttonLed5, OUTPUT);
  pinMode(buttonLed6, OUTPUT);
  pinMode(buttonLed7, OUTPUT);
  pinMode(buttonLed8, OUTPUT);
  pinMode(interuptLed1, OUTPUT);
  pinMode(interuptLed2, OUTPUT);
  
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  pinMode(button3, INPUT);
  pinMode(button4, INPUT);
  pinMode(button5, INPUT);
  pinMode(button6, INPUT);
  pinMode(button7, INPUT);
  pinMode(button8, INPUT);  
  pinMode(button9, INPUT);
  pinMode(button10,INPUT); 
  
 
  
  digitalWrite(relay1, HIGH); // Wired as normally closed //
  digitalWrite(relay2, HIGH); // Wired as normally closed //
  digitalWrite(relay3, HIGH);
  digitalWrite(relay4, HIGH);
  digitalWrite(relay5, HIGH);
  digitalWrite(relay6, HIGH);
  digitalWrite(relay7, HIGH);
  digitalWrite(relay8, HIGH);  

  sensors.begin();
  sensors.setResolution(Probe01, 12);
  sensors.setResolution(Probe02, 12);
  Wire.begin();
  Serial.begin(9600);  
  lcd.begin(20,4);          //initialize LCD for 20 CHAR 4 lines, turn on backlight
  
  for(int i = 0; i< 3; i++) //3 quick blinks of backlight
    {
      lcd.backlight();
      delay(250);
      lcd.noBacklight();
      delay(250);
    }  
  lcd.backlight();         // finish with back light on
  
  lcd.setCursor(3,1);      //Start character 3 on line 1
  lcd.print("Darrin's Tank");
  delay(1000);
  lcd.setCursor(2,2);
  lcd.print("Controller 1.0");
  delay(4000); 
  lcd.clear();   
}

/////////////////////////////////////////////////
//                LOOP BEGINS                  //
/////////////////////////////////////////////////
 
void loop() 
{    
  RTC.readClock(); 
  
  //******************* display time on lcd +++++++++++++++++++++++++ 
  lcd.setCursor(8,3);
  if (RTC.getHours()<10)         //adds a "0" in front of all numbers less than 10
    {     
    lcd.print(0);
    }
  lcd.print(RTC.getHours());     //gets hour from RTC and displays on LCD    
  lcd.setCursor(10,3); 
  lcd.print(":");
  lcd.setCursor(11,3);
  if (RTC.getMinutes()<10)       //adds a "0" in front of all numbers less than 10
    {
    lcd.print(0);
    }
  lcd.print(RTC.getMinutes());   //gets minutes from RTC and displays on LCD
 
  //++++++++++++++++++ displays temp on LCD ++++++++++++++++++++++++++
  sensors.requestTemperatures();  // Send the command to get temperatures
  float temperature1 = sensors.getTempFByIndex(1); // Tank Temp
  float temperature0 = sensors.getTempFByIndex(0); // Box Temp  
  lcd.setCursor(0,0);
  lcd.print("H2O:");
  lcd.setCursor(4,0);    
  lcd.print(temperature1);  //displays TANK temp in F on LCD
  lcd.setCursor(0,1);
  lcd.print("Box:");
  lcd.setCursor(4,1);  
  lcd.print(temperature0);   //displays BOX temp in F on LCD
  
  //+++++++++++++++++++ functions ++++++++++++++++++++++++++++++++++++
    //heater();      //function used to display "HEATING" when relay5 (heater) is on
    sysInterupt(); 
    liteInterupt(); 
    
  //++++++++++++++++++ setup relay/outlet timers ++++++++++++++++++++
  //++++ Relay 1,2 will always be on and do not need a timer ++++++++
  //++++ Relay 4 is controlled by temp; does not need timer +++++++++
  if(feeding||systemInterupt||butt1)      //+++++ relay1 (Filter) ++++++
    {
    digitalWrite(relay1, LOW);
    digitalWrite(buttonLed1, LOW);   
    }
  else
    {
    digitalWrite(relay1, HIGH);
    digitalWrite(buttonLed1, HIGH);    
    }
  if(feeding||systemInterupt||butt2)      //+++++ relay2 (Filter) ++++++
    {
    digitalWrite(relay2, LOW); 
    digitalWrite(buttonLed2, LOW);  
    }
  else
    {
    digitalWrite(relay2, HIGH);
    digitalWrite(buttonLed2, HIGH);    
    }  
  if((RTC.getHours() >= 06 && RTC.getHours() <= 17)&&(!systemInterupt)&&(!feeding)&&(!butt3))  //+++++ relay3 (POWERHEAD) ++++++
    {
    digitalWrite(relay3, LOW);
    digitalWrite(buttonLed3, HIGH);   
    }
  if((RTC.getHours() >=18||RTC.getHours() <=05)||(systemInterupt)||(feeding)||(butt3))
    {
    digitalWrite(relay3, HIGH);
    digitalWrite(buttonLed3, LOW);
    }  
  if((RTC.getHours() >= 18 || RTC.getHours() <= 05)&&(!systemInterupt)&&(!feeding)&&(!butt4))   //+++++ relay4 (POWERHEAD) ++++++
    {
    digitalWrite(relay4, LOW);
    digitalWrite(buttonLed4, HIGH);  
    }
  if((RTC.getHours()>=06 && RTC.getHours() <=17)||(systemInterupt)||(feeding)||(butt4))
    {
    digitalWrite(relay4, HIGH);
    digitalWrite(buttonLed4, LOW);
    } 
  if(temperature1 < 78.00 && (!systemInterupt) && (!butt5) && (!feeding))     //+++++ relay5 (Heater) +++++++++++++
    {
    digitalWrite(relay5, LOW);
    digitalWrite(buttonLed5, HIGH);
    lcd.setCursor(12,0);
    lcd.print("HEATING");
    }
    else if(temperature1 > 79.50 || (systemInterupt) || (butt5) || (feeding))
    {
    digitalWrite(relay5, HIGH);
    digitalWrite(buttonLed5, LOW);
    lcd.setCursor(10,0); 
    lcd.print("          ");
    }    
  if((RTC.getHours() >= 18 || RTC.getHours() <= 06)&&(!systemInterupt)&&(!butt6)&&(!feeding)) //+++++ relay6 (Air Pump) ++++++
    {
    digitalWrite(relay6, LOW);
    digitalWrite(buttonLed6, HIGH);    
    }
  else if((RTC.getHours() >= 07 || RTC.getHours() <= 17)||(systemInterupt)||(butt6)||(feeding))
    {
    digitalWrite(relay6, HIGH);
    digitalWrite(buttonLed6, LOW);    
    }
  if((RTC.getHours() >= 07 && RTC.getHours() <= 16)&&(!systemInterupt)&&(!butt7)&&(!feeding))  //+++++ relay7 (CO2)++++++
    {
    digitalWrite(relay7, LOW);
    digitalWrite(buttonLed7, HIGH);    
    }
  if((RTC.getHours() >= 17 || RTC.getHours() <= 06)||(systemInterupt)||(butt7)||(feeding))
    {
    digitalWrite(relay7, HIGH); 
    digitalWrite(buttonLed7, LOW);   
    } /* 
  if((RTC.getHours() >= 18 && RTC.getMinutes() >= 00)||(!systemInterupt)||(!butt8))  //+++++ relay8 ++++++
    {
    digitalWrite(relay8, LOW);
    digitalWrite(buttonLed8, HIGH);
    }
  if((RTC.getHours() >= 24 && RTC.getMinutes() >= 45)||(systemInterupt)||(butt8))
    {
    digitalWrite(relay8, HIGH);
    digitalWrite(buttonLed8, LOW);
    }  */
    
//+++++++++++++++++++++ Control For Box Fan) +++++++++++++++++++++++++   
  
  if(temperature0 > 77.00)      
    {
    digitalWrite(fan4, HIGH);    
    }
    else if(temperature0 < 74.00)
    {
    digitalWrite(fan4, LOW);    
    }       
   
//++++++++++++++++++++ SETUP DOSING PUMP TIMER ++++++++++++++++++++++
  if((RTC.getDayOfWeek()==2 || RTC.getDayOfWeek()==4 || RTC.getDayOfWeek()==6)&&(RTC.getHours()==6)
  &&(RTC.getMinutes()==30)&&(RTC.getSeconds()>=5)&&(RTC.getSeconds()<=10))    //+++++ dose macro ferts on MON, WED, FRI
    { 
      digitalWrite(macro1, HIGH);      
    }
    else
    {
      digitalWrite(macro1, LOW);
    }  
  if((RTC.getDayOfWeek() ==3 || RTC.getDayOfWeek()==5 || RTC.getDayOfWeek()==7)&&(RTC.getHours()==6)
  &&(RTC.getMinutes()==30)&&(RTC.getSeconds()>=5)&&(RTC.getSeconds()<=10))   //+++++ dose micro ferts on TUE, THUR, SAT
    { 
      digitalWrite(micro2, HIGH);
    }
    else
    {
      digitalWrite(micro2, LOW);
    } 
   if((RTC.getDayOfWeek() ==3 || RTC.getDayOfWeek()==5 || RTC.getDayOfWeek()==7)&&(RTC.getHours()==6)
   &&(RTC.getMinutes()==5)&&(RTC.getSeconds()>=5)&&(RTC.getSeconds()<=10))
    { 
      digitalWrite(fe3, HIGH);
    }
    else
    {
      digitalWrite(fe3, LOW);
    }  
//++++++++++++++++++++SETUP AUTO FEEDER SCHEDULE ++++++++++++++++++++
  if((RTC.getHours() == 7 || RTC.getHours() == 17)&&(RTC.getMinutes() >= 30)&&(RTC.getMinutes() <= 34))
      {
      feeding = true;     
      lcd.setCursor(12,1);
      lcd.print("FEEDING");
      }
    else
      {
      feeding = false;   
      lcd.setCursor(12,1);
      lcd.print("       ");
      } 
    
//+++++++++++++++++++SETUP BUTTON STATES ++++++++++++++++++++++++++++
  int buttonstate1 = 0;
  buttonstate1 = digitalRead(button1);
  if(buttonstate1 == HIGH)
    {
      butt1=true;      
    }
    else if (buttonstate1 == LOW)
    {
      butt1=false;      
    }  
  int buttonstate2 = 0;
  buttonstate2 = digitalRead(button2);
  if(buttonstate2 == HIGH)
    {
      butt2=true;      
    }
    else if (buttonstate2 == LOW)
    {
      butt2=false;      
    }  
  int buttonstate3 = 0;
  buttonstate3 = digitalRead(button3);
  if(buttonstate3 == HIGH)
    {
      butt3=true;      
    }
    else if (buttonstate3 == LOW)
    {
      butt3=false;      
    }  
  int buttonstate4 = 0;
  buttonstate4 = digitalRead(button4);
  if(buttonstate4 == HIGH)
    {
      butt4=true;      
    }
    else if (buttonstate4 == LOW)
    {
      butt4=false;      
    }   
  int buttonstate5 = 0;
  buttonstate5 = digitalRead(button5);
  if(buttonstate5 == HIGH)
    {
      butt5=true;      
    }
    else if (buttonstate5 == LOW)
    {
      butt5=false;      
    }   
  int buttonstate6 = 0;
  buttonstate6 = digitalRead(button6);
  if(buttonstate6 == HIGH)
    {
      butt6=true;      
    }
    else if (buttonstate6 == LOW)
    {
      butt6=false;      
    }   
  int buttonstate7 = 0;
  buttonstate7 = digitalRead(button7);
  if(buttonstate7 == HIGH)
    {
      butt7=true;      
    }
    else if (buttonstate7 == LOW)
    {
      butt7=false;      
    }
  int buttonstate8 = 0;
  buttonstate8 = digitalRead(button8);
  if(buttonstate8 == HIGH)
    {
      butt8=true;      
    }
    else if (buttonstate8 == LOW)
    {
      butt8=false;      
    }
//++++++++++++++++++++ USED TO CONTROL DS1307 RTC +++++++++++++++++++

  /*if(Serial.available())  +++++ Commented out to free up Serial Monitor for Debugging Must be active to set time
  {
    processCommand();
  }
  delay(1000);*/
  
  /*count++;
  if(count % Display_Clock_Every_N_Seconds == 0)
  {    
    Serial.print(count);
    Serial.print(": ");
    RTC.getFormatted(formatted);
    Serial.print(formatted);
    Serial.println();       
  }
  
  if(count % Display_ShortHelp_Every_N_Seconds == 0)
  {
    Serial.println("Send ? for a list of commands.");
  }
  
#ifdef TEST_Squarewave
if(count%10 == 0)
{
  switch(count/10 % 6)
  {
    case 0:
    Serial.print("Squarewave disabled (low impedance): ");
    RTC.sqwDisable(0);
    Serial.println((int) RTC.readData(7));
    break;
    case 1:
    Serial.print("Squarewave disabled (high impedance): ");
    RTC.sqwDisable(1);
    Serial.println((int) RTC.readData(7));
    break;
    case 2:
    Serial.println("Squarewave enabled at 1 Hz");
    RTC.sqwEnable(RTC.SQW_1Hz);
    break;
    case 3:
    Serial.println("Squarewave enabled at 4.096 kHz");
    RTC.sqwEnable(RTC.SQW_4kHz);
    break;
    case 4:
    Serial.println("Squarewave enabled at 8.192 kHz");
    RTC.sqwEnable(RTC.SQW_8kHz);
    break;
    case 5:
    Serial.println("Squarewave enabled at 32.768 kHz");
    RTC.sqwEnable(RTC.SQW_32kHz);
    break;
    default:
    Serial.println("Squarewave test not defined");
  }//switch
}
#endif

#ifdef TEST_StopStart
if(count%10 == 0)
{
  if(!RTC.isStopped()) 
  {
    if(RTC.getSeconds() < 45) 
    {
      Serial.println("Stopping clock for 10 seconds");
      RTC.stop();
    }//if we have enough time
  } else {
    RTC.setSeconds(RTC.getSeconds()+11);
    RTC.start();
    Serial.println("Adding 11 seconds and restarting clock");
  }
}//if on a multiple of 10 counts
#endif 

#ifdef TEST_1224Switch  
  if(count%10 == 0)
  {
    if(count %20 == 0)
    {
      Serial.println("switching to 12-hour time");
      RTC.switchTo12h();
      RTC.setClock();
    }
    else
    {
      Serial.println("switching to 24-hour time");
      RTC.switchTo24h();
      RTC.setClock();
    }
  } 
#endif  +++++ Commented out to free up Serial Monitor for Debugging Must be active to set time */
} 

/////////////////////////////////////////////////
//             FUNCTIONS BEGINS                //
/////////////////////////////////////////////////

//++++++++++++++++++ AUTO FEEDER FUNCTION +++++++++++++++++++++++++++
/*
void autoFeeder()
    {    
      lcd.setCursor(12,1);
      lcd.print("FEEDING");
    } 
 */ 
//++++++++++++++++++ HEATER FUNCTION++++++++++++++++++++++++++++++++
/*void heater()
    {
     if (digitalRead (relay5) == LOW)
      {
       lcd.setCursor(12,0);
       lcd.print("HEATING");
      }
     else
      {
       lcd.setCursor(10,0); 
       lcd.print("          ");
      }
    } */
//+++++++++++++++++ SYSTEM INTERUPT FUNCTION +++++++++++++++++++++++
void sysInterupt()
   {
     int buttonstate = 0;
     buttonstate = digitalRead(button9);
   if (buttonstate == HIGH)
     {
       systemInterupt = true;
       digitalWrite(interuptLed1, HIGH);
       lcd.setCursor(10,0);
       lcd.print("*INTERUPT*");
       
     }
   else if (buttonstate == LOW)
     {   
       systemInterupt = false;
       digitalWrite(interuptLed1, LOW);
     }
   } 

//+++++++++++++++++ LIGHT INTERUPT FUNCTION +++++++++++++++++++++++   

void liteInterupt()
   {
     int buttonstate = 0;
     buttonstate = digitalRead(button10);
   if (buttonstate == HIGH)
     {
       lightInterupt = true;
       digitalWrite(interuptLed2, HIGH);
       analogWrite(led1, 0);
       analogWrite(led2, 0);
       analogWrite(led3, 0);
       analogWrite(led4, 0);
       analogWrite(led5, 0);
     }
   else 
     {   
       lightInterupt = false;
       digitalWrite(interuptLed2, LOW);
     }
   }  
   
//+++++++++++++++++ RTC Process Command FUNCTION +++++++++++++++++++++++     
void processCommand()
{
  if(!Serial.available()) { return; }
  char command = Serial.read();
  int in,in2;
  switch(command)
  {
    case 'H':
    case 'h':
    in=SerialReadPosInt();
    RTC.setHours(in);
    RTC.setClock();
    Serial.print("Setting hours to ");
    Serial.println(in);
    break;
    case 'I':
    case 'i':
    in=SerialReadPosInt();
    RTC.setMinutes(in);
    RTC.setClock();
    Serial.print("Setting minutes to ");
    Serial.println(in);
    break;
    case 'S':
    case 's':
    in=SerialReadPosInt();
    RTC.setSeconds(in);
    RTC.setClock();
    Serial.print("Setting seconds to ");
    Serial.println(in);
    break;
    case 'Y':
    case 'y':
    in=SerialReadPosInt();
    RTC.setYear(in);
    RTC.setClock();
    Serial.print("Setting year to ");
    Serial.println(in);
    break;
    case 'M':
    case 'm':
    in=SerialReadPosInt();
    RTC.setMonth(in);
    RTC.setClock();
    Serial.print("Setting month to ");
    Serial.println(in);
    break;
    case 'D':
    case 'd':
    in=SerialReadPosInt();
    RTC.setDate(in);
    RTC.setClock();
    Serial.print("Setting date to ");
    Serial.println(in);
    break;
    case 'W':
    Serial.print("Day of week is ");
    Serial.println((int) RTC.getDayOfWeek());
    break;
    case 'w':
    in=SerialReadPosInt();
    RTC.setDayOfWeek(in);
    RTC.setClock();
    Serial.print("Setting day of week to ");
    Serial.println(in);
    break;
    
    case 't':
    case 'T':
    if(RTC.is12hour()) {
      RTC.switchTo24h();
      Serial.println("Switching to 24-hour clock.");
    } else {
      RTC.switchTo12h();
      Serial.println("Switching to 12-hour clock.");
    }
    RTC.setClock();
    break;
    
    case 'A':
    case 'a':
    if(RTC.is12hour()) {
      RTC.setAM();
      RTC.setClock();
      Serial.println("Set AM.");
    } else {
      Serial.println("(Set hours only in 24-hour mode.)");
    }
    break;
    
    case 'P':
    case 'p':
    if(RTC.is12hour()) {
      RTC.setPM();
      RTC.setClock();
      Serial.println("Set PM.");
    } else {
      Serial.println("(Set hours only in 24-hour mode.)");
    }
    break;

    case 'q':
    RTC.sqwEnable(RTC.SQW_1Hz);
    Serial.println("Square wave output set to 1Hz");
    break;
    case 'Q':
    RTC.sqwDisable(0);
    Serial.println("Square wave output disabled (low)");
    break;
    
    case 'z':
    RTC.start();
    Serial.println("Clock oscillator started.");
    break;
    case 'Z':
    RTC.stop();
    Serial.println("Clock oscillator stopped.");
    break;
    
    case '>':
    in=SerialReadPosInt();
    in2=SerialReadPosInt();
    RTC.writeData(in, in2);
    Serial.print("Write to register ");
    Serial.print(in);
    Serial.print(" the value ");
    Serial.println(in2);
    break;    
    case '<':
    in=SerialReadPosInt();
    in2=RTC.readData(in);
    Serial.print("Read from register ");
    Serial.print(in);
    Serial.print(" the value ");
    Serial.println(in2);
    break;

    default:
    Serial.println("Unknown command. Try these:");
    Serial.println(" h## - set Hours       d## - set Date");
    Serial.println(" i## - set mInutes     m## - set Month");
    Serial.println(" s## - set Seconds     y## - set Year");
    Serial.println(" w## - set arbitrary day of Week");
    Serial.println(" t   - toggle 24-hour mode");
    Serial.println(" a   - set AM          p   - set PM");
    Serial.println();
    Serial.println(" z   - start clock     Z   - stop clock");
    Serial.println(" q   - SQW/OUT = 1Hz   Q   - stop SQW/OUT");
    Serial.println();
    Serial.println(" >##,###  - write to register ## the value ###");
    Serial.println(" <##      - read the value in register ##");
    
  }//switch on command  
}

//read in numeric characters until something else
//or no more data is available on serial.
int SerialReadPosInt() 
 {
  int i = 0;
  boolean done=false;
  while(Serial.available() && !done)
  {
    char c = Serial.read();
    if (c >= '0' && c <='9')
    {
      i = i * 10 + (c-'0');
    }
    else 
    {
      done = true;
    }
  }
  return i;
}


----------



## Bryanmc1988

so from looking at the code it seems as if the auto dosing just checks and see's if the time and date matches with the set time/date in the script then turns it on?

my question is why not make it to where you can set/ change all this in the lcd and save it to the eeprom? wouldnt this save time from having to always upload and reload the script every time you want to change the date and time?


another question i have is how do you know how long the pump stays on or how many ml of dosing it will pump?



> if((RTC.getDayOfWeek()==2 || RTC.getDayOfWeek()==4 || RTC.getDayOfWeek()==6)&&(RTC.getHours()==6)
> &&(RTC.getMinutes()==30)&&(RTC.getSeconds()>=5)&&(RTC.getSeconds()<=10)) //+++++ dose macro ferts on MON, WED, FRI
> {
> digitalWrite(macro1, HIGH);
> }
> else
> {
> digitalWrite(macro1, LOW);
> }


as you can see it just says "High" or "Low" - i am assuming this just means "High" is sending 5vdc to the doing pump and "Low" means turn off the pump or provide 0vdc to the pump... but with the "Else" in between it will just check and if its on or off right? and if its off it will turn on and if its on it will turn off...


kinda confusing sorry if you dont understand what i am trying to ask xD... but shouldnt it be more like this?



> if((RTC.getDayOfWeek()==2 || RTC.getDayOfWeek()==4 || RTC.getDayOfWeek()==6)&&(RTC.getHours()==6)
> &&(RTC.getMinutes()==30)&&(RTC.getSeconds()>=5)&&(RTC.getSeconds()<=10)) //+++++ dose macro ferts on MON, WED, FRI
> {
> digitalWrite(macro1, HIGH);
> delay(1000); //delay for 1sec in millsec - this would keep the pump powered for 1 sec while its dosing...
> digitalWrite(macro1, LOW);
> }
> else
> {
> digitalWrite(macro1, LOW);
> }


----------



## HunterX

Bryanmc1988 said:


> so from looking at the code it seems as if the auto dosing just checks and see's if the time and date matches with the set time/date in the script then turns it on?
> 
> my question is why not make it to where you can set/ change all this in the lcd and save it to the eeprom? wouldnt this save time from having to always upload and reload the script every time you want to change the date and time?
> 
> 
> another question i have is how do you know how long the pump stays on or how many ml of dosing it will pump?
> 
> 
> 
> as you can see it just says "High" or "Low" - i am assuming this just means "High" is sending 5vdc to the doing pump and "Low" means turn off the pump or provide 0vdc to the pump... but with the "Else" in between it will just check and if its on or off right? and if its off it will turn on and if its on it will turn off...
> 
> 
> kinda confusing sorry if you dont understand what i am trying to ask xD... but shouldnt it be more like this?


 Look at the last part of my code. It is asking that if seconds is greater than or equal to 5 and less than or equal to 10, the pump will stay on. Effectively the pump will stay on for 6 seconds. That way I do not have to use a delay command. During a delay command the whole Arduino just waits. That means nothing else can happen while the delay is going on. They way I wrote the code always the Arduino to continue to cycle. It does not slow the program down. Why is that important? Say I want to push the button to shut one of the filters off while it is dosing FERTS. The Aruduino would not be able to read the button state and shut the filter off while stuck in a delay command.

As far as why do I have it on for 6 seconds. Based on test, it takes 6 seconds to pump the amount of fert I need.


----------



## Bryanmc1988

with that being said it makes lots of sense... but i'm not an expert on arduino and so how does the last part of your code work? i got a little confused trying to figure how that plays out lol sorry noob talk here xD



> if((RTC.getDayOfWeek()==2 || RTC.getDayOfWeek()==4 || RTC.getDayOfWeek()==6)&&(RTC.getHours()==6)
> &&(RTC.getMinutes()==30)&&(RTC.getSeconds()>=5)&&( RTC.getSeconds()<=10)) //+++++ dose macro ferts on MON, WED, FRI





> It is asking that if seconds is greater than or equal to 5 and less than or equal to 10, the pump will stay on


why does it need to be greater then or qual to 5 and less then or equal to 10? confused me here - wouldnt this only keep the pump on for 5 sec not 6?


----------



## bigd603

No worries Bryan, we're here to help you learn! So everytime the Arduino runs through the loop and it hits this if statement it is checking the day of the week, the hour, the minute, and the seconds. This code is telling the arduino that as long as the day is Monday, wednesday, or friday, the hour is 6am, the minute is thirty, and the second is ANYTHING BETWEEN AND INCLUDING 5 through 10 it will execute this if statement. When the arduino runs through the loop and the second is no longer between 5 and 10, it will not execute, move on to the else statement where the PWM is set to 0 effectively only allowing it to run for 6 seconds. The six seconds would have come from Hunter testing his pumps to determine how long it takes them to dose the proper amount of ferts.


----------



## bigd603

Bryanmc1988 said:


> why does it need to be greater then or qual to 5 and less then or equal to 10? confused me here - wouldnt this only keep the pump on for 5 sec not 6?


When counting the seconds you have to also include second 5. So seconds 5, 6, 7, 8, 9, and 10.


----------



## Bryanmc1988

ok that makes lots of sense now... thanks for clearing that up guys... xD i will need to put this doing code into a script for my arduino some time this week with a touch screen lcd tho menu and everything... no i am no expert but i will try and hope for the best lol



bigd603 said:


> No worries Bryan, we're here to help you learn! So everytime the Arduino runs through the loop and it hits this if statement it is checking the day of the week, the hour, the minute, and the seconds. This code is telling the arduino that as long as the day is Monday, wednesday, or friday, the hour is 6am, the minute is thirty, and the second is ANYTHING BETWEEN AND INCLUDING 5 through 10 it will execute this if statement. When the arduino runs through the loop and the second is no longer between 5 and 10, it will not execute, move on to the else statement where the PWM is set to 0 effectively only allowing it to run for 6 seconds. The six seconds would have come from Hunter testing his pumps to determine how long it takes them to dose the proper amount of ferts.


but i would like to know tho is why between 5-10 sec's? why not just do 1-6 sec then?


----------



## HunterX

bigd603 said:


> No worries Bryan, we're here to help you learn! So everytime the Arduino runs through the loop and it hits this if statement it is checking the day of the week, the hour, the minute, and the seconds. This code is telling the arduino that as long as the day is Monday, wednesday, or friday, the hour is 6am, the minute is thirty, and the second is ANYTHING BETWEEN AND INCLUDING 5 through 10 it will execute this if statement. When the arduino runs through the loop and the second is no longer between 5 and 10, it will not execute, move on to the else statement where the PWM is set to 0 effectively only allowing it to run for 6 seconds. The six seconds would have come from Hunter testing his pumps to determine how long it takes them to dose the proper amount of ferts.


Well Said Big D! Thanks


----------



## HunterX

Bryanmc1988 said:


> ok that makes lots of sense now... thanks for clearing that up guys... xD i will need to put this doing code into a script for my arduino some time this week with a touch screen lcd tho menu and everything... no i am no expert but i will try and hope for the best lol
> 
> 
> 
> but i would like to know tho is why between 5-10 sec's? why not just do 1-6 sec then?


Sure. That would work fine as well. It doesn't really matter.


----------



## Bryanmc1988

Ok just wondering if it was something that couldn't be done but I got it now thanks guys lets hope this works out xD


----------



## Fluffles

Thanks for posting you code Hunter. I finally had time to go through it today and I think I have a better idea of how I'm going to code my scheduler.
It's very easy to follow and well commented, thanks again.

I do have a question tho. Say that your powerhead #1 (relay3) automatically turns off at 5pm. What happens if you want to manually turn it on after 5pm?

Not sure if I read the code correctly or understand it completely, but it seems like your buttons can either turn a relay off OR allow the scheduler to take over. Do you consider the opposite where you might want force a relay on?

That's where I ran into the problem and started coding 3 states for each button: ON-OFF-AUTO (unless you don't care about forcing a relay ON)


----------



## HunterX

Fluffles said:


> Thanks for posting you code Hunter. I finally had time to go through it today and I think I have a better idea of how I'm going to code my scheduler.
> It's very easy to follow and well commented, thanks again.
> 
> I do have a question tho. Say that your powerhead #1 (relay3) automatically turns off at 5pm. What happens if you want to manually turn it on after 5pm?
> 
> Not sure if I read the code correctly or understand it completely, but it seems like your buttons can either turn a relay off OR allow the scheduler to take over. Do you consider the opposite where you might want force a relay on?
> 
> That's where I ran into the problem and started coding 3 states for each button: ON-OFF-AUTO (unless you don't care about forcing a relay ON)


You make a great point. I didn't think about needing to "force" a relay on. I think this can be done pretty easy by adding another "if" statement to the "if" statement that shuts the relay off. It would just ask it to check the Boolean to see if it is true. If it's true, turn the relay on. Let me play with it and I'll get something back to you. Thanks for pointing that out.


----------



## bigd603

Hey Guys,

SO I have been making a lot of good progress on my project (after not doing anything for far too long), and I have got the thing online, its serving data to a website hosted on a raspberry pi (check it out here, but keep in mind its still very early in development), and the site has graphs fed from Xively, but im having some issues with some timing aspects of my sketch. I want the arduino to to feed the data to Xively every ten seconds without using a delay command so the rest of the sketch doesn't get held up in the mean time. I'm using the millis method from the Blink Without Delay example. It works well for a while, but after several hours it stops the feed until i reset the Arduino. I think it has something to do with the millis crossing over, but I don't really know how to fix it. Anyone have any ideas? Here's my sketch:




Code:


#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
#include <Xively.h>
#include <SPI.h>
#include <Ethernet.h>
#include <HttpClient.h>


// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0x90, 0xA2, 0xDA, 0x0D, 0x26, 0x4E };
//IPAddress ip(192,168,0,14);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);



// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); 

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *macroPump = AFMS.getMotor(1);
// You can also make another motor on port M2
Adafruit_DCMotor *microPump = AFMS.getMotor(2);

//THIS SECTION TELLS ARDUINO THE ADDRESS OF THE TEMP SENSORS
#define ONE_WIRE_BUS 2 //temp is coming from pin 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress testProbe = { 
  0x28, 0xD5, 0xD7, 0xAA, 0x02, 0x00, 0x00, 0xC3 };
DeviceAddress testProbe2 = { 
  0x28, 0x05, 0x02, 0x84, 0x04, 0x00, 0x00, 0x3F };
float tempTest;
float tempTest2;
//END OF TEMP SENSORS SECTION

/////XIVELY
// Your Xively key to let you upload data
char xivelyKey[] = "8Ot0JKtOfqg7yLaG9QhNN5s3HSqbPl9WnO7c4wrBptpiq6ER";
//your xively feed ID
#define xivelyFeed 835109294
//datastreams
char sensorID[] = "TankTemp";
char resID[] = "ResTemp";

 
// Define the strings for our datastream IDs
XivelyDatastream datastreams[] = {
  XivelyDatastream(sensorID, strlen(sensorID), DATASTREAM_FLOAT),
  XivelyDatastream(resID, strlen(resID), DATASTREAM_FLOAT),
};
// Finally, wrap the datastreams into a feed
XivelyFeed feed(xivelyFeed, datastreams, 2 /* number of datastreams */);
 
EthernetClient client;
XivelyClient xivelyclient(client);

//timing for sending Xively data
unsigned long lastXivelyPut = 0; //stores the last time Xively sent data
unsigned long putInterval = 10000;  //interval at which to send data



unsigned char doseTime;

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  
   Ethernet.begin(mac/*, ip*/);
  server.begin();
  
  setSyncProvider(RTC.get); //Retrieves time from the RTC
   

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  // Set the speed to start, from 0 (off) to 255 (max speed)
  macroPump->setSpeed(150);
  macroPump->run(FORWARD);
  // turn on motor
  macroPump->run(RELEASE);//Turn off motor
  
  microPump->setSpeed(150);
  microPump->run(FORWARD);
  // turn on motor
  microPump->run(RELEASE);
}

void loop() {
  uint8_t i;
  unsigned long currentMillis = millis();
  
  sensors.requestTemperatures();
  tempTest = (sensors.getTempF(testProbe));
  tempTest2 = (sensors.getTempF(testProbe2));
  
  int TankTemp = (sensors.getTempF(testProbe));
  datastreams[0].setFloat(TankTemp);
  
  int ResTemp = (sensors.getTempF(testProbe2));
  datastreams[1].setFloat(ResTemp);
  
   
  
  if (currentMillis - lastXivelyPut > putInterval) {
    lastXivelyPut = currentMillis;
    Serial.println("Uploading it to Xively");
    int ret = xivelyclient.put(feed, xivelyKey);
  }
  
  
  if (hour() == 7 && minute() == 46 && second() == 0) {
      doseTime = second();
    macroPump->setSpeed(155);
    macroPump->run(FORWARD);
    }
  if (second() >= (doseTime + 2)) {
        macroPump->run(RELEASE);
      }
      
    if (hour() == 13 && minute() == 5 && second() == 0) {
      doseTime = second();
    microPump->setSpeed(155);
    microPump->run(FORWARD);
    }
  if (second() >= (doseTime + 2)) {
        microPump->run(RELEASE);
      }
}


----------



## benjaf

bigd603 said:


> I want the arduino to to feed the data to Xively every ten seconds without using a delay command so the rest of the sketch doesn't get held up in the mean time. I'm using the millis method from the Blink Without Delay example. It works well for a while, but after several hours it stops the feed until i reset the Arduino. I think it has something to do with the millis crossing over, but I don't really know how to fix it. Anyone have any ideas?


Nice to see someone is making progress!
Any particular reason for using millis rather than a timestamp from the RTC? If you do want to use millis you will have to handle rollover. That could be done with something like this:


Code:


if (currentMillis - lastXivelyPut > putInterval) 
{ ... }
else if(currentMillis < lastXivelyPut) {
lastXivelyPut = 0;
}


----------



## bigd603

benjaf said:


> Nice to see someone is making progress!
> Any particular reason for using millis rather than a timestamp from the RTC? If you do want to use millis you will have to handle rollover. That could be done with something like this:
> 
> 
> Code:
> 
> 
> if (currentMillis - lastXivelyPut > putInterval)
> { ... }
> else if(currentMillis < lastXivelyPut) {
> lastXivelyPut = 0;
> }


Thanks Benjaf, I didn't do the RTC time stamp at first because I was also worried about a rollover scenario (if it checked if lastXivelyPut >= second() + 9 or something like that) when the second rolled over into the next minute. But thinking about it, I could just have it check if second = 0, 10, 20, 30, 40, or 50. That would give me the same result without worrying about a rollover. Thanks!


----------



## benjaf

bigd603 said:


> Thanks Benjaf, I didn't do the RTC time stamp at first because I was also worried about a rollover scenario (if it checked if lastXivelyPut >= second() + 9 or something like that) when the second rolled over into the next minute. But thinking about it, I could just have it check if second = 0, 10, 20, 30, 40, or 50. That would give me the same result without worrying about a rollover. Thanks!


You're welcome!
Most RTC libraries also have an option to return a proper timestamp, usually Unix time (seconds since 01-01-1970) or seconds since 01-01-2000 which would be ideal for this use since it doesn't roll over any time soon.


----------



## HunterX

benjaf said:


> You're welcome!
> Most RTC libraries also have an option to return a proper timestamp, usually Unix time (seconds since 01-01-1970) or seconds since 01-01-2000 which would be ideal for this use since it doesn't roll over any time soon.


Benjaf to the rescue! Thanks Ben. I have been so busy. I'm getting ready to redeploy back to the states. Can't wait!


----------



## benjaf

HunterX said:


> Benjaf to the rescue! Thanks Ben. I have been so busy. I'm getting ready to redeploy back to the states. Can't wait!


Well, someone has to troll the board, and it is a lot easier to find time for than playing around with the soldering iron.. Don't you just hate when real life gets in the way of a hobby!


----------



## HunterX

benjaf said:


> Well, someone has to troll the board, and it is a lot easier to find time for than playing around with the soldering iron.. Don't you just hate when real life gets in the way of a hobby!


Hey Ben,
Sorry if I sounded sarcastic. You have made a huge contribution to this thread and project. I sincerely appreciate your help and input. As soon as I get back to the states I can get back to giving this thread the attention it deserves!


----------



## benjaf

HunterX said:


> Hey Ben,
> Sorry if I sounded sarcastic. You have made a huge contribution to this thread and project. I sincerely appreciate your help and input. As soon as I get back to the states I can get back to giving this thread the attention it deserves!


Oh, not at all!  I just had a kid not long ago - and really don't have time to get anything done. That part rather sucks! ;-)

Looking forward to see the final result once you get back to the States!


----------



## bigd603

Fluffles said:


> Most of the parts are in, but I'm still missing the 8-channel relay board, 4x24 LCD, and the 10P terminal blocks. They are coming in from China so it still might be 1-3 weeks from now. Also, I ordered a wood box for the project since I don't have any woodworking skills or tools. That's still about 2 weeks away from arrival. I don't think I'll really be able to start before getting the box.
> 
> Here's a quick pic of where everything stands:
> 
> 
> 
> 
> 
> 
> 
> 
> 
> This will be very similar to your project except I have less space to fit everything in so it will be a bit of a challenge.
> 
> I will be adding an in-line fuse for the AC line before the terminal blocks just to be safe.
> Also, I'll have a second LCD screen inside the box (above the power supply). The screen has pushbuttons so I was thinking of making the second screen a menu that will allow me to select LED brightness, morning ramp-up time, nightime, time set, and fan speed.
> 
> I kinda decided not to do temperature or PH readings from the tank. My tank is a small 10G rimless tank, and I'd like to minimize the amount of wires going in and out. I won't be doing any sort of ethernet/wireless communication since I don't see the point with my specific setup, it also keeps things simple.
> 
> I think the biggest thing for me is that I'll be able to control relays, LEDs, and dosing pumps from the same RTC module. Right now I have 3 different timers in my tank and already had several accidents happen while I'm on a trip. Also, with pushbuttons to control the relays, it will be a breeze to disable outlets for doing maintenance.
> 
> Thanks again for posting your project up so everyone can see it. It made me take the plunge and get started on this. I'll keep you posted on any new ideas or discoveries I make while working on this.



Fluffles, what size fuse did you wind up using on your build?


----------



## Fluffles

I used a 10A 20mm fuse. There is a fuse drawer included with the module where the power cord plugs in.
The relays' max current spec is 10A so that's the main reason I chose this value. 
Also, I don't expect the current draw for the controller to be more than 10A even with heater, filter, lights, skimmer, etc all connected and on at the same time. If for some reason my controller is drawing 10A at 120V, then there's a huge problem happening somewhere lol.


----------



## bigd603

Fluffles said:


> I used a 10A 20mm fuse. There is a fuse drawer included with the module where the power cord plugs in.
> The relays' max current spec is 10A so that's the main reason I chose this value.
> Also, I don't expect the current draw for the controller to be more than 10A even with heater, filter, lights, skimmer, etc all connected and on at the same time. If for some reason my controller is drawing 10A at 120V, then there's a huge problem happening somewhere lol.



Is this what you used for the power module? There's a place to put a fuse in that little guy?

https://www.jameco.com/webapp/wcs/s...&catalogId=10001&pa=1951596&productId=1951596


----------



## Fluffles

I ended up changing the power entry module from what you see in the picture above.

I'm using Corcom *PSJS0SBX0* (Warning PDF). It doesn't have an EMI filter, but it has a switch and fusebox. I figured that I didn't need an EMI filter since my 12V power supply has one included. It was pretty much the only thing available at my local electronics store that met my requirements.

You can take a better look at the pictures I posted on post #141 earlier. It's the big plastic box on the back right corner.


----------



## allabouttheplants

First of all, Hunter thank you for your service. i make it a habit to thank all who have served, and i am teaching my 5 y/o to have the same respect that the service men and women of our country deserve. Second all i can say is WOW on this build. i did a diy aquarium controller about 15 years ago, all timers, relays and 2 PLC ( setup by the maintenance tech for me) for the heating and cooling, no dosing. with all i have been reading about the arduino's lately i am becoming very interested, and my wife can tell you that is not a good thing when it comes to my wallet. you have taken every aspect of normal aquarium attention, and automated them all. i am curious to know who easy would this be for someone like me with very little experience with PCB and no experience with coding be to do?again great work and have a safe trip home.


----------



## HunterX

allabouttheplants said:


> First of all, Hunter thank you for your service. i make it a habit to thank all who have served, and i am teaching my 5 y/o to have the same respect that the service men and women of our country deserve. Second all i can say is WOW on this build. i did a diy aquarium controller about 15 years ago, all timers, relays and 2 PLC ( setup by the maintenance tech for me) for the heating and cooling, no dosing. with all i have been reading about the arduino's lately i am becoming very interested, and my wife can tell you that is not a good thing when it comes to my wallet. you have taken every aspect of normal aquarium attention, and automated them all. i am curious to know who easy would this be for someone like me with very little experience with PCB and no experience with coding be to do?again great work and have a safe trip home.


 Thanks for the reply and appreciation. It was a rough deployment. My wife ended up leaving me but it is good to know that our fellow countrymen and women appreciate the sacrifice of the men in women in uniform.

I'm almost done. I landed back in the states about a week ago. I will be here going through the demobilization process for a few weeks and then home sweet home. 

As far as the controller and learning the code. I knew nothing about the Arduino or coding when I started this project. That's what made it so fun. There are so many resources online to help you out. I also bought a basic Arduino book that really helped a lot with the code. If you are scared to dive into this project because of the coding, you have no reason to be. Not to mention, we all will help! 

Thanks again!


----------



## allabouttheplants

Are sainsmart good knockoffs of the arduino? i can find the mega, sensor shield, an relays for half the cost of arduino brand


----------



## HunterX

allabouttheplants said:


> Are sainsmart good knockoffs of the arduino? i can find the mega, sensor shield, an relays for half the cost of arduino brand


I can't provide any input as I have not use any parts made by Sainsmart. I used most of the "Yourduino" brand. Which are less expensive then the Arduino line. They have performed flawlessly. I have included the web link below. 

http://yourduino.com/sunshop2/


----------



## bigd603

allabouttheplants said:


> Are sainsmart good knockoffs of the arduino? i can find the mega, sensor shield, an relays for half the cost of arduino brand


I've had really good luck with Sainsmart. I have a relay board and 3.2" touchscreen LCD from them, both work flawlessly. 

Sent from my Galaxy Nexus using Tapatalk


----------



## allabouttheplants

As far as the power and step up/down, could a 350watt computer supply work. It has 12v 5v and 3.3, power.


----------



## scapegoat

allabouttheplants said:


> As far as the power and step up/down, could a 350watt computer supply work. It has 12v 5v and 3.3, power.


This was actually suggested to me on another forum when I inquired power supply and wiring. computer PSUs are rather large though


----------



## allabouttheplants

The overall size would not matter to me, it is more about cost. I can remove any unneeded wires and only have the power and ground. Plus it is fused, and most have a power filter on them.


----------



## sumer

Wow. Such an awesome thread.
So many pages to read through. I am gonna start a similar project soon. I am getting acquainted with arduino right now. 
I have a few more ideas in mind like adding a pH probe and a touchscreen for the interface.
I am glad to find this thread because now I know which people to ask if I encounter a problem 

Thanks,
Sumer.


----------



## HunterX

sumer said:


> Wow. Such an awesome thread.
> So many pages to read through. I am gonna start a similar project soon. I am getting acquainted with arduino right now.
> I have a few more ideas in mind like adding a pH probe and a touchscreen for the interface.
> I am glad to find this thread because now I know which people to ask if I encounter a problem
> 
> Thanks,
> Sumer.


Let me know how adding the pH probe goes. I have considered doing that as well.


----------



## scapegoat

what was your process for bending the short bits of wire on the terminal strips? I'm having a hell of a time, and might just break down and use the 18g stranded wire I bought for my internal wiring.


----------



## HunterX

scapegoat said:


> what was your process for bending the short bits of wire on the terminal strips? I'm having a hell of a time, and might just break down and use the 18g stranded wire I bought for my internal wiring.


Needle nose!


----------



## bigd603

Hey guys, I have been working on putting together a custom Arduino Mega Shield that will accomodate a lot of what we're doing here. There's a place for an RTC, an Atlas Scientific ph curcuit (actually, it will fit any of their embedded circuits), a female bnc connecter, you can connect 12v power directly to the shield, which will run the up to 3 pumps connected to the on board screw terminals, there is a group of four I2C device input headers, an IR LED to control the Current Satelite+ (or anything else you can come up with!), and 6 headers for digital inputs/outputs. You can check out my Fritzing File here: https://www.dropbox.com/s/suu31k4vy3s1qv7/MegaMegaWickedAquatic.fzz

Would anyone be interested in buying some? I can get them ordered in batches of 3 for about $18 each, and i can do a bulk order for the components (not including the pH circuit and BNC connector). That will add about $30 to each unit. If I can get an order of 18 or more, then the price for the PCB drops down to like $8.50. The price of the components would drop as well, but I haven't done the math on that one yet. 

Here's a render of how it will look:



What do you guys think?

Also, this is my first time doing anything like this so if there's any mistakes, feel free to let me know.


----------



## gus6464

So basically just drop that bad boy on top of a Mega?


----------



## bigd603

Yep, pretty much. There's a fair amount of room for expandability with he i2c area and the digital input headers. That's a great place to plug in some temperature sensors, for example.


----------



## bigd603

I'm pretty sure I can get a better price on all the components but $18 or $8.50 is a great price for custom PCBs.


----------



## bigd603

I took the file down. I just noticed a couple errors that i need to correct, will put it back when its fixed.


----------



## O2surplus

bigd603 said:


> I'm pretty sure I can get a better price on all the components but $18 or $8.50 is a great price for custom PCBs.



What are the dimensions of your PcB? If it's 10cm x10cm or smaller you can get 10 of them from Seeedstudio or Iteadstudio for about $25 plus shipping. That's only $2.50 per board.

ITEAD Studio - Make innovation easier 

Services : Seeed Studio Bazaar, Boost ideas, extend the reach


----------



## bigd603

I checked iteed out and they look pretty good, lots of reviews say they're pretty good quality with really fast turn around. I can definitely fit into the 10x10cm. I'm working on an alternative layout as well that moves the pH stamp and connector to the back, so you can still put other shields on top. I'm gonna make a whole new thread about this tomorrow to see how many people would be interested.


----------



## bigd603

Hey guys, I just created a new thread with a final revised version of the Aqua Shield. Check it out here: http://www.plantedtank.net/forums/showthread.php?t=683913


----------



## HunterX

Hello everyone. I finally got home and got my controller connected to my 120g tank. Its working like a charm. The ferts are dosing perfectly. All the components are turning off and on when they should. I still have two things I would like to add to it. I want to test and display the PH on the LCD and I have got to figure out how to use the wifi without locking the Arduino up if it doesn't resolve/connect to a website. 

I'll post some pictures of it working away this evening.


----------



## paronaram

Welcome HOME!!!
No one give you hard time to cary this project around? 

Again, awesome project!

Aram


----------



## HunterX

paronaram said:


> Welcome HOME!!!
> No one give you hard time to cary this project around?
> 
> Again, awesome project!
> 
> Aram


Sorry I didn't reply sooner. I saw this message and then got busy and forgot to reply. Lucky for me I didn't carry it back to the states. I was able to mail it home through USPS with no issues. The did break one of the joints free on the lid. It wasn't a big deal. A little wood glue and it was as good as new!

Bump: Sorry I still haven't posted any new pictures. When I get home from work I start playing with everything and forget to take updated pictures. I'll get some posted soon. I did order the ATLAS ph kit. My first impression is a good one. I'm only having one issue. It's not calibrating correctly. It calibrates to 7.0 ph with no issues but will not calibrate to 4.0 or 10.0. I contacted the ATLAS customer support and they responded right away. I haven't been able to work through their troubleshooting instructions yet but should be able to tomorrow night. If anyone is interetested in adding the abiltiy to track PH to their controller, I really think this is the way to go.


----------



## HunterX

bigd603 said:


> Hey guys, I just created a new thread with a final revised version of the Aqua Shield. Check it out here: http://www.plantedtank.net/forums/showthread.php?t=683913


Bigd,

I'm not able to see your thread. I get an error that says I do not have permission to see it. Whats up with that? HA HA HA. I want to check out where you are with it.


----------



## gus6464

HunterX said:


> Bigd,
> 
> I'm not able to see your thread. I get an error that says I do not have permission to see it. Whats up with that? HA HA HA. I want to check out where you are with it.


The mods closed it because they consider it a group buy. He will post another thread once the boards are in hand.


----------



## bigd603

HunterX said:


> Bigd,
> 
> I'm not able to see your thread. I get an error that says I do not have permission to see it. Whats up with that? HA HA HA. I want to check out where you are with it.


Yeah, Gus is right, they took it down :-/

I got the PCBs in the other day, and unfortunately there were broken traces on each of the boards and all the holes in the ICSP area were connected to one another. That really bummed me out. To make matters worse, the manufacturer wouldn't replace the boards without paying full price. So that also sucked. But I found another company that has been getting rave reviews and has a money back satisfaction guarantee (and they can do ENIG for only a dollar more!), so I placed an order with them. The bright side of it is that it allowed me to make some modifications and improve the layout of a few things. Hopefully they will be here soon. Reviewers say they typically take about 2 weeks from date of order to arrival in the US. I'm also leaving for a trip to Alaska on the 28th, so I'm REALLY hoping they get here before then so I can get them out to everyone before I leave. 

But, I will definitely post pictures here once I get them in hand.

By the way, Darrin, welcome home!


----------



## gus6464

bigd603 said:


> Yeah, Gus is right, they took it down :-/
> 
> I got the PCBs in the other day, and unfortunately there were broken traces on each of the boards and all the holes in the ICSP area were connected to one another. That really bummed me out. To make matters worse, the manufacturer wouldn't replace the boards without paying full price. So that also sucked. But I found another company that has been getting rave reviews and has a money back satisfaction guarantee (and they can do ENIG for only a dollar more!), so I placed an order with them. The bright side of it is that it allowed me to make some modifications and improve the layout of a few things. Hopefully they will be here soon. Reviewers say they typically take about 2 weeks from date of order to arrival in the US. I'm also leaving for a trip to Alaska on the 28th, so I'm REALLY hoping they get here before then so I can get them out to everyone before I leave.
> 
> But, I will definitely post pictures here once I get them in hand.
> 
> By the way, Darrin, welcome home!


Nice! Did you order ENIG for the new ones?

Sent from my XT1060 using Tapatalk


----------



## bigd603

gus6464 said:


> Nice! Did you order ENIG for the new ones?
> 
> Sent from my XT1060 using Tapatalk


Sure did! I am stoked about that, the gold makes PCBs look pro. I'll get some pics of the faulty boards up for you guys in a little bit so you can at least get a good idea of what they will look like.


----------



## HunterX

Thanks bigd!


----------



## AnotherHobby

I just wanted to drop in and say this is an awesome build! Excellent job Hunter! I somehow missed this thread until recently (I think because I was so engrossed in my own project). I finally read through the whole thing, and I'm super impressed.

One thing that might make things cleaner for scheduling is to use the Time.Alarms library. I used it in my project, and it's nice that you don't have to check time in the loop to catch things. It also makes it easy to change the schedule. If you read the docs, you can adjust the library to do up to 255 timers. It has quite a bit of functionality.

Here is an example. This one line below would be executed at startup and creates a schedule that'll run a routine called "lightsOn" every day at 11:00am.



Code:


Alarm.alarmRepeat(11,00,0, lightsOn);

The lightsOn routine could look like this:



Code:


void lightsOn()
{
   digitalWrite(pwrLightPin, HIGH); // this turns the relay on
}

That's it — super easy! It also opens the doors to making it pretty easy to edit the schedule through a menu, and saving that in EEPROM.


----------



## bigd603

Check out what came in the mail today...





The AquaShield boards!

I think they look great! I tested the pump controls, and they all work flawlessly! Really stoked.


----------



## AnotherHobby

Nice! That's a sweet little board!


----------



## HunterX

AnotherHobby said:


> I just wanted to drop in and say this is an awesome build! Excellent job Hunter! I somehow missed this thread until recently (I think because I was so engrossed in my own project). I finally read through the whole thing, and I'm super impressed.
> 
> One thing that might make things cleaner for scheduling is to use the Time.Alarms library. I used it in my project, and it's nice that you don't have to check time in the loop to catch things. It also makes it easy to change the schedule. If you read the docs, you can adjust the library to do up to 255 timers. It has quite a bit of functionality.
> 
> Here is an example. This one line below would be executed at startup and creates a schedule that'll run a routine called "lightsOn" every day at 11:00am.
> 
> 
> 
> Code:
> 
> 
> Alarm.alarmRepeat(11,00,0, lightsOn);
> 
> The lightsOn routine could look like this:
> 
> 
> 
> Code:
> 
> 
> void lightsOn()
> {
> digitalWrite(pwrLightPin, HIGH); // this turns the relay on
> }
> 
> That's it — super easy! It also opens the doors to making it pretty easy to edit the schedule through a menu, and saving that in EEPROM.


Hey Hobby,

That does look like it would make my code more simple but I have a question. Say I wanted to turn something on at and exact second and then turn it off at an exact second. Have you seen any issues where the areduing misses that second and skips that alarm. I have an automatic feeder connected to my Arduino. I drive it through a transister using the 5 volts from the Arduino. It takes 5 seconds for it to complete 1 feed cycle. I turn it on say at (11,05,01) and turn it off at (11,05,04). What do you think?

Bump:


bigd603 said:


> Check out what came in the mail today...
> 
> 
> 
> 
> 
> The AquaShield boards!
> 
> I think they look great! I tested the pump controls, and they all work flawlessly! Really stoked.


Those look great bigd!


----------



## mistergreen

@HunterX
I don't see why TimeAlarms would skip time set in seconds. It has an internal loop where it checks up on time from what I remember when I looked at the library code.


----------



## HunterX

I think I'm going to give it a shot. I'll rewrite my code this weekend and let everyone know how it went. Thanks for the info Hobby.



mistergreen said:


> @HunterX
> I don't see why TimeAlarms would skip time set in seconds. It has an internal loop where it checks up on time from what I remember when I looked at the library code.


----------



## AnotherHobby

mistergreen said:


> @HunterX
> I don't see why TimeAlarms would skip time set in seconds. It has an internal loop where it checks up on time from what I remember when I looked at the library code.


Correct. In your main loop, you have to use "Alarm.delay(5);" at the end of the loop instead of a normal delay. That's how it keeps track. It should not skip any seconds.


----------



## HunterX

AnotherHobby said:


> Correct. In your main loop, you have to use "Alarm.delay(5);" at the end of the loop instead of a normal delay. That's how it keeps track. It should not skip any seconds.


Would I really have to use the "Alrarm.delay(5)"? If I just turn it on and then turn it off 5 seconds later wouldn't that do the same thing? Which would be more effecient way of coding?


----------



## mistergreen

Alarm.delay(5) means to check up on all Alarms & timers every 5 milliseconds (the internal loop). You can do Alarm.delay(0) if you don't want any delay for the Alarms class.


----------



## AnotherHobby

mistergreen said:


> Alarm.delay(5) means to check up on all Alarms & timers every 5 milliseconds (the internal loop). You can do Alarm.delay(0) if you don't want any delay for the Alarms class.


Yes, I just grabbed the line I had in my project. :thumbsup:



HunterX said:


> Would I really have to use the "Alrarm.delay(5)"? If I just turn it on and then turn it off 5 seconds later wouldn't that do the same thing? Which would be more effecient way of coding?


You have to use Alarm.delay no matter what in your loop (where n can be any number of millis). It's what calls the TimeAlarms library.

The timer library also has "Alarm.alarmOnce" instead of "Alarm.repeat". You could just kick that off when you start, with the Once timer set to kick off 5 seconds later. Go through the readme, it's pretty easy to use.


----------



## HunterX

AnotherHobby said:


> Yes, I just grabbed the line I had in my project. :thumbsup:
> 
> 
> 
> You have to use Alarm.delay no matter what in your loop (where n can be any number of millis). It's what calls the TimeAlarms library.
> 
> The timer library also has "Alarm.alarmOnce" instead of "Alarm.repeat". You could just kick that off when you start, with the Once timer set to kick off 5 seconds later. Go through the readme, it's pretty easy to use.


Yeah I just checked it out. I understand it now. I'm using a differnt RTC time library. Looks like I would have to change that too. Which means changing all the code for displaying the time on the LCD as well. I'll play with it this weekend.


----------



## HunterX

bigd603 said:


> Check out what came in the mail today...
> 
> 
> 
> 
> 
> The AquaShield boards!
> 
> I think they look great! I tested the pump controls, and they all work flawlessly! Really stoked.


Bigd,

Do you have the atlas ph board? If so I have a few questions for you.


----------



## bigd603

Hey guys, its been a while. What gauge wire do you recommend to connect between the terminal strips and the plugs?


----------



## theknight

bigd603 said:


> Hey guys, its been a while. What gauge wire do you recommend to connect between the terminal strips and the plugs?


14 gauge would be more than adequate and still easy to work with.


----------



## bigd603

The biggest I could find at RadioShack last night was 18. Think that's OK? I haven't opened it so I could still return it.


----------



## salman

I got 14ga at lowes. The sell by foot. I think it was around $0.30/ft


Sent from my iPhone using Tapatalk


----------



## HunterX

Hey bigD how are you doing? How are the boards working. Are you using the Atlas Ph chip. I noticed it in the picture of your boards. If so what version and how is it working for you. Mine runs great when I load only their code. When I add their code to my sketch it starts responding funny after it reports the PH 12 times. It reports more then 1 reading per line which makes it very hard to display the PH reading on the LCD.


----------



## PhysicsDude55

bigd603 said:


> The biggest I could find at RadioShack last night was 18. Think that's OK? I haven't opened it so I could still return it.


18 gauge is fine... Its perfectly safe to run 5 amps or so through 18 gauge. The biggest worry is to make sure that whatever wires have 120V mains voltage on them should be rated for 120V.


----------



## HunterX

Hello everyone. Sorry I haven't added anything to this in a few years. In cause someone stumbles across the thread and is concerned about the longevity of this project, it's still running strong controlling my 220G now. I was able to get the PH added to it with out issue.


----------

