// reeftank controller guidance plz

I didn't quite follow that circuit using a SPDT relay to drive the blue/white LEDs. Firstly because the diagram shows the relay in a mid position, but a conventional SPDT relay has a common contact, a normally open contact and a normally closed contact; except when the relay is in the process of switching, the common terminal is connected to either the NO or NC terminal. Secondly, I don't understand why one LED is backwards and there is another diode between them. Is there something clever going on here - if so, what?

As far as sketch design goes, I suggest that you design the sketch to be non-blocking and modular. Implement each major functional area with whatever global data it requires, and functions to be called from setup() and loop() to carry out the corresponding behaviour. These functions should be non-blocking (should not stop and wait for some external event to occur). The preferred approach to implement this is to design your code to check for events that might need to be handled, such as input arriving on a serial port, or some scheduled action being due. The 'blink without delay' example sketch demonstrates how to use this approach for simple timed activity (blinking an LED on and off at regular intervals) and I recommend that you follow a similar approach for the other things your code needs to do. In this way your code can check for and handle all the tasks that need to be performed, without any piece of the code needing to cooperate with or be aware of what any other parts are doing. The only overriding requirement is that you stay within the total available memory, and that all of your code completes quickly enough that you can complete the loop fast enough to meet your latency requirements.

you're right, i drew the led backwards...oops.. good catch. it was late and nyquil was catching up...
and i might be wrong but the SPDT here has three conditions, blue/off/white and blue
the SPDT is the current setup on the lighting fixture. i am going to remove that switch and put a new jack in its place to run the wires to the relay board for switching.
that way i can switch between white and blue on both runs of lights at their respective times.
i could have the fans come on when the first set of whites come on and go off when the second whites go off.
that would eliminate the need for the temp sensor. but it would be way more efficient with it.

and i have minimal to no idea about the sketching parts you mentioned, sorry i'm just new to C++ and arduino IDE

after studying your reply, i believe i know what you are talking about as far as trying to keep it simple(KISS).
but as far as all the code language and the usage of each command and function lingo, i am lost.
i know i need an "int, include lib, or h., setup, loop the brackets and { }, and all the ;'s ()
but i don't know how when or why to use them, that is where i need the assistance i guess.
if no one here helps me, maybe this CookBook that comes in monday will. it'll just take alot longer..

Lots of good advice here. A traditional approach for complex system development is "Stepwise Refinement".. championed by Nicholas Wirth, who created the PASCAL language.

You could write the outline of your system with Procedures for each major function like ControlPump or ReadLightSensor or ReadClock or ReadUserInput, but have those procedures at first do nothing at all. You could define your State Machine and debug the logic it implements with long delays and outputting the State Variable to the serial monitor to see where you are. Make your procedures put out phoney expected data to see that it is handled correctly. Leave the real-time type things until last.

See: Arduino Playground - HomePage (Thanks Alexander Brevig) and maybe the example at: http://arduino.cc/forum/index.php/topic,37153.0.html

You'll be glad you implemented a State Machine when you can find out where you are every time and Why..

If you get your skeleton constructed properly and well controlled, you can start adding flesh. Flesh is weak and will break, but you can handle one thing at a time.

If you can relax and get into the "Oh, that's an interesting Problem!" mode and avoid getting bent out of shape and thrashing, you may find you LIKE this stuff!

I was in your position around 2 years ago when I considered making my own led controller, which over the following 12 months turned into a fully blown controller for all of my equipment i.e. return pumps, skimmer pump etc. This was initially based on a 20x4 LCD display and keypad but I am currently working on a TFT LCD with Touch screen controller.

You may find that someone else has done exactly what you require using your hardware, but the chances are slim. So, if you are going to end up with what you want then you will need to learn the programming language. Take baby steps, add one thing at a time and get that working - start with blinking a led so that you understand what you are doing.

This forum is great for answering specific questions that you may have, but you can't expect someone to teach you the language - my estimate is that my first controller would have taken in excess of 200 hours to complete, spread over 12 months but lots of that was researching how to do things.

There are quite a few threads on Reefcentral which may help get you started.

Good luck.

well it's been a few days and no one has been able to tell me anything new....anyone else?

glennwl:
well it's been a few days and no one has been able to tell me anything new....anyone else?

I, for one, don't know where to get started with helping. Your project is pretty large and you don't have code yet. Everyone here can help you with small steps, not simply because it's a free forum, but more or less because no one knows exactly what you need. With some code, we can say "this portion should look like this" or "that part is missing something". With a plan and no code, I'm not sure I want to dive into it. It's deep water with unknown depth. If you want some simpler plan executed, someone may even come up with a skeleton code. I do consulting work on software and hardware. If this were a consulting job, I'd be asking a lot of questions for details and investing major time to write code to work. I expect your code to be somewhere around 750-1000 lines of code when complete but at least several hundred lines to get it started. I doubt anyone will invest that much time for another forum member. It's work for several nights if the person has the hardware and several hundred dollars of pay. If you get to the several hundred lines status and then ask, you get more responses since we can build upon your existing project now. Not trying to throw you a wet blanket but I'm can't sweep away the feeling in my original reply, too ambitious as your first(ish) project.

*/
great reply and very helpful, thank you;
fear not, i am working with others with the skeleton and then meat;
my last post a few minutes ago was more antagonistic and provoking than anything...stirring the pot, and look, you wrote with a good view and some great advice;
like the code, a little will go a long way;
i will be sure to post the finished product, the code, and schematics when done;
thanks

@luidr is right.. You have to get this diagrammed out on paper before you really start coding.

Often people do an outline showing the functional things that happen, then write in PseudoCode (Pseudocode - Wikipedia)
an approximation of what the code might look like.

If that all makes sense, then building that skeleton and starting to put real code pieces in and debugging them one at a time would be where real coding starts.

Don't drive yourself crazy with lots of code that just doesn't work.

Have you considered a bottom up approach? Rather than worrying about the big picture and struggling because of the complexity, take a subset of the system and get that working. Either as a standalone sketch or better as a function or two that are called from loop. One place to start might be be reading the RTC - trivial, because you can likely lift all the code from existing examples. Then write something that prints to the serial port what you should be doing at that time of day.

Then add the temp sensor that checks on the lights. Once that's working, put in the stuff to control the fans that cool them. etc. etc.

This way, you'll acquire a set of functions you can use as building blocks for your system and best of all, you'll see some immediate progress. Another advantage is that people here can give you some concrete advice if you're having issues with these sub projects because you'll have some code and circuitry that they can comment on.

  1. "blink" your led
  2. decide on a clock and learn to drive it -> send to serial (blinking led as well)
  3. decide on a display + keypad and learn how to drive them (it)-> now to display (blinking led as well)
  4. debounce those keypresses AND keep things moving on the display (use rtc -> display -> blinking led as well)
  5. single I2C temperature reading-> display -> blinking led as well
  6. multiple I2C temperature reading -> display -> blinking led as well
  7. Triggering of events for making something happen (clock time, temperature, keypad, state machine etc) -> blinking led as well

You're going to have to figure physical drive for your led's - this is probably going to be your biggest issue!
Are you going to PWM drive your LED's to start them off dim so that they are effectively 0 at 7am and maybe 15 at 7:30 then start your 2nd column @ 0 ramping to 15 while your 1st row ramps from 15 to 30 etc etc? if so, sin(x); is your friend for this!

You might also want to think about full spectrum rather than just blue and white (red/green/uv/ir)

here is what i think you mean by skeleton code. the keypad on the display isn't as necessary as the light timing, i can change the times and stuff with the coding, once i have it that is....
i don't want any one person to build the code for me, but if i can get a collective of people to help piece it together, i will be able to "learn as i go".
so... if someone has a portion that might help, my fishies will thank you :wink:

//start clock
//start display
//check temp
//diplay time and temp
//temp sensor in display tank for water temp display
//temp sensor on light fixture for fan control
//fans come on when lights are too warm
//the light fixture temp sensor doesn't need a display function
//lights are blue and white, two sets of each
//blues will be on with whites at all times and off at night
//sump lights are seperate
/*sequence is : 8 am first blue on,
9 am sump off and second blue on,
10 am first white/blue on,
11 am second white/blue on
*/
//all lights on for four hours
/*after four hour on time,
3 pm the first set of whites go off,
4 pm second set of whites go off,
6 pm the first blues go off,
7 pm the sump comes on,
7 pm the second blues go off.
*/
/the lights are one hour intervals except for the all on time
starting at 8 am and the last set of blues
/

to Atlanta: shortly after posting the skeleton sketch i noticed the second page of the posts and seen yours, great advice and i will work on it. but my original problem was getting the rtc, keypad display, and mega 2560 to talk together. so if you know a page where it shows how to do that, i might be able to take control from there, and i won't need to bother the forum any more except for showing the final product off. lol

The DFRbot display is a direct drop in and works flawlessly with the Mega 2560 - their sample code should get you giong easily ... look in the "LCD Keypad Library" for how to drive the dsplay, there's a good example in there Gravity: 1602 LCD Keypad Shield For Arduino - DFRobot
The RTC - you show what it's supposed to physically look like but don't give interface specs or anything to it

Check out my "www.reeftopper.com" link below for more thoughts on aquarium lighting :slight_smile:

interesting, informed.. i know i need to get more of a spectrum...
here are the lights i have right now..
http://www.aquatraders.com/EVO-Quad-60-LED-Reef-Bright-TR-p/56264.htm
i need to get the 72 inchers..
but i might also just bite the bullet and just buy this..
http://www.bulkreefsupply.com/reefkeeper-elite-w-net-digital-aquatics.html
that would let me control relays that i could wire in with this..
http://www.bulkreefsupply.com/reefkeeper-elite-w-net-digital-aquatics.html
its alot of money, but it would delay the headache of learning programming languages..
but i still wanna make this build so i can use it on my 55 gal in the bedroom
right now i am piecing together the rtc and board, then i'll put in the keypad/lcd shield
and i might just get some more red/purple,uv,ir leds for the corals..
can i use RGB leds and PWM for those?

OBVIOUSLY, as you've summized, a ReefKeeper or Apex would get your automation up and running faster, there's nothing wrong with that, it's what I did initially
The Apex actually has a better programming interface than the ReefKeeper in my mind but I still bought the ReefKeeper!

For basic control while you're building your own controller, you'll be able to save a whole lot of money by going with the RK-Lite packages (do you really need internet availability.. can be somewhat painful to implement)

An additional thing I did (My whole system was battery backed) - I put a 120V relay onto a separate plug outlet and fed the "Normally Open" contacts into a switch input... when house power was lost, an alarm condition was triggered, I turned off everything that was non-essential (lights / skimmer / return / excessive fans / dosing pumps) keeping flow running in the tank until power got restored.

If you post on any of the reef forums asking what is best, you're likely to get slammed with this is right, this is wrong - everyone has their own way of implementing their setup so take my input with a big grain of salt :smiley:

Additional: If you do go ReefKeeper route, make sure you put the power bars and controller interfaces somewhere that doesn't get too much salt laden humidity.. those 6 way network type connectors they use are cheap and are susceptible to corrosion. It's easy enough to swap them out if they do corrode, forewarned is forearmed! I have no idea how susceptible the Apex etc is to corrosion as I don't own one

yes i do kinda need(want) the net interface, we are planning a outta state trip in june, = the need for the automation...
i too was thinking about the possibilities of power outages.. im gonna put a battery operated air pump normally closed on a relay to pump a jet of air into my siphon drain in the event of a PO. and if i have the Reef Keeper that can send alerts like that, i can call my neighbor to come and restart my system... the 120v relay is a must...i am also getting the...

...the 50 gpd 4-stage RO/DI...and the float valve..
it's a big project, i know...but a reef tank is worse than crack or meth...not that i'd know, just sayin..

Get yourself registered on ReefCentral.com lots of good resources on there for configuring / information on saltwater automation.
Remember that once you've disabled the siphon by blowing air, your return pump better not be pumping any more water from sump into main tank until the siphon is re-primed or a couple of things might happen...

  1. Sump is going to run dry on you and you'll need a new sump pump
  2. You might overflow your display tank

Talking about RODI etc - If there's a local reef-club, get yourself logged in, see if anyone is getting out of the hobby. First rule of reefing - BUY USED if you can

We can trade tank design scenario's etc on ReefCentral (I'm "BigFloppy" over there).

Lets keep this thread on track with your arduino buildout. The people in this forum can and will help guide you through the programming mire.

yes, i would need another pump to draw suction on the siphon once power was restored, but that again is where the more advanced arduino programming comes in... and about the reef central, it says registration has been disabled by administrator....