# Calling all DIY LED "Junkies" - Your opinions wanted!



## O2surplus (Jan 31, 2010)

I was bored to death at work today, so I designed this just to keep my brain busy and pass the time. It's a 4 channel LED driver- that's very similar to ones that I built in the past, but with a new twist. I integrated a micro-controller/ real time clock into the design that will allow full programmable control of each channel. The controller features an I2C connection that will enable multiple driver boards to be connected together to communicate with, and act as slaves to a "master controller," or simply wired up to leds and left to run a user defined LED dimming "sketch". The controller is programmed using the standard ARDUINO IDE. I see this design being a really great way to have high resolution control over large groups of leds, or as a "stand alone" driver contoller for Nano Tank led builds. I personally have 90 leds over my tank being driven and controlled in groups of 30. This set up leaves me with only 3 channels of control. If I built this design, I'd have *15* channels of control to play with and be able to create seriously high resolution dimming and other lighting effects. *Does anyone else see a value to this design? Thoughts?

*Here's a photo/schematic of the driver


----------



## jcgd (Feb 18, 2004)

I'd use it. 

I can see how this is going to go. I'm going to be upgrading my fixture every six months.


----------



## theblondskeleton (Aug 28, 2009)

This would work really well with one of the "full spectrum" builds, particularly when dialing in good color rendering. Sounds like you could pretty much fine tune it like a stage light board to shift color intensities over time so you could have a nice crisp noon sun color, then fade in some deeper ambers and reds at sunset. It'd be a neat effect. 

I wonder if you could program a few fast pulses for a brief thunderstorm sequence. Do you have that degree of time resolution?


----------



## jcgd (Feb 18, 2004)

You can really do anything, if you can code it. Coding is the hard part. Well, once O2Surplus does the rest for us. In other words, the arduino controls everything the electronics do. Rey just do what they are told by the arduino, so you have to code it to do whatever.


----------



## O2surplus (Jan 31, 2010)

Can You guys think of anything else I should add? I'm thinking that I'll add a transistor to switch the 12v output off/on. That way cooling fans can be controlled directly and can be programmed to follow the Off/on times of the LEDS. I"m also thinking that I should "breakout" more pins on the micro-controller chip so that all the analog inputs can be addressed and used. I can see a situation where someone may want to add a temp sensor to their LED rig, measure Ph, or add an LCD display. I guess the possibilities are only limited by ones imagination. I just want this gadget to be as feature packed as possible before I pull the trigger and order the PCB's


----------



## theblondskeleton (Aug 28, 2009)

Oh in that case, CO2 control would be great. Simple as a relay, that. Auto water change system/top off.


----------



## jcgd (Feb 18, 2004)

Don't you think the master should have a lcd screen? My ideal all in one would have:

Lcd
Buttons for menu nav.
Four drivers
Full Dimming, Sunrise/sunset on all strings
Movie mode (something like dimmed lights and back to normal after 2.5 hours)
Moonlight Control (Just an override for a daylight string to come on at night too)
Co2 control by timer, just low voltage, not 120V
Fan control by fixture temp

Not sure how practical all those requests would be, but ideally, the expansion would just have more driver strings. Have a Plug it in and go. I'd like to hear how the controller would work for expansion.

Is adding more strings in the code as simple as copying the code from the other strings and giving it a new designation or something along those lines? It would be nice if it was pre-programmed for a bunch of channels, like 12 or 20 separate strings. 

Neat concept. I hope you make a few, whatever the final design.


----------



## O2surplus (Jan 31, 2010)

I'm thinking that I'll probably keep this driver/ controller combo fairly simple or "modular" for some important reasons-Mainly, reliability and serviceability . The driver could simply be replaced in the event of a failure, rather than having to take down the entire "Tank Controller" and it's associated sub systems. I think It would be best thing to do as the more complicated tasks should be handled by a dedicated controller. This driver could just be configured as a "slave" to the dedicated controller. It would carry it's own programming and be made to function autonomously, and merely "report back" to the "master controller" via the "2 wire" I2C communication protocol. The "Master Controller" could then be made with all the "Bells and Whistles"and either be made from scratch or from a existing Arduino UNO and appropriate "shields".

I'm going to redesign the PCB to include what will amount to an ARDUINO PRO MINI + an DS1307 RTC on the board. All the pins on the Atmega 328 will be accessible, so that the end user will be able to go either "mild or wild" with additional connections and complexity. I'm not very good at writing code, so I'm not much help there, but I'll make sure the hardware connections are available for the coding "experts" to take advantage of.


----------



## O2surplus (Jan 31, 2010)

So, I took my original design back to the drawing board, made a few changes, and came up with this- ( the board measures 80mm x 100mm)













I think this design has all the the elements needed to go from "mild to wild" with an LED build. Too many many features to list, but here's a partial rundown:

16 MHz ATMEGA 328P-AU micro-controller on board w/ ALL pins "Broken out for connections"

DS1307 "Real Time Clock" w/ back-up battery.

Standard "FTD1 Connection" on board (for programming purposes)

I2C connection ( for "2 wire communication" with other I2C enabled devices )

12 volt, 1.5 amp Voltage regulator ( for powering cooling fans ect..)

5 volt, 1.5 amp Voltage regulator ( provides power to Atmega 328 and CAT4101 led drivers.)

6 OnSemi CAT4101 led Constant current Regulators w/ up to 1000ma output.( will drive 6 - 8 leds per string, provided total led Vf does not exceed 25 volts.)

Analog current control for each CAT4101 ( 50ma - 1000ma adjustable )

Independent PWM dimming capability on a 6 CAT4101's.


I'm going to order a batch of these, build a few for myself, and retrofit them into my existing LED lighting system. I'll let you guys know how they perform.


----------



## Pickled_Herring (Jul 26, 2010)

Wow great design looks like this may be your masterpiece. You have really progressed past the early designs on RC. Independent led string control, relay control for stuff like Co2, Temp, and expandability. All the hardware is in place. I'm sure the sketches are already there that could be modified and cobbled together. Great job! I'm looking forward to the build. Subscribed.


----------



## O2surplus (Jan 31, 2010)

Pickled_Herring said:


> Wow great design looks like this may be your masterpiece. You have really progressed past the early designs on RC. Independent led string control, relay control for stuff like Co2, Temp, and expandability. All the hardware is in place. I'm sure the sketches are already there that could be modified and cobbled together. Great job! I'm looking forward to the build. Subscribed.



Hey thanks for the compliments! This is the biggest PCB that the "Free-ware" version of EAGLE will allow. I had a lot of "fun" trying to cram all of the needed components into that space. I went with 6 CAT4101's since that is the maximum number of PWM outputs available on the ATMEGA 328. The CAT's may require additional heat sinking, but that's an easy fix, as I already have a few CPU coolers laying around. I'm sure there's plenty of Arduino "Sketches" already available that can make this driver to some really cool things, so I'll be searching for that while I wait for the PCB's to arrive.


----------



## shrimpNewbie (May 6, 2011)

I really look forward to seeing one in action from what you told me this is insanely promising


----------



## theblondskeleton (Aug 28, 2009)

That's excellent - this will allow for so much control! Much better than having a stand cluttered with jiggered-up gizmos. Also having the analog option is very convenient. That way you can use whichever dimmable driver you prefer with this. My issue with the Inventronics driver was that it was analog control. The only controller I could find was the DIM4 on LEDgroupbuy - a great unit but expensive. Great work!


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> That's excellent - this will allow for so much control! Much better than having a stand cluttered with jiggered-up gizmos. Also having the analog option is very convenient. That way you can use whichever dimmable driver you prefer with this. My issue with the Inventronics driver was that it was analog control. The only controller I could find was the DIM4 on LEDgroupbuy - a great unit but expensive. Great work!



I think there may be misunderstanding with regards to how the "Analog Dimming" works with this driver. The CAT4101 IC normally uses a "Sense resistor" ( labeled RSense in the chips spec) to set it's upper current limit. The Chip can output up to 1000ma maximum, and that is set by installing a 549ohm resistor between the "RSense" pin and ground. This is how the driver is normally set up. If one wished to run the chip at 700ma instead of 1000ma, they'd have to install a 768ohm resistor instead of the 549ohm unit. I found this method of setting the current very cumbersome, so I installed a 10k trimmer pot inline with a 549 ohm resistor. This makes the output current fully adjustable ( 50 - 1000ma ) and there's no further need to desolder/solder resistors to change the output current. With 6 CAT4101's on board, this driver will be able to handle up to 150 watts worth of leds, that's 6 - 8 3W leds per channel or 36 -48 3W leds per driver board. The beautiful part of this driver is, once the maximum current per channel is set, (using the Analog current Pots) Each of the six channels can be programmed to dim via PWM signals provided by the on board Arduino microcontroller.
I put in the order for the PCB's and they're already in production,so I should have them in my hands in a week or so. I'm going to build 3 of them for my own use and then maybe pass out a few to people with coding experience, that will hopefully be able to show us all - How to take full advantage of this design. I'm a total NOOB with coding so I could use the additional help. ( This is code speak- for getting "SINK" to chime in )


----------



## Pickled_Herring (Jul 26, 2010)

O2 have you posted the Eagles anywhere yet?


----------



## theblondskeleton (Aug 28, 2009)

O2surplus said:


> I think there may be misunderstanding with regards to how the "Analog Dimming" works with this driver. The CAT4101 IC normally uses a "Sense resistor" ( labeled RSense in the chips spec) to set it's upper current limit. The Chip can output up to 1000ma maximum, and that is set by installing a 549ohm resistor between the "RSense" pin and ground. This is how the driver is normally set up. If one wished to run the chip at 700ma instead of 1000ma, they'd have to install a 768ohm resistor instead of the 549ohm unit. I found this method of setting the current very cumbersome, so I installed a 10k trimmer pot inline with a 549 ohm resistor. This makes the output current fully adjustable ( 50 - 1000ma ) and there's no further need to desolder/solder resistors to change the output current. With 6 CAT4101's on board, this driver will be able to handle up to 150 watts worth of leds, that's 6 - 8 3W leds per channel or 36 -48 3W leds per driver board. The beautiful part of this driver is, once the maximum current per channel is set, (using the Analog current Pots) Each of the six channels can be programmed to dim via PWM signals provided by the on board Arduino microcontroller.
> I put in the order for the PCB's and they're already in production,so I should have them in my hands in a week or so. I'm going to build 3 of them for my own use and then maybe pass out a few to people with coding experience, that will hopefully be able to show us all - How to take full advantage of this design. I'm a total NOOB with coding so I could use the additional help. ( This is code speak- for getting "SINK" to chime in )


Whoops :redface: haha... Well, I never claimed to be an expert. That makes sense, though. So it can operate as a kind of 'driverless' controller? And the current for each channel is adjustable similar to a MeanWell driver? Up to 48 LEDs?

If i understand this correctly now, that makes this capable of doing all the work (driving, dimming, and controlling) for just about any size build, providing there is no minimum quantity of LEDs per channel? Wicked cool! This could save DIY'ers a ton of cash on separate drivers and controllers.


----------



## O2surplus (Jan 31, 2010)

Pickled_Herring said:


> O2 have you posted the Eagles anywhere yet?


I'll post the build files after I've built a few of these and see how they behave in the "real world" I don't want to release the design until it's proven. I tend to design, build, test and re-design a few times over until I'm comfortable enough to post the files for the "Final product".


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> Whoops :redface: haha... Well, I never claimed to be an expert. That makes sense, though. So it can operate as a kind of 'driverless' controller? And the current for each channel is adjustable similar to a MeanWell driver? Up to 48 LEDs?
> 
> If i understand this correctly now, that makes this capable of doing all the work (driving, dimming, and controlling) for just about any size build, providing there is no minimum quantity of LEDs per channel? Wicked cool! This could save DIY'ers a ton of cash on separate drivers and controllers.



Yes- Now you get it! I've literally tried to cram everything anyone would ever want into one place. It's a 150 watt/ 6 channel LED driver with it's own integrated programmable controller. The original idea was to find a way to eliminate the need to run wires "all over the place". This little board will act as a "central hub"by providing power to the leds, power to cooling fans ect.. , be fully programmable for dimming control. It also will be fully expandable to read sensors and control other aquarium devices.

If it works as designed, it will definitely be a "one stop solution" for most led builds, as it eliminates the need to purchase most of the commonly needed components.


----------



## ugn (Mar 26, 2012)

> 6 OnSemi CAT4101 led Constant current Regulators w/ up to 1000ma output.( will drive 6 - 8 leds per string, provided total led Vf does not exceed 25 volts.)


Sounds very promising, but if you want to run 10W leds and about 4-8 of them.. this would not work i guess?


----------



## theblondskeleton (Aug 28, 2009)

That's pretty incredible! Nice work! I've linked this to the FAQ as 'in progress' until you have the opportunity to test it out. I'm sure there will be a lot of builders interested in this driver.


----------



## O2surplus (Jan 31, 2010)

ugn said:


> Sounds very promising, but if you want to run 10W leds and about 4-8 of them.. this would not work i guess?



Driving 10 watt leds shouldn't be a problem. All you'd have to consider the Vf of you particular 10 watt led. Most of them, that I've run across, have a Vf of around 12 volts, so you should be able to run 2 of them in series on each chip. Each CAT4101 is rated to handle up to 1000ma at 25 volts maximum ( 25 watts total), so driving (2) 10 watt emitters at 800ma would yield approximately 20 watts per string. That scenario would let you drive (12) 10 watt emitters from this driver design. I have personally used 2 CAT4101's wired in parallel to drive BridgeLux 50 watt emitters, so this driver design could be configured to drive 3 of those same 50 watt emitters.


----------



## d3snoopy (Apr 1, 2011)

Love it. Tagging along. Once you have it running well, you should get a batch of 20-40 made & sell em. I'd buy a couple.


----------



## ugn (Mar 26, 2012)

1000mA should be enough for the most guys here, but is it possible to increase the voltage, for example up to 48 volts? 
So each string could give out max 48 watt.


----------



## O2surplus (Jan 31, 2010)

ugn said:


> 1000mA should be enough for the most guys here, but is it possible to increase the voltage, for example up to 48 volts?
> So each string could give out max 48 watt.



Nope- the CAT4101 driver IC is only rated for 25 volts. That's why there's 6 of them on the board. The nice thing about shorter strings is more control or higher resolution when dimming.


----------



## hamato (Jun 7, 2008)

Is there any cutoff for the CAT4101s? That is one thing about the Meanwells I don't like, they cut out at about 30% which is still pretty bright when driven at 800ma max.
Also I wonder about moonlight support. Something like 2-3 LEDs running off one channel fully dimmable would be nice.


----------



## jcgd (Feb 18, 2004)

Nope. I have a bunch of O2's old drivers with the cats. No cut off. Mine dim all the way off and all the way on. I was warned that they make not dim if the LEDs aren't warned up, but no problems so far.


----------



## O2surplus (Jan 31, 2010)

hamato said:


> Is there any cutoff for the CAT4101s? That is one thing about the Meanwells I don't like, they cut out at about 30% which is still pretty bright when driven at 800ma max.
> Also I wonder about moonlight support. Something like 2-3 LEDs running off one channel fully dimmable would be nice.



There's no abrupt cut-off with the CAT 4101's. They can be made to dim to a fraction of 1%, provided the PWM signal frequency has been set low enough. 150Hz seems to be that magic number. It's too bad only 2 output pins on the arduino can be configured to PWM with a frequency that low.


----------



## d3snoopy (Apr 1, 2011)

O2surplus said:


> There's no abrupt cut-off with the CAT 4101's. They can be made to dim to a fraction of 1%, provided the PWM signal frequency has been set low enough. 150Hz seems to be that magic number. It's too bad only 2 output pins on the arduino can be configured to PWM with a frequency that low.


Forgive my ignorance, but aren't lower PWM frequencies easier to do? I know there is lots of code out there related to servo control running at ~60Hz - I'd think that you'd just have convert from a "built in" PWM philosophy to a manually-programmed PWM where you program discrete pulses at a given length?


----------



## O2surplus (Jan 31, 2010)

d3snoopy said:


> Forgive my ignorance, but aren't lower PWM frequencies easier to do? I know there is lots of code out there related to servo control running at ~60Hz - I'd think that you'd just have convert from a "built in" PWM philosophy to a manually-programmed PWM where you program discrete pulses at a given length?



If I'm not mistaken, I believe the normal default setting for the PWM frequency coming from the Atmega chip is set at 5KHz. The Pwm frequency can be adjusted from there- using the programming software. It's just a matter of plugging in the appropriate numbers to the programming code.


----------



## d3snoopy (Apr 1, 2011)

O2surplus said:


> If I'm not mistaken, I believe the normal default setting for the PWM frequency coming from the Atmega chip is set at 5KHz. The Pwm frequency can be adjusted from there- using the programming software. It's just a matter of plugging in the appropriate numbers to the programming code.


I'm saying that I think the approach that most of the servo control guys take is simply to do something like:

Set N = 1.5ms (servos typically receive signals in the 1-2ms range @ ~60Hz)

Loop:
Output a N ms pulse
Delay 18 ms
goto loop


So, if you adapted it to your purposes, you could do something like:

Set DutyCycle = 0.2

Loop:
Output a (DutyCycle * 7) ms pulse
Delay for [(1 - DutyCycle) * 7] ms
goto loop

Obviously, you'd have to account for everything else you wanted the controller to be doing... but with low PWM's everything happens slowly enough that you can just manually program the pulse widths and delays.


I don't know much about Aurdino, so I'm not sure how tricky it will be to get all of the multitasking right... especially when you want to be able to vary all the way from 0 to 100% duty cycle. with servo control, you can count on having at least 18ms between pulses... with a fully variable duty cycle you have to adjust where you get your extra clock cycles depending upon the desired duty cycle.


----------



## O2surplus (Jan 31, 2010)

d3snoopy said:


> I'm saying that I think the approach that most of the servo control guys take is simply to do something like:
> 
> Set N = 1.5ms (servos typically receive signals in the 1-2ms range @ ~60Hz)
> 
> ...


This driver has a clock on board and other components that can be adversely affected by altering the base PWM frequency, So I plan to just live with the default PWM settings and avoid unwanted timing "issues" that could affect reliable operation of the drivers.
The Arduino PWM outputs use 255 steps to range from 0 to 100% duty cycle across *all 6* PWM output pins. That's plenty of dimming range, considering that my personal build employs 15 CAT4101's and 90 leds. I'll simply program the drivers to dim the leds in groups of six, using a time staggered arrangement. That dimming approach should make the led dimming appear perfectly natural when viewed. I may even leave 18 leds running at 1/2% duty cycle as "Moon Lightts". I'm no Arduino expert either, but I'm sure there are people out there that could make this driver design do really neat things.


----------



## O2surplus (Jan 31, 2010)

Got an Email notification today telling me to expect a visit from "the Man in the Brown Van" sometime tomorrow. I guess I'll be doing some soldering tomorrow night and doing some tests, with pictures to follow.


----------



## theblondskeleton (Aug 28, 2009)

roud:


----------



## O2surplus (Jan 31, 2010)

The PCB's arrived from China today, so I took the time to solder one up tonight. First Impression- This is gonna be cool! I loaded the ATMEGA chip with the standard arduino "Blink" sketch just to make sure it works. All systems go! There's a red led tied in to digital pin 13, so verifying proper operation is as simple as watching for the "blink". I'll test out the actual driver section of the board sometime this weekend and post some pictures. Here's a photo of the finished driver, I paid a bit extra for "white" and I think it looks pretty clean. Let me know what you guys think. 














Running the "BLINK SKETCH"


----------



## jcgd (Feb 18, 2004)

Looks good. I want one.

So what can this do? Six drivers, six channels? But you need to get the controller coded right? 

Are you putting an LED screen with buttons and the menus on it?

I noticed the green and red led labels are swapped.


----------



## theblondskeleton (Aug 28, 2009)

Very nice  a screen with menu and buttons would be great - easier to program for some!


----------



## O2surplus (Jan 31, 2010)

jcgd said:


> Looks good. I want one.
> Thanks for the compliment- I'll send you one ( U.S. Customs doesn't scare me. It's only Canada for Pete's sake, not N. Korea.)
> 
> 
> ...


...


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> Very nice  a screen with menu and buttons would be great - easier to program for some!



Hey- Thanks, You'll get one too!

I'm going to treat this design as a prototype, so I'll make changes to the design as we go. I'm open to whatever you guys want. I suppose, after we've had a chance to nail down some software, I could design a type of LCD and button "shield" that would plug in to the PCB to provide additional functionality. This will be a work in progress, but I'll have to stay as close to the original design, in order to retain "backward" compatibility.


----------



## Pickled_Herring (Jul 26, 2010)

Wow O2 looks great! Pretty quick turn around too. It took me a month to get my Cat3 boards from itead. I would be interested in a board and would be willing to trade a few of these:


----------



## O2surplus (Jan 31, 2010)

Pickled_Herring said:


> Wow O2 looks great! Pretty quick turn around too. It took me a month to get my Cat3 boards from itead. I would be interested in a board and would be willing to trade a few of these:



Hey Thanks! LOL I nearly paid as much for shipping as the actual cost of the PCBs! But hey- I'm not patient, 10 days was pushing it for me! I got 10 boards for $25 + $10 for full E-Testing, + $10 for "white" + another $42 and change for express UPS shipping. That breaks down to about $8.70 per board, but who cares- It's just a cost of the hobby, right?

Assuming I can build all 10 to perfection, keep 3 for myself and send out 2 to the guys inline ahead of you, that leaves 5. So one will have your name on it.

Is that a 20x4 LCD with a serial connection? We could put those to use with this project, if they are. I'm sure that I've seen some good dimming code out there that would work great with an I2C enabled LCD. I'll have to hunt it down, as that's the direction I think we should be moving.


----------



## Pickled_Herring (Jul 26, 2010)

5 x 7- dot 16-character 2-line dot-matrix LCD panel. I have some better ones I'll have to see if I can get a pin-out of them.


----------



## ReluctantHippy (Jun 23, 2011)

Another amazing thread. Bravo. Out of curiosity and if you don't mind me asking, about how much is the total cost to produce one finished board?


----------



## theblondskeleton (Aug 28, 2009)

O2surplus said:


> Hey- Thanks, You'll get one too!
> 
> I'm going to treat this design as a prototype, so I'll make changes to the design as we go. I'm open to whatever you guys want. I suppose, after we've had a chance to nail down some software, I could design a type of LCD and button "shield" that would plug in to the PCB to provide additional functionality. This will be a work in progress, but I'll have to stay as close to the original design, in order to retain "backward" compatibility.


Groovy man  What are you using for a power supply, by the way? Anything special or just a wall wart?


----------



## jcgd (Feb 18, 2004)

Sweet, that's awesome, Aaron. 

I've been using Meanwell 24v power supplies. Normally they are expensive but I bought a bunch online from evilbay. The guy had limited stock do I got extras but there are lots of Chinese ripoffs on there too that would probably work okay.


----------



## O2surplus (Jan 31, 2010)

ReluctantHippy said:


> Another amazing thread. Bravo. Out of curiosity and if you don't mind me asking, about how much is the total cost to produce one finished board?



Good question! I'm populating a spreadsheet with component costs as time permits. I should have an exact cost nailed down in the next few days.


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> Groovy man  What are you using for a power supply, by the way? Anything special or just a wall wart?


Most people, Myself included, use MeanWell power supplies. I've got three 24V/6.5 amp supplies powering my original LED build. They've been going strong for nearly 3 years now so I can't complain lol. I helped a local fish store owner set up an LED lighting system for his stock tanks last year. He "cheaped out" and didn't buy the MeanWell's and went with some Chinese knock offs instead. Everything worked fine for the first couple of weeks until, as reported by a store employee, "one of the power supplies let out a bang followed by a 4 foot tall flame!" Lesson learned - "You get what you pay for". The store owner replaced all his supplies with MeanWell units and has not had any more failures to date.


----------



## hamato (Jun 7, 2008)

theblondskeleton said:


> Very nice  a screen with menu and buttons would be great - easier to program for some!


I use a combo of a 16x4 LCD and a Logitech harmony remote to control my Arduino controller. The circuit for the remote is quite simple, just a cap,resistor and a IR receiver so as long as this device has a free pin and free memory for the IR code, that would be an easy add on as well


----------



## O2surplus (Jan 31, 2010)

hamato said:


> I use a combo of a 16x4 LCD and a Logitech harmony remote to control my Arduino controller. The circuit for the remote is quite simple, just a cap,resistor and a IR receiver so as long as this device has a free pin and free memory for the IR code, that would be an easy add on as well


Hey that's a great idea! who wouldn't want the ability to adjust their lighting from across the room? Do you think you could provide me a schematic and the coding to add that function? I'd love to be able to do that.


----------



## hamato (Jun 7, 2008)

O2surplus said:


> Hey that's a great idea! who wouldn't want the ability to adjust their lighting from across the room? Do you think you could provide me a schematic and the coding to add that function? I'd love to be able to do that.


Yeah it's handy for lazy people like me 

I used a TSOP 1138 chip and pretty much exactly the example circuit described in the PDF.
http://www.vishay.com/docs/82006/tsop11xx.pdf

Here are the details on the library and the download. Terahz @ RC has some nice IR programming/menuing code that is also useful from the hydra project over therehttp://reefcentral.com/forums/member.php?u=228099. 
I had a bunch of old remotes lying around that I tested but about 20% of them didn't work with this library for whatever reason. I just picked one that did and cloned it on my harmony remote. 

http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html
http://arcfn.com/files/IRremote.zip


----------



## jcgd (Feb 18, 2004)

Hmm. This controller seems great Aaron. With the typhoon controllers I just use the lcd to make changes since I know nothing about typhoon.

With this controller we can just modify the code and upload it via usb? I may have to add a usb hub to my "ballast".

Ideally though, I'd like to add an lcd and buttons. Is there any tutorials on this that you could link me to?


----------



## jcgd (Feb 18, 2004)

I was thinking about the general setup for the lighting that we have been using... fade duration, max and on time/off time.

If we can figure out the coding, I think a more ideal setup would be like ATIs programs, where you set everything incrementally. For example.

Time: 1000-1100, 40%
Time : 1100-1400, 40%
Time: 1400-1500, 100%
Time: 1500-1600, 40%
Time: 1600-1900, 40%
Time: 1900-2000, 0%

This program would do a 1 hour ramp to 40%, stay at 40% for three hours, ramp up to 100% and back down to 40% over the next two hours (mid day burst), back to 40% for three more hours and fade off over the last hour.

The only thing I don't like now, is if I want a mid day burst it has to be super long if I want that string on all day, or I have to leave the "burst" string off until mid day.

Just an idea.


----------



## O2surplus (Jan 31, 2010)

Justin-

I know there's already someone that already created a 6 channel code for the "Typhon Controller". I haven't been able to locate it yet, as I haven't had enough free time to do so. I know that it's buried somewhere in the Typhon thread over on RC. That software would work nicely for you with this design, as it would behave just like the "typhon controllers" that you already have. Once I get this new driver/controller tested and sorted out, I'll try to get a collection of different sketches put together and post them in this thread. That way people who want to use this design will have enough software options to choose from.
I'm going to concentrate for now on the hardware side of this project. There could be problems with it that I didn't catch before having the boards made. I have to make sure that the Arduino, DS1307, and all six CAT's will "play nice" with each other reliably, before I pass these out to other user's. Once I'm sure of the hardware design, we'll get to the software side of the project. My "day job" and my two small kids are keeping me quite busy right now, so this could take a while.


----------



## shrimpNewbie (May 6, 2011)

Hey Aaron liking the Idea of using one of these on a future build! Will be watching this for updates, also I have your plants bagged if you want to meet at ob or somewhere with nice angels? I don't think I have as many stems for you this time around by the quality is higher. I also got the power supply and I figured out how long the line from the controller to the driver needs to be, I'm gonna have it at 8'6" hoping the curren will still get to it, if you feel I need a thicker wire I don't mind I'd rather have the led run correctly. Let me know if and when today I work at 3


----------



## shrimpNewbie (May 6, 2011)

By the way your 225 is super impressive, saw a few for the first time last night on someone's thread about LEDs. Looking forward to seeing the new scape


----------



## ugn (Mar 26, 2012)

Hope you can build more of these, as demand surely will be there.
Would love 1-2 of these ;D


----------



## O2surplus (Jan 31, 2010)

ugn said:


> Hope you can build more of these, as demand surely will be there.
> Would love 1-2 of these ;D


I've never shipped anything to Norway..... yet! Give me some time to sort this new driver out and I'll see about getting you a copy.


----------



## drhemlock2 (Aug 11, 2012)

this is just what i was thinking about a ph sensor and temp etc. this is a good idea
doc


----------



## drhemlock2 (Aug 11, 2012)

O2surplus said:


> Can You guys think of anything else I should add? I'm thinking that I'll add a transistor to switch the 12v output off/on. That way cooling fans can be controlled directly and can be programmed to follow the Off/on times of the LEDS. I"m also thinking that I should "breakout" more pins on the micro-controller chip so that all the analog inputs can be addressed and used. I can see a situation where someone may want to add a temp sensor to their LED rig, measure Ph, or add an LCD display. I guess the possibilities are only limited by ones imagination. I just want this gadget to be as feature packed as possible before I pull the trigger and order the PCB's


this is just what i was thinking about a ph sensor and temp etc. this is a good idea
doc


----------



## ReluctantHippy (Jun 23, 2011)

I have some memory problems and didn't realize you were the one posting on my cheapo Chinese led thread the other day or I would have blown you up with compatibility questions. 

I would have to reread the thread to make sure but I think you stated earlier that your wonder driver could be applied to running the higher wattage arrays I'm using. If you don't mind saving me the time of rereading, could a single PCB power all 3 of the 50w arrays I have on each of my panels? 2 CATs per array should work right? 

I have another question about dimming arrays but I'll have to work on reminding myself what question I had and get back to you.

Thanks!


----------



## Pickled_Herring (Jul 26, 2010)

Hey O2 any update on the board?


----------



## O2surplus (Jan 31, 2010)

ReluctantHippy said:


> I have some memory problems and didn't realize you were the one posting on my cheapo Chinese led thread the other day or I would have blown you up with compatibility questions.
> 
> I would have to reread the thread to make sure but I think you stated earlier that your wonder driver could be applied to running the higher wattage arrays I'm using. If you don't mind saving me the time of rereading, could a single PCB power all 3 of the 50w arrays I have on each of my panels? 2 CATs per array should work right?
> 
> ...


The answer to your question depends on the Vf of the particular led arrays that your using. The CAT4101's are only rated to run reliably up to 25 volts. If the Vf of you leds is higher than that then - No, it isn't possible . If their Vf is lower than 25 volts, then it's possible. I have some big 50 watt BridgeLux led arrays (BXRA-C4500) that have an average Vf of 25.6 volts that I've successfully driven at 2,000ma using two CAT4101's wired in parallel. I had six led arrays mounted in an old Current PC lamp housing that I built just for fun. It was rated to produce 30.000 lumens :icon_twis I lent it to one of my LFS for testing, and they ended up bleaching a lot of coral with it. LOL Here's a picture of it, blasting away in my kitchen.


----------



## O2surplus (Jan 31, 2010)

Pickled_Herring said:


> Hey O2 any update on the board?


I've built 6 of them so far, but I have to order another 24 CAT4101's to complete the remaining 4. I did find one small defect in the design, but it was easily fixed by soldering in a small jumper wire. I had inadvertently named a connection "5 volts" instead of "VCC" and that resulted in a broken connection between the 5v pin @ the I2C connection and VCC on the board. I've already fixed that issue in the EAGLE files.

I've got one of the units driving 5 channels of leds from my original build right now. I programmed it to dim each string from full power to off over the space of one hour, and staggered the start time by 10 minutes between each string. The effect is pretty cool to watch as the leds begin to dim in turn from one end of the lighting fixture to the other. I'll have to make a video of it and post it to youtube, but I'll have to adjust the program to speed up the dimming program a bit. Nobody wants to waste an hour to watch it in real time.LOL


----------



## wastedtime (Oct 27, 2011)

O2surplus said:


>


Wow that thing is bright. Do you wear one of those masks made for welding while handling those ? I accidentally stared into my LED fixture once, couldnt see much for a couple of hours after that :icon_sad:


----------



## ReluctantHippy (Jun 23, 2011)

Lol, love the picture. Half expected to see molten kitchen tiles flowing from that glow. Maybe 6 50w arrays over my 55g is overkill... but then perhaps it's just what I need to grow some monster cattails. 

Hmm, I'll have to check the actual voltage or my arrays. My current drivers are listed as putting out 1500mA 28-40v but they are cheapo cheapo so paired with my cheapo arrays I'm not sure I trust the label.


----------



## theblondskeleton (Aug 28, 2009)

Haha- wow! That thing is intense!


----------



## O2surplus (Jan 31, 2010)

Yeah that thing was bright. It's too bad that I don't have another tank to put it over. I'm probably going to gut that fixture and use the leds in other lighting projects around the house. I've been slowly converting all of my home's lighting over to led, so those big BridgeLux arrays will come in handy.


----------



## Pickled_Herring (Jul 26, 2010)

Just curious since you say that you are replacing all the lighting in your house with LEDs, that's something I was thinking of doing. Are you replacing your current fixtures, modifying them, or just swapping out the bulbs?


----------



## O2surplus (Jan 31, 2010)

Pickled_Herring said:


> Just curious since you say that you are replacing all the lighting in your house with LEDs, that's something I was thinking of doing. Are you replacing your current fixtures, modifying them, or just swapping out the bulbs?



I'm doing a combination of both. I replaced all the lighting in my kitchen with leds first. Actually.... I had to. It was done to correct an earlier mistake. My wife hated the fluorescent lighting that was put in originally when the house was built, so she "asked" me to replace it with (6) 4" recessed can lights. I did what she wanted and she was happy with the result. She now was able to cook under the glow of 6 35watt Halogen bulbs that produced a nice "warm white" light and good CRI. I however, was not happy at all. I'm 6'-5", and when I walked into the kitchen it felt as if someone had lit a match and tossed it on top of my head! Those 35watt halogens get hot! and they burn out often. I hated being in the kitchen, and hated replacing those dang bulbs all the time. I decided that something had to be done, so I began looking for a solution. This was a few years ago when led lighting for the home had just started to appear on the market. I found a local lighting supplier that had just began stocking led bulbs in his store, and he was kind enough to "loan" me a new GU10 bulb constructed with Cree leds. I took it home for a "test drive" and liked what I saw. The bulb only consumed 4watts of power, put out plenty of light, and didn't fry my scalp. I was sold, I purchased 6 for $150 (ouch!) and they still work perfectly to this day! I also added under cabinet led lighting to augment the main lighting by using led light strips that were originally intended for automotive use. They're a flat ribbon of white SMD leds wrapped in water proof plastic lined on one side with double sided adhesive tape. I installed 12' worth under the cabinets and powered them with a 12 supply that was wired to a conventional wall mounted light switch. I'm slowly replacing all the other bulbs around the house with led powered bulbs and have a few plans in the works for some "DIY custom built stuff" for locations that don't currently have any lighting at all.


----------



## theblondskeleton (Aug 28, 2009)

I have those GU10 halogens as well. They don't last very long at all, and I agree they burn super hot. I found some LEDS a few years ago, but I got the cheapies and of course, they fell apart. None of them have the Crees, however. I'll have to keep an eye out for those.


----------



## O2surplus (Jan 31, 2010)

I finally got around to opening a you tube account tonight. So I'll post a video of the new 6 channel driver in action, just as soon as I time to shoot it. Until then here's a link to a video of my tank as it looks right now. I planted it with a few cuttings that SHRIMPNEWBIE gave me about six weeks ago. I can't remember the name of all the plants off hand right now, but I'm sure most people will recognize a few. I'm really liking the Ludwigia Var. "Cuba" a lot. I recently added 3 more 50watt led arrays to the mix to really raise the PAR a bit and maintain the red coloration of the plants. I'm up to 420 watts so far with high CO2 injection rates and additional Macro-nutrients added to fuel the extra quick plant growth. Check out the video and Notice the bubbling Oxygen due to the *O2Surplus* I was forced to do a big trim over the weekend, so some of the "bushes" may appear a bit unkempt.

http://www.youtube.com/watch?v=NuylLCUmxtE&feature=youtu.be


----------



## skanderson (Jul 25, 2010)

great thread thanks for all the work. i am going to be putting together a bunch of different diy leds in the nearish future and love the idea of having dimming and driving consolidated like that and especially in that price range. my current diy used xml u2s driven at near 2m each in strings of 6. would your chip be able to handle xmls at that kind of amperage. i have also heard about a new luxeon M being a good new led for freshwater and vivarium builds. would that be a better fit for this driver and if so how many could you power at 1000ma. thanks again and hopefully i will be able to order up a few of these from you in the near future.


----------



## O2surplus (Jan 31, 2010)

skanderson said:


> great thread thanks for all the work. i am going to be putting together a bunch of different diy leds in the nearish future and love the idea of having dimming and driving consolidated like that and especially in that price range. my current diy used xml u2s driven at near 2m each in strings of 6. would your chip be able to handle xmls at that kind of amperage. i have also heard about a new luxeon M being a good new led for freshwater and vivarium builds. would that be a better fit for this driver and if so how many could you power at 1000ma. thanks again and hopefully i will be able to order up a few of these from you in the near future.


Hey Thanks for the compliments. The CAT4101 is rated for led loads up to 25 volts and 1000ma. The Cree XM-L's that you mention *can be driven* to 2,000ma or even 3,000ma. All it takes is additional CAT chips wired in to the negative side of each led string. 2000ma requires 2 chips, 3,000ma requires 3. Since my driver board has 6 driver chips, you could drive 3 strings of 6-7 XM-L's @ 2,000ma OR 2 strings of 6-7 XM-L's @ 3,000 ma. All it takes is a little creative wiring. If you want to see a build using CREE XM-L's and CAT4101 drivers, check out JCGD's tank thread. He's using drivers that I built for him. 165 Impulse Build (56k) --- New FTS post #208


----------



## ReluctantHippy (Jun 23, 2011)

How much heat does this thing generate? Say all CAT4101s are running full blast - some heat? a bit of heat? tons of heat? Thanks again.


----------



## O2surplus (Jan 31, 2010)

ReluctantHippy said:


> How much heat does this thing generate? Say all CAT4101s are running full blast - some heat? a bit of heat? tons of heat? Thanks again.



The amount of heat produced by the chips is heavily dependent on the amount of voltage the Cat4101 is forced to drop while regulating the led current. The Cat4101 is a linear (low drop out) current regulator and does require a bit of extra voltage over the led string voltage to do it's job. According to the OnSemi engineering specs for the chip, the amount of voltage "headroom" should be set approximately 1/2 to 8/10ths of a volt above the led strings voltage. This is why it's important to balance the Vf's of multiple strings to one another, and have a power supply that has an adjustable voltage output. Using my lighting system as an example, this is how I do it. Each one of my arrays is comprised of 5 strings of 6 leds per string, driven by a single Cat4101, and powered by a 24volt/6.5 amp power supply. I measure the total Vf of each led string and then take an average. In most cases the average string Vf measured around 20.5 volts. I then adjusted the voltage of my power supply down to around 21.2 volts. With the proper adjustment made, the CAT's operate just warm to the touch, and have been working flawlessly for nearly 3 years running. The CAT4101's do feature thermal protection. If it is ever caused to overheat, it will turn itself off until it has had a chance to cool down a bit. Since I build a lot of these drivers for other people, and I'm not there to make the necessary voltage adjustments,I now place a lot of emphasis on building them to run cool from the start. My latest driver design and the "SmaryCat" Driver/controller combo come with a fan cooled heat sink as standard equipment. The Heat sink/cooling fan is attached to the bottom of the PCB and secured with screws or thermal epoxy. I construct them this way to add a bit of insurance to them, as they'll continue to run cool enough to be reliable, even if the end user doesn't provide the correct voltage adjustments. I'll post a picture of the completed "SmartyCat" with it's fan cooled heat sink later, to show you what I'm describing.


----------



## O2surplus (Jan 31, 2010)

Here's 6 of the "SmartyCats"











and a view of the heat sink and cooling fan,













Here's a side view- There's plenty of cooling capacity there ( if needed )


----------



## ReluctantHippy (Jun 23, 2011)

So pretty. I appreciate the heat breakdown and the pics with heatsinks. I'd be begging for one if I thought I'd be able to wire it up to my lights successfully. Can't wait for the video of it in action - the last video was very impressive; Great tank.


----------



## O2surplus (Jan 31, 2010)

A certain "Fish w/ a drinking problem" asked for the EAGLE files for the "SmartyCat". I included a bill of materials that also lists what I paid for the parts with shipping charges included. The total cost is just shy of $70 per unit. 

I have parts on order to finish out the remaining 3. Since I don't have use for 7 of them, I'll sell them for my cost to anyone who's interested in having one. Just send me a PM. If interest in this exceeds supply- no worries, I'll order more PCB's and build more of them, as this is just another hobby that I enjoy, and no one should go away "empty handed".


----------



## Pickled_Herring (Jul 26, 2010)

Hey that guy should seek professional help for his problem. Thank you so much for posting the files and I'll toast you later tonight with a completely drinkable bottle of Montepulciano wine. Just by coincidence I got my order for cat1401s from Future electronics today.


----------



## O2surplus (Jan 31, 2010)

Pickled_Herring said:


> Hey that guy should seek professional help for his problem. Thank you so much for posting the files and I'll toast you later tonight with a completely drinkable bottle of Montepulciano wine. Just by coincidence I got my order for cat1401s from Future electronics today.



Your welcome! (I'm a Guinness aficionado myself) It's funny I checked them a few day's ago and they claimed to have none, zero, nada, zilch! I ordered 36 of them from DIGIKEY @ a cost of $2.47 each. They should be here by Tuesday of next week. Here's a link that's saved me a lot of time, when it comes to chasing down electronic parts- FindChips.com Error Just punch in a part # and let it do all the searching for you.


----------



## O2surplus (Jan 31, 2010)

I never had given much thought to hard it is to make a video of an led dimming simulation. I've been trying, but no matter how dim I set the leds, their light overwhelms my camera. By the time one channel of six reaches just 50ma - you can't see what the other channels are doing. This is very frustrating. I don't know how to proceed? Employ some kind of filter?

New Sig photo?


----------



## theblondskeleton (Aug 28, 2009)

Good lookin' stuff, O2!


----------



## Dan Knowlton (Jan 9, 2009)

O2surplus said:


> I never had given much thought to hard it is to make a video of an led dimming simulation. I've been trying, but no matter how dim I set the leds, their light overwhelms my camera. By the time one channel of six reaches just 50ma - you can't see what the other channels are doing. This is very frustrating. I don't know how to proceed? Employ some kind of filter?
> 
> New Sig photo?


Maybe a neutral density filter would help.

Dan K.


----------



## Pickled_Herring (Jul 26, 2010)

I think that you would have to put the camera in manual mode and turn off the automatic light level compensation.


----------



## O2surplus (Jan 31, 2010)

Pickled_Herring said:


> I think that you would have to put the camera in manual mode and turn off the automatic light level compensation.


Yeah- I'll probably just have to spend the time necessary to learn how to use my digital camera. It's a CANON "Power Shot" SD880 IS "Digital Elph". I bought it just to take photos on my job, which it does just fine. I'm not a photographer, so there's a bit of a learning curve for me when it comes to doing more creative things involving a camera. "White balance","F-stop" and all that camera jargon is still Greek to me -LOL.


----------



## silvawispa (Oct 11, 2011)

After a quick glance through your camera's manual (http://gdlp01.c-wss.com/gds/8/0300001448/01/PSSD880IS_IXUS870IS_CUG_EN.pdf), it doesn't look like you get a choice of shooting video with a fixed exposure. This is a bad thing as that's what you need to be able to show off your drivers abilities. I may have missed something.
Grab a mate with a dSLR that has video. Sadly I'm a bit far away otherwise I'd be more than happy to do it.
I'm definitely interested in these drivers as they offer the "stage lighting" options I'd like to be able to use to dramatise my tank. Having them optimised for plant welfare while I'm out and for viewing whilst I'm in sounds fantastic. Not to mention the ability to rearrange lighting patterns to go with rescapes...


----------



## O2surplus (Jan 31, 2010)

silvawispa said:


> After a quick glance through your camera's manual (http://gdlp01.c-wss.com/gds/8/0300001448/01/PSSD880IS_IXUS870IS_CUG_EN.pdf), it doesn't look like you get a choice of shooting video with a fixed exposure. This is a bad thing as that's what you need to be able to show off your drivers abilities. I may have missed something.
> Grab a mate with a dSLR that has video. Sadly I'm a bit far away otherwise I'd be more than happy to do it.
> I'm definitely interested in these drivers as they offer the "stage lighting" options I'd like to be able to use to dramatise my tank. Having them optimised for plant welfare while I'm out and for viewing whilst I'm in sounds fantastic. Not to mention the ability to rearrange lighting patterns to go with rescapes...


Thanks for taking a look at the "camera issue". Sadly, I don't know anyone that owns a DSLR camera that could help me out. The way I see it- the real advantage to this driver is the "packaging". It will behave just like any other arduino controlled led driver, but with less of the wiring mess normally involved. I've already passed a couple of these out to other members to play with, hopefully one of them will be able to make a video as part of their build thread.


----------



## silvawispa (Oct 11, 2011)

If you can sell me a driver I can take the video.


----------



## O2surplus (Jan 31, 2010)

silvawispa said:


> If you can sell me a driver I can take the video.



Thanks for the offer, I sent you a PM.


----------



## theblondskeleton (Aug 28, 2009)

Now, that is a sexy piece of electronics  nice job, O2, and thanks man! I'll let you know as soon as I can fire this up! It may be a few weeks, though. Thanks again!


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> Now, that is a sexy piece of electronics  nice job, O2, and thanks man! I'll let you know as soon as I can fire this up! It may be a few weeks, though. Thanks again!



You're Welcome- I'm glad you like it. Here's a copy of a "sketch" that will take advantage of all 6 channels. Give it a try when you're ready.


----------



## theblondskeleton (Aug 28, 2009)

Warning: barrage of noob questions coming:

Ok, so for a power supply... I need around 48v to run my emitters. Specifically, would a pair of these work? I think 1.1A is plenty of current, as 500mA is already more than I need, haha... 

1. Do I just plug this into the Power Input on the board?
2. What if I need more than 2 power supplies? How/where do I wire those in?

I'm also a total noob when it comes to programming one of these things. I have a Mac, but that doesn't seem to be an obstacle. Just my ignorance. 

1. What do I need to connect this to my computer? Also, to what inputs on the board do I connect it?
2. Do I just use the Arduino software to load the sketch?

Last questions:

1. Not sure what the extra connectors are for... do these connect the drivers to the controller via the input pins? 
2. If so, do I need to connect drivers I do not use (I will only need 4)?

Thanks for the help on these - I'm very inexperienced with PCB's, so I'm not too sure what I'm looking at. However, I'm clever enough to get myself into trouble if I try to figure it out on my own, haha...


----------



## O2surplus (Jan 31, 2010)

OK- Here we go! I can't post a FleaBay link for obvious reasons, but go there and look for a MeanWell RS-150-24 power supply. They're available for around $32 brand new and can supply enough current to drive the "SmartyCat" to full power, should you ever choose to. You'll also need a USB to FTDI adapter to program the board and you can find those on flea bay too. Here's a photo of the board with the programming adapter connected.









If you don't already have the arduino software it's available here. http://arduino.cc/en/Main/Software look for the "older IDE Version 23" not Version 1.0. Version 23 works well with the "Sketch" that I posted earlier.

The jumper wires that I sent you get connected from any one of the six available PWM output pins (Arduino ) to the PWM input header (Cat4101). You don't need to connect all six, if you're only using 4 channels.
I'll draw up a photo of the SmartyCat with all typical connections and post it later. Hopefully I've provided enough info to get you started.


----------



## theblondskeleton (Aug 28, 2009)

Perfect, thanks! That's pretty much what I needed!


----------



## Mcg177 (Apr 6, 2011)

do you have any left ??? i WANT ONE!


----------



## O2surplus (Jan 31, 2010)

Mcg177 said:


> do you have any left ??? i WANT ONE!


I sent you a PM.


----------



## kennyishio (Oct 18, 2012)

This is the most awesome I've seen since ever! Holy Moly! Question why can't we just use one 549 resistor and wire all the cat4101 to that one chip?


----------



## O2surplus (Jan 31, 2010)

kennyishio said:


> This is the most awesome I've seen since ever! Holy Moly! Question why can't we just use one 549 resistor and wire all the cat4101 to that one chip?


Thanks for the compliments, I'm glad you like it. I wish it were that simple but, each CAT4101 needs it's own reference resistor to work properly. The chip attempts to maintain 1.2 volts across the resistor and the current needed to attain that voltage ends up being 1/400 of the actual current driven through the leds.


----------



## kennyishio (Oct 18, 2012)

I'm going to try to making a 10X cat4101 with ATmega328. The only thing that is bugging me is the PCB. I can't get away without using one can I? I dunno if you can tell. I'm a super noob O_O.


----------



## O2surplus (Jan 31, 2010)

kennyishio said:


> I'm going to try to making a 10X cat4101 with ATmega328. The only thing that is bugging me is the PCB. I can't get away without using one can I? I dunno if you can tell. I'm a super noob O_O.



You'll need a PCB as the CAT4101 is only available in a surface mount package. Be aware that you'll need to design in provisions for adequate cooling. The Cat chips are linear current regulators that can quite hot if their source voltage isn't closely matched to their led load.
I only used 6 per PCB because that matched the number of PWM outputs available from the Atmega 328. If you haven't done so already, download the freeware version of EAGLE available here- Downloads | Get The Latest Version of EAGLE | CadSoft EAGLE |and use the design files that I posted earlier in this thread to create your own schematic and PCB. You can edit my schematic using the "copy" command to add as many CAT4101s as you wish. Good Luck


----------



## kennyishio (Oct 18, 2012)

Ok, I'll do that ! I'm just iffy about making the eagle board correctly. Which company did you go through?


----------



## O2surplus (Jan 31, 2010)

kennyishio said:


> Ok, I'll do that ! I'm just iffy about making the eagle board correctly. Which company did you go through?


My PCB's were manufactured by Seeedstudios in China. They'll make you 10 pcb's measuring 10cm x10cm for as little as $25. Here's a link- Services : Seeed Studio Bazaar, Boost ideas, extend the reach
Just be aware that their "free shipping" can take up to 6 weeks. I paid considerably more for mine because I went with expedited shipping, full testing of the PCB's and a non standard color. My order came in at $87.


----------



## dspangler (Dec 13, 2011)

This...is...just...AWESOME!!!

I've been following this for a while now, and it's looking more and more exactly what I need. Do you have any left?

I'm waiting on the LED's and have been holding off on the drivers 'cuz I'm still going back and forth with design/layout and power/driver. As soon as I get close to a decision on one, something about the other doesn't match, changing decision one, which changes decision 2.....Vicious cycle. Problem may have been solved right here.

Oh, and the WAF is an issue also. I'll make that work, though. It'll probably be a situation where it is easier to ask for forgiveness than to ask for approval.

Also, how easy to add Temp, PH, etc?

Dave


----------



## theblondskeleton (Aug 28, 2009)

This totally clears up the issues and confusion with drivers. The biggest issues I had with my build was figuring out what drivers to get so I could control it the way I wanted. Many birds- one little stone


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> This totally clears up the issues and confusion with drivers. The biggest issues I had with my build was figuring out what drivers to get so I could control it the way I wanted. Many birds- one little stone


Have you had a chance to set yours up yet? I've passed out 4 of these so far. So I'm just waiting patiently to see how well these work for others.


----------



## theblondskeleton (Aug 28, 2009)

I just got my FTDI adapter yesterday, (should have ordered it stateside) so I'm assembling it tomorrow. I'll let you know how it goes! 

It'll take some rewiring, but it shouldn't be a big deal. That's the whole reason I went with the fancy heat sink


----------



## theblondskeleton (Aug 28, 2009)

So, found my first issue, haha...

I'm trying to upload the sketch, and I am getting an error.

I'm not sure what I'm missing here. I have the Time.h file, so I'm not sure what it means by "no such directory". Am I missing a file? It's bound to be something idiotically simple. This is my first go with any kind of coding, so I feel like I'm playing with fire a bit. Here's what it looks like:










I saved it as a separate file and renamed it "B" in case I screwed something up. Which I probably did.


----------



## theblondskeleton (Aug 28, 2009)

Ok, I had apparently installed the libraries incorrectly. That's fixed. Now, I'm getting a new set of errors, and I don't know what the fix is:

SmartyCat_6_channel_codeB:84: error: 'byte second' redeclared as different kind of symbol
/Users/seankelly/Documents/Arduino/libraries/Time/Time.h:93: error: previous declaration of 'int second(time_t)'
SmartyCat_6_channel_codeB:84: error: 'byte month' redeclared as different kind of symbol
/Users/seankelly/Documents/Arduino/libraries/Time/Time.h:99: error: previous declaration of 'int month(time_t)'
SmartyCat_6_channel_codeB:84: error: 'byte year' redeclared as different kind of symbol
/Users/seankelly/Documents/Arduino/libraries/Time/Time.h:101: error: previous declaration of 'int year(time_t)'
SmartyCat_6_channel_codeB:268: error: expected unqualified-id before '/' token
SmartyCat_6_channel_codeB:268: error: expected constructor, destructor, or type conversion before '/' token
SmartyCat_6_channel_codeB.cpp: In function 'void loop()':
SmartyCat_6_channel_codeB:345: error: cannot resolve overloaded function 'second' based on conversion to type 'byte*'
SmartyCat_6_channel_codeB:349: error: 'DS1307_HR' was not declared in this scope
SmartyCat_6_channel_codeB:353: error: 'DS1307_MIN' was not declared in this scope
SmartyCat_6_channel_codeB:357: error: 'DS1307_SEC' was not declared in this scope
SmartyCat_6_channel_codeB:361: error: 'DS1307_MTH' was not declared in this scope
SmartyCat_6_channel_codeB:365: error: 'DS1307_DATE' was not declared in this scope
SmartyCat_6_channel_codeB:369: error: 'DS1307_YR' was not declared in this scope

Anyone? I'm a hopeless noob, here. I have never done any coding, and I just want this thing to work, haha...


----------



## O2surplus (Jan 31, 2010)

I looks to me like you're trying to compile and load a "library" file. Library files can be identified by the ".h" at the end of the file name. Make sure to place that file and any others with the same ".h" into the Arduino 23 "Library" folder. The actual Program "Sketch" will have ".cpp" at the end of the file name. When you open and then "verify/compile" the sketch, the libraries that are called out in that sketch will be accessed and integrated into the actual binary code that is transferred to the chip.

Here's some code that "Sink" wrote. It makes setting the time a breeze. Just copy and paste this into the Arduino23 IDE and name it the "Time_set" sketch. Load this one first to set the time and then load the "Smartycat" sketch( be sure to adjust the start/stop/fade duration/max led intensity values to your liking before loading)


```
/*
 * Name:	timeset.pde
 * Author:	User "sink" at plantedtank.net forums
 * URL:		http://bitbucket.org/akl/tank-control
 *
 * This code sets the time on a DS1307 RTC chip attached to an Arduino
 * microcontroller board.  The time is set to the system time when the
 * sketch was compiled (using preprocessor macros), so make sure that:
 *
 *     1. Your system (PC) time is accurate.
 *     2. You recompile the sketch and then upload immediately.
 *
 * The time is skewed forward some seconds to accomodate for compilation and
 * upload time.  If you find the time is consistently off by the same amount,
 * you can modify the adjustment constant below.
 *
 * This code requires the following libraries: Wire, Time, DS1307RTC
 *
 * The latest version of this code can always be found at above url.
 */

/*
 * Copyright (c) 2011, User "sink" at plantedtank.net forums
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.

 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.  
 */

#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>

/*
 * Time adjustment forward in seconds.  Used to compensate for
 * compilation/upload time.
 */
const int kAdjustment = 20;

/*
 * Utility function for pretty digital clock time output
 * From example code in Time library -- author unknown
 */
void printDigits(int digits) {
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

/*
 * Display time
 * Adapted from example code in Time library -- author unknown
 */
void digitalClockDisplay() {
  Serial.print(hour());
  printDigits(minute());
  printDigits(second());
  Serial.print(" ");
  Serial.print(month());
  Serial.print("/");
  Serial.print(day());
  Serial.print("/");
  Serial.print(year()); 
  Serial.println(); 
}

void setup() {

  // convert compilation time and set system clock
  char const *date = __DATE__;
  char const *time = __TIME__;
  int sec, min, hour, day, month, year;
  
  char s_month[5];
  static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
  sscanf(date, "%s %d %d", s_month, &day, &year);
  month = (strstr(month_names, s_month)-month_names)/3;
  sscanf(time, "%d:%d:%d", &hour, &min, &sec);

  setTime(hour, min, sec, day, month+1, year);
  adjustTime(kAdjustment); // crude fwd correction
  time_t t = now();

  // set RTC
  RTC.set(t);

  Serial.begin(115200);
}

void loop () {
  digitalClockDisplay();  
  Serial.println(); 
  delay(1000);
}
```


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> Ok, I had apparently installed the libraries incorrectly. That's fixed. Now, I'm getting a new set of errors, and I don't know what the fix is:
> 
> SmartyCat_6_channel_codeB:84: error: 'byte second' redeclared as different kind of symbol
> /Users/seankelly/Documents/Arduino/libraries/Time/Time.h:93: error: previous declaration of 'int second(time_t)'
> ...


It looks to me like you may have the "wrong" library installed in your library folder. I can compile that copy of the sketch without issue, so I'd imagine that there has to be an incompatible library that's installed on your pc. I'll try to put together a folder with all the needed "stuff" to get you up and running. Might take some time though - I gotta chase the kids today


----------



## theblondskeleton (Aug 28, 2009)

This may be the issue: I have a Mac. I've seen in the forums that the names for some things are different (I really have no clue about this stuff). Would this account for the errors?


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> This may be the issue: I have a Mac. I've seen in the forums that the names for some things are different (I really have no clue about this stuff). Would this account for the errors?


It may have something to do with it, but I'm not sure. Have you tried loading some of the more basic sketches, like "Blink", just to see what happens? The red LED is already connected to digital pin 13 on the Smartycat, just like an "off the shelf" Arduino, so there's no need for any other connections. Just run the sketch and see what happens.


----------



## theblondskeleton (Aug 28, 2009)

I did - Blink functions perfectly. No errors  The code you posted from Sink runs and installs with no issues, but still getting errors with the SmartyCat sketch.


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> I did - Blink functions perfectly. No errors  The code you posted from Sink runs and installs with no issues, but still getting errors with the SmartyCat sketch.



That's weird. Try this copy. There are only two Libraries included, so if it doesn't compile properly, maybe the library you have is wrong or corrupted in some way.



```
/*
// ATMEG328P-AU Microcontroller LED lighting controller for aquarium use. 
// The programming code uses a DS1307 Real Time clock to set the LED lighting schedule. Current date and time can be accessed with the serial monitor set to 9600 baud.
// sunrise/sunset time,length of fade duration, and the length of the day are selectable via the programmed schedule.  
//  Circuit description
// PWM pins described below connected to dimming circuits on drivers spread among 6 seperate channels.
// DS1307 RTC ( real time clock) connected via I2C protocol.
*/



// Pins to control each channel LEDs. Change these if you're using different pins.

int oneLed = 3;       // LED PWM arduino pin for channel one.

int twoLed = 5;       // LED PWM arduino pin for channel two 

int threeLed = 6;     // LED PWM arduino pin for channel three

int fourLed = 9;      // LED PWM arduino pin for channel four

int fiveLed = 10;     // LED PWM arduino pin for channel five

int sixLed = 11;      // LED PWM arduino pin for channel six


#include <WProgram.h>
#include <DS1307.h> 
// written by  mattt on the Arduino forum and modified by D. Sjunnesson



// Set up RTC

#include "Wire.h"

#define DS1307_I2C_ADDRESS 0x68



// RTC variables

byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year;



// Other variables. These control the behavior of lighting. Change these to customize behavior.

int minCounter = 0;         // counter that resets at midnight. Don't change this.



int oneStartMins = 540;     // minute to start channel 1. Change this to the number of minutes past midnight you want to start

int twoStartMins =420;      // minute to start channel 2. Change this to the number of minutes past midnight you want to start                         

int threeStartMins =540;    // minute to start channel 3. Change this to the number of minutes past midnight you want to start 

int fourStartMins =420;     // minute to start channel 4. Change this to the number of minutes past midnight you want to start 

int fiveStartMins =420;     // minute to start channel 5. Change this to the number of minutes past midnight you want to start 

int sixStartMins =420;      // minute to start channel 6. Change this to the number of minutes past midnight you want to start 


int onePhotoPeriod = 720;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int twoPhotoPeriod = 960;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day                           

int threePhotoPeriod = 720; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fourPhotoPeriod = 960;  // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fivePhotoPeriod = 960;  // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int sixPhotoPeriod = 960;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day


int fadeDuration = 180;      // duration of the fade on and off for sunrise and sunset. Change
                            
//    this to alter how long the fade lasts.

int oneMax = 100;           // max intensity for this channel. Change if you want to limit max intensity.

int twoMax = 100;           // max intensity for this channel. Change if you want to limit max intensity. 

int threeMax = 100;         // max intensity for this channel. Change if you want to limit max intensity.

int fourMax = 100;          // max intensity for this channel. Change if you want to limit max intensity.

int fiveMax = 100;          // max intensity for this channel. Change if you want to limit max intensity.

int sixMax = 100;           // max intensity for this channel. Change if you want to limit max intensity.

/****** LED Functions ******/

/***************************/

//function to set LED brightness according to time of day

//function has three equal phases - ramp up, hold, and ramp down

void setLed(int mins,    // current time in minutes
            
int ledPin,  // pin for this channel of LEDs
            
int start,   // start time for this channel of LEDs
            
int period,  // photoperiod for this channel of LEDs
            
int fade,    // fade duration for this channel of LEDs
            
int ledMax   // max value for this channel
            
)  {
  
if (mins <= start || mins <= mins > start + period)  {
    
analogWrite(ledPin, 0);
  
}// This is when the led's are off, thus ledVal =0
  
if (mins > start && mins <= start + fade)  {
    
analogWrite(ledPin, map(mins - start, 0, fade, 0, ledMax));
  
}// This is sunrise. Leds slowly brighten to full intensity
    
if (mins > start + fade && mins <= start + period - fade)  {
   
analogWrite(ledPin, ledMax);
  
}//This is when the led's are at maximum intensity
    
if (mins > start + period - fade && mins <= start + period)  {
    
analogWrite(ledPin, map(mins - start - period + fade, 0, fade, ledMax, 0));
  
}// This is sunset. LEDs slowly fade out.

}



/***** RTC Functions *******/

/***************************/

// Convert normal decimal numbers to binary coded decimal

byte decToBcd(byte val)

{
  
return ( (val/10*16) + (val%10) );

}



// Convert binary coded decimal to normal decimal numbers

byte bcdToDec(byte val)

{
  
return ( (val/16*10) + (val%16) );

}



// 1) Sets the date and time on the ds1307

// 2) Starts the clock

// 3) Sets hour mode to 24 hour clock

// Assumes you're passing in valid numbers.



/* //remove the forward slash and asterisk at the far left to activate the time date setting code




void setDateDs1307(byte second, // 0-59 
                   
byte minute, // 0-59
                   
byte hour, // 1-23
                   
byte dayOfWeek, // 1-7
              
byte dayOfMonth, // 1-28/29/30/31
                   
byte month, // 1-12
                   
byte year) // 0-99

{
   
Wire.beginTransmission(DS1307_I2C_ADDRESS);
   
Wire.send(0);
   
Wire.send(decToBcd(second));
   
Wire.send(decToBcd(minute));
   
Wire.send(decToBcd(hour));
   Wire.send(decToBcd(dayOfWeek));
   
Wire.send(decToBcd(dayOfMonth));
   
Wire.send(decToBcd(month));
   
Wire.send(decToBcd(year));
   
Wire.endTransmission();
     
                             

}

*/ //remove the forward slash and asterisk at the far left to activate the time date setting code



// Gets the date and time from the ds1307 via the I2C protocol.

void getDateDs1307(byte *second,
          
byte *minute,
          
byte *hour,
          
byte *dayOfWeek,
          
byte *dayOfMonth,
          
byte *month,
          
byte *year)

{
  
Wire.beginTransmission(DS1307_I2C_ADDRESS);
  
Wire.send(0);
  
Wire.endTransmission();

  

Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  
*second     = bcdToDec(Wire.receive() & 0x7f);
  
*minute     = bcdToDec(Wire.receive());
  
*hour       = bcdToDec(Wire.receive() & 0x3f);
  
*dayOfWeek  = bcdToDec(Wire.receive());
  
*dayOfMonth = bcdToDec(Wire.receive());
  
*month      = bcdToDec(Wire.receive());
  
*year  = bcdToDec(Wire.receive());

}



void setup()  { 
    


// init I2C  
  
Serial.begin(9600);
  
Wire.begin();
} 
// these functions only occur once.



/***** Main Loop ***********/

/***************************/

void loop() { 

 
 
  

// get time from RTC and put in hrs and mins variables
  
getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);
  
minCounter = rtcHrs * 60 + rtcMins;
 
Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  
Serial.print(":");
  
Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  
Serial.print(":");
  
Serial.print(RTC.get(DS1307_SEC,false));//read seconds
  
Serial.print("      "); // some space for a more happy life
  
Serial.print(RTC.get(DS1307_MTH,false));//read month
  
Serial.print("/");
  
Serial.print(RTC.get(DS1307_DATE,false));//read date
  
Serial.print("/");
  
Serial.print(RTC.get(DS1307_YR,false)); //read year 
  
Serial.println();


//set LED values
  
setLed(minCounter, oneLed, oneStartMins, onePhotoPeriod, fadeDuration, oneMax);
  
setLed(minCounter, twoLed, twoStartMins, twoPhotoPeriod, fadeDuration, twoMax);
  
setLed(minCounter, threeLed, threeStartMins, threePhotoPeriod, fadeDuration, threeMax);
  
setLed(minCounter, fourLed, fourStartMins, fourPhotoPeriod, fadeDuration, fourMax);
 
setLed(minCounter, fiveLed, fiveStartMins, fivePhotoPeriod, fadeDuration, fiveMax);
   
setLed(minCounter, sixLed, sixStartMins, sixPhotoPeriod, fadeDuration, sixMax);
 
// Get ready for next iteration of loop
  
delay(1000);

}
```


----------



## theblondskeleton (Aug 28, 2009)

Ok, so here's a bit of a breakdown of what's going on. 

I cut and pasted the code you posted and verified it. This is what came up:

'RTC' was not declared in this scope

SmartyCat_6_channel_codeB.cpp:65:21: error: DS1307.h: No such file or directory
SmartyCat_6_channel_codeB.cpp: In function 'void loop()':
SmartyCat_6_channel_codeB:337: error: 'RTC' was not declared in this scope
SmartyCat_6_channel_codeB:337: error: 'DS1307_HR' was not declared in this scope
SmartyCat_6_channel_codeB:341: error: 'DS1307_MIN' was not declared in this scope
SmartyCat_6_channel_codeB:345: error: 'DS1307_SEC' was not declared in this scope
SmartyCat_6_channel_codeB:349: error: 'DS1307_MTH' was not declared in this scope
SmartyCat_6_channel_codeB:353: error: 'DS1307_DATE' was not declared in this scope
SmartyCat_6_channel_codeB:357: error: 'DS1307_YR' was not declared in this scope

So, I add this: #include <DS1307RTC.h> and this is what I get:

'class DS1307RTC.h' has no member named 'get'

In file included from SmartyCat_6_channel_codeB.cpp:1:
/Users/seankelly/Documents/Arduino/libraries/DS1307RTC/DS1307RTC.h:9:18: error: Time.h: No such file or directory
SmartyCat_6_channel_codeB.cpp:67:21: error: DS1307.h: No such file or directory
In file included from SmartyCat_6_channel_codeB.cpp:1:
/Users/seankelly/Documents/Arduino/libraries/DS1307RTC/DS1307RTC.h:17: error: 'time_t' does not name a type
/Users/seankelly/Documents/Arduino/libraries/DS1307RTC/DS1307RTC.h:18: error: 'time_t' has not been declared
/Users/seankelly/Documents/Arduino/libraries/DS1307RTC/DS1307RTC.h:19: error: 'tmElements_t' has not been declared
/Users/seankelly/Documents/Arduino/libraries/DS1307RTC/DS1307RTC.h:20: error: 'tmElements_t' has not been declared
/Users/seankelly/Documents/Arduino/libraries/DS1307RTC/DS1307RTC.h:23: error: 'uint8_t' does not name a type
/Users/seankelly/Documents/Arduino/libraries/DS1307RTC/DS1307RTC.h:24: error: 'uint8_t' does not name a type
SmartyCat_6_channel_codeB.cpp: In function 'void loop()':
SmartyCat_6_channel_codeB:339: error: 'class DS1307RTC' has no member named 'get'
SmartyCat_6_channel_codeB:339: error: 'DS1307_HR' was not declared in this scope
SmartyCat_6_channel_codeB:343: error: 'class DS1307RTC' has no member named 'get'
SmartyCat_6_channel_codeB:343: error: 'DS1307_MIN' was not declared in this scope
SmartyCat_6_channel_codeB:347: error: 'class DS1307RTC' has no member named 'get'
SmartyCat_6_channel_codeB:347: error: 'DS1307_SEC' was not declared in this scope
SmartyCat_6_channel_codeB:351: error: 'class DS1307RTC' has no member named 'get'
SmartyCat_6_channel_codeB:351: error: 'DS1307_MTH' was not declared in this scope
SmartyCat_6_channel_codeB:355: error: 'class DS1307RTC' has no member named 'get'
SmartyCat_6_channel_codeB:355: error: 'DS1307_DATE' was not declared in this scope
SmartyCat_6_channel_codeB:359: error: 'class DS1307RTC' has no member named 'get'
SmartyCat_6_channel_codeB:359: error: 'DS1307_YR' was not declared in this scope

So, I add: #include <Time.h> and I end up with:

SmartyCat_6_channel_codeB.cpp:69:21: error: DS1307.h: No such file or directory
SmartyCat_6_channel_codeB:76: error: 'byte second' redeclared as different kind of symbol
/Users/seankelly/Documents/Arduino/libraries/Time/Time.h:93: error: previous declaration of 'int second(time_t)'
SmartyCat_6_channel_codeB:76: error: 'byte month' redeclared as different kind of symbol
/Users/seankelly/Documents/Arduino/libraries/Time/Time.h:99: error: previous declaration of 'int month(time_t)'
SmartyCat_6_channel_codeB:76: error: 'byte year' redeclared as different kind of symbol
/Users/seankelly/Documents/Arduino/libraries/Time/Time.h:101: error: previous declaration of 'int year(time_t)'
SmartyCat_6_channel_codeB.cpp: In function 'void loop()':
SmartyCat_6_channel_codeB:337: error: cannot resolve overloaded function 'second' based on conversion to type 'byte*'
SmartyCat_6_channel_codeB:341: error: 'DS1307_HR' was not declared in this scope
SmartyCat_6_channel_codeB:345: error: 'DS1307_MIN' was not declared in this scope
SmartyCat_6_channel_codeB:349: error: 'DS1307_SEC' was not declared in this scope
SmartyCat_6_channel_codeB:353: error: 'DS1307_MTH' was not declared in this scope
SmartyCat_6_channel_codeB:357: error: 'DS1307_DATE' was not declared in this scope
SmartyCat_6_channel_codeB:361: error: 'DS1307_YR' was not declared in this scope

My head hurts, haha... Does this help at all, or am I just making things more difficult? should I shoot Sink a message?


----------



## O2surplus (Jan 31, 2010)

Ok, I think you have the wrong version of the DS1307 RTC library version installed. Try the ones attached. You should be able to place both of these folders (unzipped of course) into your library folder and the Arduino IDE should be able to pick the correct one.


----------



## theblondskeleton (Aug 28, 2009)

Win  that was it. Verified with no problems. Thanks, O2! Now, to get it all wired up


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> Win  that was it. Verified with no problems. Thanks, O2! Now, to get it all wired up


Cool! I's no 'Puter expert neither, but sometimes even a blind squirrel gets a nut!


----------



## theblondskeleton (Aug 28, 2009)

Well now I have a bit of a wiring issue - I think. The emitters were working fine until I installed my splash guard. After that, some weird stuff was going on. I was unplugging the jumpers from the inputs, and the lead for channel one touched the heat sink - and the emitters for that channel turned on. Sure enough, I checked all of them and all four channels were doing the same thing. I'm not really sure what to think, so I left it. I don't want to hijack this thread any more than I already have so I'll leave it at that until I can get it repaired. It may be next week before I get things up again, as I have no idea where to begin.


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> Well now I have a bit of a wiring issue - I think. The emitters were working fine until I installed my splash guard. After that, some weird stuff was going on. I was unplugging the jumpers from the inputs, and the lead for channel one touched the heat sink - and the emitters for that channel turned on. Sure enough, I checked all of them and all four channels were doing the same thing. I'm not really sure what to think, so I left it. I don't want to hijack this thread any more than I already have so I'll leave it at that until I can get it repaired. It may be next week before I get things up again, as I have no idea where to begin.


Send me a PM describing the "weird stuff" that was going on.


----------



## skanderson (Jul 25, 2010)

ok starting to wire up my build and have a few questions. firstly i have 3 meanwell power supplies that i got cheap a while ago and was wondering if i could use one to power the chip. i have a s-320-24 meanwell. i puts out 24 volts at 12.5 amps. next i see that there are 2 power inputs on the driver. do i need to supply power to one or both. my ftdi to usb adaptor is on the way so im sure i will have questions on programming when i get that going. i will be running 3 lines of 6 cree xmls at around 2 amps ea. i am a little confused about the pwm part of the driver. wont i be able to dim it based on programming the driver and if not what do i need to wire to where to get this thing to auto dim up and down. thanks for all the help, i will post pics of the build on here as well as par numbers once the unit is up and running.


----------



## O2surplus (Jan 31, 2010)

skanderson said:


> ok starting to wire up my build and have a few questions. firstly i have 3 meanwell power supplies that i got cheap a while ago and was wondering if i could use one to power the chip. i have a s-320-24 meanwell. i puts out 24 volts at 12.5 amps. next i see that there are 2 power inputs on the driver. do i need to supply power to one or both. my ftdi to usb adaptor is on the way so im sure i will have questions on programming when i get that going. i will be running 3 lines of 6 cree xmls at around 2 amps ea. i am a little confused about the pwm part of the driver. wont i be able to dim it based on programming the driver and if not what do i need to wire to where to get this thing to auto dim up and down. thanks for all the help, i will post pics of the build on here as well as par numbers once the unit is up and running.


The Power supply you have will work just fine. Here's photo (pardon my Paint skills) of how you should hook it all up. All it really comes down to is "doubling up" on the negative connections from each string of leds to the CAT4101"s and the PWM connections. Your setup only requires a 3 channel control code if the board is wired up like I've shown, since two CAT4101's will be connected to the same PWM signal. You can use the same six channel code that I posted earlier. You'll just have to adjust the variables for the 3 pwm pins that you're using, instead of all 6.


----------



## Mcg177 (Apr 6, 2011)

does any body have a video of this in action? with storm effects? o2 going to be ordering at least one of these in the coming weeks(gotta wait to get paid)


----------



## skanderson (Jul 25, 2010)

thanks for the quick reply. will probably get the wiring done one wednesday, and then i only need to wait on the ftdi to usb to get the coding correct. thanks again, steve


----------



## skanderson (Jul 25, 2010)

one quick question about your drawing. i plan on wiring the red wires to the positive side of the led emitters and the black to the negative side at the end of the string. is this correct? also will the drive work at all without the programming. i would like to see if it will come on even if the dimming doesnt work. i am still waiting on my usb adaptor so i can input the programming.


----------



## O2surplus (Jan 31, 2010)

skanderson said:


> one quick question about your drawing. i plan on wiring the red wires to the positive side of the led emitters and the black to the negative side at the end of the string. is this correct? also will the drive work at all without the programming. i would like to see if it will come on even if the dimming doesnt work. i am still waiting on my usb adaptor so i can input the programming.


Yes, RED = Positive, BLACK = Negative. You can turn on the individual driver chips by connecting their respective PWM connection to the 5V OUTPUT screw terminal.


----------



## skanderson (Jul 25, 2010)

ok all hooked up but no light so i obviously have a short or bad connection somewhere. will try to get it up and lit this weekend. will play with my meter and see where ive gone wrong. hopefully will be able to show pics of it lit up and over the viv soon. thanks again for getting back to me so quickly.


----------



## fab (Oct 28, 2012)

Hello, 

I am françai to sadden for my anglai 

Would be it possible d utilser this card(map) just for 240 led 3w piloted by a signal pwm and the whole fed by an alim atx 480w any controlé by the arduino? 
I just want to feed led 3w 700ma the rest is deja piloted by the arduino 

Thank you in advance for your reponce


----------



## O2surplus (Jan 31, 2010)

Well Guys, I was messing around with my tank today and had to remove the lighting to gain access. When got everything back together and reconnected the power I noticed something weird. Two out of the three SmartyCats would not turn the leds back on. I rechecked all my connections and could find nothing wrong, so I figured the problem had to be internal to the SmartyCats themselves. I connected them to my PC and soon found that the System time had been reset to an earlier time? I did some further checks and found that the DS1307 RTC's weren't keeping time with the power interrupted. After another hour or so of trouble shooting, this is what I found- There's a defect in the PCB at the DS1307 RTC. Pin #7(SQW), which should have been left "floating" according to the schematic and PCB design files, is in reality *grounded* . This defect was not caught at the PCB factory and may be present in some of the SmartyCat's that some of you are using. I found the same defect in 2 more of the units that I haven't even built yet. 
If any of you guys notice the same problem with the clock, here's the fix- Remove Pin#7 from the DS1307 and the problem will be fixed. I used a fine point soldering iron to heat the pin and a small jeweler's screw driver to lift the pin from it's pad. Here's a photo-










If your unit suffers from this defect and you can't tackle the repair yourself, send me a PM and we'll make other arrangements.


----------



## skanderson (Jul 25, 2010)

ok i have gotten all 3 strings to light up using the 5 volt as the dimming input so the wiring on the strings is now correct. this is the first time i have ever used and ardino and i am confused. i have placed the following files into the libraray file on the ardino, ds1307 cpp file, ds1307 o file, ds1307.h, timer1, but i dont know how to get them to compile. i read the part about restarting the ardino IDE but i dont know how to do that. my red blink button is blinking so there is something going on in there. also i dont know where to go into to do the setting of the timers on the dimmers. thanks in advance, hopefully i will get this thing up and running within the week so i can post some pics.


----------



## theblondskeleton (Aug 28, 2009)

This code is confusing to a newbie!! (That's me, too.) I was finally programming my moonlights and it took me three tries to correctly input the start time. Now it's in there and all is well. I reduced my moonlights to 2 emitters and cranked it waaaay down. Still looks good, and hopefully won't kick up the algae. Last time I had 6 emitters at 700mA. You could see everything but it was really bad for algae.

I'm getting some "stepping" on the dimming, and at the end it doesn't just fade out, it clicks off. Normal? It still looks awesome and it is much more tidy and easy to handle than all the other stuff!

PS- Sorry!I haven't forgotten, O2! Holidays and all, you know. Friday!


----------



## O2surplus (Jan 31, 2010)

skanderson said:


> ok i have gotten all 3 strings to light up using the 5 volt as the dimming input so the wiring on the strings is now correct. this is the first time i have ever used and ardino and i am confused. i have placed the following files into the libraray file on the ardino, ds1307 cpp file, ds1307 o file, ds1307.h, timer1, but i dont know how to get them to compile. i read the part about restarting the ardino IDE but i dont know how to do that. my red blink button is blinking so there is something going on in there. also i dont know where to go into to do the setting of the timers on the dimmers. thanks in advance, hopefully i will get this thing up and running within the week so i can post some pics.



The Libraries don't need to be compiled Per Se. Just insert them into the "Libraries" folder first and then restart the Arduino IDE. The actual program"Sketch" that you're using will reference the needed libraries during the compiling process and pull in the needed information.
Since you're just getting started with Arduino programming, Try some of the simpler programs first, like "blink" ( that's the code that I left running on the unit that you have) The red led is tied to digital pin 13 and that pin is currently programmed to "blink". You can always edit the "Blink" code to add more pins like I've done here. Try this code-

```
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain. This copy has been modified to test all 6 PWM output pins.
 */

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  pinMode(3, OUTPUT);     
  pinMode(5, OUTPUT); 
  pinMode(6, OUTPUT); 
  pinMode(9, OUTPUT); 
  pinMode(10, OUTPUT); 
  pinMode(11, OUTPUT); 
}

void loop() {
  digitalWrite(3, HIGH);   // set the LED on
  digitalWrite(5, HIGH);   // set the LED on
  digitalWrite(6, HIGH);   // set the LED on  
  digitalWrite(9, HIGH);   // set the LED on 
  digitalWrite(10, HIGH);   // set the LED on 
  digitalWrite(11, HIGH);   // set the LED on
  
  delay(1000);              // wait for a second
  digitalWrite(3, LOW);    // set the LED off
  digitalWrite(5, LOW);    // set the LED off 
  digitalWrite(6, LOW);    // set the LED off 
  digitalWrite(9, LOW);    // set the LED off
  digitalWrite(10, LOW);    // set the LED off 
  digitalWrite(11, LOW);    // set the LED off
  
  delay(1000);              // wait for a second
}
```
When you've conquered this- try some of the "fading" code.

Like this-


```
/*
 Fade
 
 This example shows how to fade an LED on pin 9
 using the analogWrite() function.
 
 This example code is in the public domain. This copy has been modified to test all 6 PWM output pins.
 
 */
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

void setup()  { 
  // declare pin 9 to be an output:
  pinMode(3, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);

} 

void loop()  { 
  // set the brightness of pin 9:
  analogWrite(3, brightness);    
  analogWrite(5, brightness);
  analogWrite(6, brightness); 
  analogWrite(9, brightness); 
  analogWrite(10, brightness); 
  analogWrite(11, brightness); 
  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade: 
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ; 
  }     
  // wait for 30 milliseconds to see the dimming effect    
  delay(30);                            
}
```
Let me know if you have any trouble with the codes and If needed, I'll custom edit some, with the variables you want, to get your system up and running.
At times it's easier to learn when you already have something working to use as an example.


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> This code is confusing to a newbie!! (That's me, too.) I was finally programming my moonlights and it took me three tries to correctly input the start time. Now it's in there and all is well. I reduced my moonlights to 2 emitters and cranked it waaaay down. Still looks good, and hopefully won't kick up the algae. Last time I had 6 emitters at 700mA. You could see everything but it was really bad for algae.
> 
> I'm getting some "stepping" on the dimming, and at the end it doesn't just fade out, it clicks off. Normal? It still looks awesome and it is much more tidy and easy to handle than all the other stuff!
> 
> PS- Sorry!I haven't forgotten, O2! Holidays and all, you know. Friday!


Well I'm glad to read that you've got it up and running. Unfortunately the "6 channel code" that I provided is very basic and does not provide for High resolution dimming ( Dimming "steps" occur once per* minute*). That's because not all of the PWM pins have the same performance capabilities. Digital pins "9 & 10" can be used for very high resolution dimming, but you'd be left with only 2 channels of control. Those two pins are what "Sinks" code takes advantage of and the dimming "steps" occur once per* second*. If you'd like to try his code, just reconfigure the jumper wires to provide the dimming signal from those two pins and upload his code. ( I wish "Sink" were around here, but he hasn't logged in in a long time)
Let me know if you need any additional help with your code and I'll do what I can to help.


----------



## theblondskeleton (Aug 28, 2009)

Soooooo... Stop me if I'm wrong here... I could wire one string through two cats (as in your diagram for skanderson) to increase the output (for some reason the light seems dim, my glosso is reflecting that fact - need a bit more light) and use sink's code to control it, if I run them through 8 and 9? I certainly don't want to burn anything out, so no touchy for me until I understand this better. However, this would let me boost the WW a bit, too. It's looking a little cool for my taste. Oh, tinkering. I do believe I will never stop


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> Soooooo... Stop me if I'm wrong here... I could wire one string through two cats (as in your diagram for skanderson) to increase the output (for some reason the light seems dim, my glosso is reflecting that fact - need a bit more light) and use sink's code to control it, if I run them through 8 and 9? I certainly don't want to burn anything out, so no touchy for me until I understand this better. However, this would let me boost the WW a bit, too. It's looking a little cool for my taste. Oh, tinkering. I do believe I will never stop


Whoa! Unless your running Cree XM-L's don't attempt to wire up your leds like Skanderson is doing. Your particular leds will not be able to handle the additional current. Have you checked the actual current consumed by your strings? The Cat4101's should be putting out 1000ma if the pots are maxed out. If they're not at 1000ma with the pots maxed then there's another possible reason. The "6 channel code" has the PWM value set at 100, which equates to about 300ma through the leds. Change the 100 to a max of 255 and recheck the current. It should now be at 1000ma and your leds should be a heck of a lot brighter. If you'd like to use "Sinks" code, connect the Cats to digital pins #*9 *& *10*. His code uses PWM values between *0 - 1023*. 1023 being Maximum.

Here's the section of the 6 channel code that needs to be modified-


```
int oneMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.

int twoMax = 255;           // max intensity for this channel. Change if you want to limit max intensity. 

int threeMax = 255;         // max intensity for this channel. Change if you want to limit max intensity.

int fourMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int fiveMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int sixMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.
```
Here's the section of "Sink's" code that has the variables for Max & Min led PWM values.

```
/*
 * Light "state" represents the PWM duty cycle for each channel This normally
 * dictates light intensity. It is an array { duty_chan_1, duty_chan_2 }.
 * Possible values for duty cycle are 0 - 1023.
 */
const int kDayState[] = { 1023,1023 }; // daytime LED state
const int kNightState[] = { 0, 0 }; // nighttime LED state
```
You can always lower the max value of one of the channels to alter the color mix of your lighting. E.g. Run your WW leds at max (1023) and the CW leds at a lower level, say (700). Your lighting will then appear "Warmer".(You can also get the same effect by adjusting the pots on the driver board, if you don't want to mess with the code.Just make sure that the code is set for the maximum PWM value first, so that you can override it with the pot adjustment.)
You can also adjust the KnightState value to a number above 0 to emulate moon lights. Remember 0 = Off, 1 = 1/10 of 1%, and 10= 1% duty cycle.


----------



## theblondskeleton (Aug 28, 2009)

O2surplus said:


> "6 channel code" has the PWM value set at 100, which equates to about 300ma through the leds. Change the 100 to a max of 255 and recheck the current. It should now be at 1000ma and your leds should be a heck of a lot brighter.


And THAT'S why I asked, haha... This should be all I need to do. It's at 100 right now, so that explains why it seems so dim. I was thinking: "this is 1000 mA? No way!" Makes sense now: it WASN'T! Thanks for saving me again!

I may try sink's code, but that may wait until winter break.


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> And THAT'S why I asked, haha... This should be all I need to do. It's at 100 right now, so that explains why it seems so dim. I was thinking: "this is 1000 mA? No way!" Makes sense now: it WASN'T! Thanks for saving me again!
> 
> I may try sink's code, but that may wait until winter break.


LOL It's been a while since I used that code, so naturally I had forgotten to mention that " you may want to turn up this variable a bit". Your comment about the " seemingly dim leds" jogged my memory though, Haha!


----------



## theblondskeleton (Aug 28, 2009)

Ha, no problem  I thought there was something I didn't know going on. I swapped in sink's code, and combined my two WW strings and CW strings so that they can run through the same 2 PWMs. Now I have what I needed: too much light, haha! So, I'm using the analog control to dim the CW as much as possible, and I'll be tinkering with light levels over the next few weeks. I also set up the CW to run as moonlights at night - that's kind of neat: the color is much more agreeable than the royal blues I was using before. I'm just hoping that it doesn't cause too much algae trouble, I'll keep it low and see how it goes.

Now, to see how I can use this bad boy to control my CO2 - I'm SO sick of my mechanical timers getting jammed. Do you know of anyone who has a code/setup for this?


----------



## O2surplus (Jan 31, 2010)

theblondskeleton said:


> Now, to see how I can use this bad boy to control my CO2 - I'm SO sick of my mechanical timers getting jammed. Do you know of anyone who has a code/setup for this?


If all you need to do is activate a solenoid- That's easy. Just use a relay that accepts a 5V control signal. You can then switch the power to your solenoid "on/off" with the addition of a little extra code added to your lighting program. Here's some reading material for you- 
Controllable Power Outlet - SparkFun Electronics


----------



## O2surplus (Jan 31, 2010)

I've decided to "go back to the drawing board" in an effort to create something new. This little project will be aimed at providing a "one stop solution" for DIY Led lighting that electronics/programming novices can tackle with relative ease. Think- "a DIM4 on steroids" LOL.
I've essentially married the "Typhon" Led controller directly to two different types of led drivers. The controller PCB will mount directly on top of the driver PCB and keep all the "guts" of the led lighting system in one small, tidy arrangement. No programming experience will be needed to make this project work, as it will only need to be programmed once and any further tweaks will be made using the buttons and the LCD interface.


First up is the Controller- It's my version of the "Typhon controller" with 4 channels of lighting control. Each channel can be independently programmed for Start time, end time, Max & Min intensity, ect.. I also include two analog inputs for temp sensing/ PAR measurement, whatever is desired.











Next is the first of two styles of led drivers. The first will contain 4 of the band new Meanwell LDD-H drivers. These drivers can be purchased for less than $10 each and are available with different maximum current ratings up to 1000ma each. They can operate in excess of 48 volts, so long strings of 12 -15 leds are possible. Each of the 4 drivers will take it's dimming signals directly from the controller mounted on top.










The next driver is Based on the National Semi-Conductor LN3409. I designed these drivers to utilize components that will allow them to run led loads up to 60 volts/ 3,000 ma. This design will allow the newer Cree XM-L leds to be run at their Max. Each driver's maximum current output can be custom tailored using the on board trim pot. Since each PCB can only hold 2 LM3409's. The driver PCB will be split to create 2 driver sub boards that will mount under the controller. I include selectable jumpers in the design to allow each driver to be addressable by the controller.










That's it for now- the PCB's needed for this project arrive tomorrow. I'll post some pictures of the finished product after it's put together.


----------



## cheesehead (Jun 13, 2007)

Nice.  I'll be following. Hope to work this into a planned full-spectrum build for my 200 gallon! I won't need the controller, but the LM3409 would be great for either XM-L or 100W chinese chip array build.



O2surplus said:


> I've decided to "go back to the drawing board" in an effort to create something new. This little project will be aimed at providing a "one stop solution" for DIY Led lighting that electronics/programming novices can tackle with relative ease. Think- "a DIM4 on steroids" LOL.
> 
> The next driver is Based on the National Semi-Conductor LN3409. I designed these drivers to utilize components that will allow them to run led loads up to 60 volts/ 3,000 ma. This design will allow the newer Cree XM-L leds to be run at their Max. Each driver's maximum current output can be custom tailored using the on board trim pot. Since each PCB can only hold 2 LM3409's. The driver PCB will be split to create 2 driver sub boards that will mount under the controller. I include selectable jumpers in the design to allow each driver to be addressable by the controller.
> 
> That's it for now- the PCB's needed for this project arrive tomorrow. I'll post some pictures of the finished product after it's put together.


----------



## O2surplus (Jan 31, 2010)

cheesehead said:


> Nice.  I'll be following. Hope to work this into a planned full-spectrum build for my 200 gallon! I won't need the controller, but the LM3409 would be great for either XM-L or 100W chinese chip array build.


Thanks Cheesehead!

Let me know if you want any PCB build files for the LM3409. I've been playing around with a few different designs lately and found that they're a lot more flexible with their input voltages/ output voltages, than I'd previously thought. I'd built most of mine to drive 50 watt BridgeLux multi-emitter arrays that have a Vf of 24.4v and need 2,000 ma, but I've found that the same drivers will also drive much higher voltages and lower currents too.


----------



## biogenetic40379 (Jan 19, 2012)

How much does it cost to make something like this to control full spectrum lighting. Looking at making one for my bio cube (reef w/ led retro fit coming soon)


----------



## O2surplus (Jan 31, 2010)

biogenetic40379 said:


> How much does it cost to make something like this to control full spectrum lighting. Looking at making one for my bio cube (reef w/ led retro fit coming soon)


By rough estimate - A controller with 4 MeanWell LDD drivers = $100. The Lm3409 drivers would drive the price up another $30.

I'm in the process of building the first one right now. When I'm done testing it and make any needed changes, I'll post the revised build files along with the Bill of Materials ( with links for purchasing) and the Software.


----------



## skanderson (Jul 25, 2010)

ok been too busy with other projects to mess with the coding and get it working. is there a way that i could download someone elses dimming and timing code to get it up and working. all im looking for is a 1 to2 hour ramp up and down with a 12 hour on/off cycle for all 6 channels. and i will definately be interested in the new build you are putting together. thanks again in advance, steve


----------



## O2surplus (Jan 31, 2010)

skanderson said:


> ok been too busy with other projects to mess with the coding and get it working. is there a way that i could download someone elses dimming and timing code to get it up and working. all im looking for is a 1 to2 hour ramp up and down with a 12 hour on/off cycle for all 6 channels. and i will definately be interested in the new build you are putting together. thanks again in advance, steve




Here's some code that will get you up and running. Just adjust the variables to your liking and let-her-rip.


```
/*
// ATMEG328P-AU Microcontroller LED lighting controller for aquarium use. 
// The programming code uses a DS1307 Real Time clock to set the LED lighting schedule. Current date and time can be accessed with the serial monitor set to 9600 baud.
// sunrise/sunset time,length of fade duration, and the length of the day are selectable via the programmed schedule.  
//  Circuit description
// PWM pins described below connected to dimming circuits on drivers spread among 6 seperate channels.
// DS1307 RTC ( real time clock) connected via I2C protocol.
*/



// Pins to control each channel LEDs. Change these if you're using different pins.

int oneLed = 3;       // LED PWM arduino pin for channel one.

int twoLed = 5;       // LED PWM arduino pin for channel two 

int threeLed = 6;     // LED PWM arduino pin for channel three

int fourLed = 9;      // LED PWM arduino pin for channel four

int fiveLed = 10;     // LED PWM arduino pin for channel five

int sixLed = 11;      // LED PWM arduino pin for channel six


#include <WProgram.h>
#include <DS1307.h> 
// written by  mattt on the Arduino forum and modified by D. Sjunnesson



// Set up RTC

#include "Wire.h"

#define DS1307_I2C_ADDRESS 0x68



// RTC variables

byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year;



// Other variables. These control the behavior of lighting. Change these to customize behavior.

int minCounter = 0;         // counter that resets at midnight. Don't change this.



int oneStartMins = 540;     // minute to start channel 1. Change this to the number of minutes past midnight you want to start

int twoStartMins =420;      // minute to start channel 2. Change this to the number of minutes past midnight you want to start                         

int threeStartMins =540;    // minute to start channel 3. Change this to the number of minutes past midnight you want to start 

int fourStartMins =420;     // minute to start channel 4. Change this to the number of minutes past midnight you want to start 

int fiveStartMins =420;     // minute to start channel 5. Change this to the number of minutes past midnight you want to start 

int sixStartMins =420;      // minute to start channel 6. Change this to the number of minutes past midnight you want to start 


int onePhotoPeriod = 720;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int twoPhotoPeriod = 960;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day                           

int threePhotoPeriod = 720; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fourPhotoPeriod = 960;  // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fivePhotoPeriod = 960;  // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int sixPhotoPeriod = 960;   // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day


int fadeDuration = 180;      // duration of the fade on and off for sunrise and sunset. Change
                            
//    this to alter how long the fade lasts.

int oneMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.

int twoMax = 255;           // max intensity for this channel. Change if you want to limit max intensity. 

int threeMax = 255;         // max intensity for this channel. Change if you want to limit max intensity.

int fourMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int fiveMax = 255;          // max intensity for this channel. Change if you want to limit max intensity.

int sixMax = 255;           // max intensity for this channel. Change if you want to limit max intensity.

/****** LED Functions ******/

/***************************/

//function to set LED brightness according to time of day

//function has three equal phases - ramp up, hold, and ramp down

void setLed(int mins,    // current time in minutes
            
int ledPin,  // pin for this channel of LEDs
            
int start,   // start time for this channel of LEDs
            
int period,  // photoperiod for this channel of LEDs
            
int fade,    // fade duration for this channel of LEDs
            
int ledMax   // max value for this channel
            
)  {
  
if (mins <= start || mins <= mins > start + period)  {
    
analogWrite(ledPin, 0);
  
}// This is when the led's are off, thus ledVal =0
  
if (mins > start && mins <= start + fade)  {
    
analogWrite(ledPin, map(mins - start, 0, fade, 0, ledMax));
  
}// This is sunrise. Leds slowly brighten to full intensity
    
if (mins > start + fade && mins <= start + period - fade)  {
   
analogWrite(ledPin, ledMax);
  
}//This is when the led's are at maximum intensity
    
if (mins > start + period - fade && mins <= start + period)  {
    
analogWrite(ledPin, map(mins - start - period + fade, 0, fade, ledMax, 0));
  
}// This is sunset. LEDs slowly fade out.

}



/***** RTC Functions *******/

/***************************/

// Convert normal decimal numbers to binary coded decimal

byte decToBcd(byte val)

{
  
return ( (val/10*16) + (val%10) );

}



// Convert binary coded decimal to normal decimal numbers

byte bcdToDec(byte val)

{
  
return ( (val/16*10) + (val%16) );

}



// 1) Sets the date and time on the ds1307

// 2) Starts the clock

// 3) Sets hour mode to 24 hour clock

// Assumes you're passing in valid numbers.



/* //remove the forward slash and asterisk at the far left to activate the time date setting code




void setDateDs1307(byte second, // 0-59 
                   
byte minute, // 0-59
                   
byte hour, // 1-23
                   
byte dayOfWeek, // 1-7
              
byte dayOfMonth, // 1-28/29/30/31
                   
byte month, // 1-12
                   
byte year) // 0-99

{
   
Wire.beginTransmission(DS1307_I2C_ADDRESS);
   
Wire.send(0);
   
Wire.send(decToBcd(second));
   
Wire.send(decToBcd(minute));
   
Wire.send(decToBcd(hour));
   Wire.send(decToBcd(dayOfWeek));
   
Wire.send(decToBcd(dayOfMonth));
   
Wire.send(decToBcd(month));
   
Wire.send(decToBcd(year));
   
Wire.endTransmission();
     
                             

}

*/ //remove the forward slash and asterisk at the far left to activate the time date setting code



// Gets the date and time from the ds1307 via the I2C protocol.

void getDateDs1307(byte *second,
          
byte *minute,
          
byte *hour,
          
byte *dayOfWeek,
          
byte *dayOfMonth,
          
byte *month,
          
byte *year)

{
  
Wire.beginTransmission(DS1307_I2C_ADDRESS);
  
Wire.send(0);
  
Wire.endTransmission();

  

Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  
*second     = bcdToDec(Wire.receive() & 0x7f);
  
*minute     = bcdToDec(Wire.receive());
  
*hour       = bcdToDec(Wire.receive() & 0x3f);
  
*dayOfWeek  = bcdToDec(Wire.receive());
  
*dayOfMonth = bcdToDec(Wire.receive());
  
*month      = bcdToDec(Wire.receive());
  
*year  = bcdToDec(Wire.receive());

}



void setup()  { 
    


// init I2C  
  
Serial.begin(9600);
  
Wire.begin();
} 
// these functions only occur once.



/***** Main Loop ***********/

/***************************/

void loop() { 

 
 
  

// get time from RTC and put in hrs and mins variables
  
getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);
  
minCounter = rtcHrs * 60 + rtcMins;
 
Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true
  
Serial.print(":");
  
Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)
  
Serial.print(":");
  
Serial.print(RTC.get(DS1307_SEC,false));//read seconds
  
Serial.print("      "); // some space for a more happy life
  
Serial.print(RTC.get(DS1307_MTH,false));//read month
  
Serial.print("/");
  
Serial.print(RTC.get(DS1307_DATE,false));//read date
  
Serial.print("/");
  
Serial.print(RTC.get(DS1307_YR,false)); //read year 
  
Serial.println();


//set LED values
  
setLed(minCounter, oneLed, oneStartMins, onePhotoPeriod, fadeDuration, oneMax);
  
setLed(minCounter, twoLed, twoStartMins, twoPhotoPeriod, fadeDuration, twoMax);
  
setLed(minCounter, threeLed, threeStartMins, threePhotoPeriod, fadeDuration, threeMax);
  
setLed(minCounter, fourLed, fourStartMins, fourPhotoPeriod, fadeDuration, fourMax);
 
setLed(minCounter, fiveLed, fiveStartMins, fivePhotoPeriod, fadeDuration, fiveMax);
   
setLed(minCounter, sixLed, sixStartMins, sixPhotoPeriod, fadeDuration, sixMax);
 
// Get ready for next iteration of loop
  
delay(1000);

}
```


----------



## skanderson (Jul 25, 2010)

ok now to sound really dumb, how do i get this into the ardino. do i type it in or can i import it?


----------



## jarvitron (Aug 6, 2012)

skanderson said:


> ok now to sound really dumb, how do i get this into the ardino. do i type it in or can i import it?


There's no such thing as a dumb question, but that's a dumb question for an aquarium forum.


----------



## O2surplus (Jan 31, 2010)

skanderson said:


> ok now to sound really dumb, how do i get this into the ardino. do i type it in or can i import it?



Copy&Paste my friend!

Highlight _all _code that I posted, Right Click "COPY" and then Paste it into the Arduino IDE. 
Click the button that says VERIFY to make sure that it compiles properly, and then either "Save" the Sketch _or _"Upload" it to the Arduino.


----------



## mistergreen (Dec 9, 2006)

skanderson said:


> ok now to sound really dumb, how do i get this into the ardino. do i type it in or can i import it?


Copy and paste but make sure to download and place libraries in the right place. When you try to compile, the arduino app will yell at you.


----------



## mistergreen (Dec 9, 2006)

I just noticed something in the code, for those that had a hard time with the code.

This is a release note from the arduino app last year.



> * The WProgram.h file, which provides declarations for the Arduino API,
> has been renamed to Arduino.h. To create a library that will work in
> both Arduino 0022 and Arduino 1.0, you can use an #ifdef that checks
> for the ARDUINO constant, which was 22 and is now 100. For example:
> ...


----------



## skanderson (Jul 25, 2010)

ok i pasted it into my ardino oo23. when i try to verify or upload i get the following message/*
// ATMEG328P-AU Microcontroller LED lighting controller for aquarium use. 
// The programming code uses a DS1307 Real Time clock to set the LED lighting schedule. Current date and time can be accessed with the serial monitor set to 9600 baud.
// sunrise/sunset time,length of fade duration, and the length of the day are selectable via the programmed schedule. 
// Circuit description
// PWM pins described below connected to dimming circuits on drivers spread among 6 seperate channels.
// DS1307 RTC ( real time clock) connected via I2C protocol.
*/



// Pins to control each channel LEDs. Change these if you're using different pins.

int oneLed = 3; // LED PWM arduino pin for channel one.

int twoLed = 5; // LED PWM arduino pin for channel two 

int threeLed = 6; // LED PWM arduino pin for channel three

int fourLed = 9; // LED PWM arduino pin for channel four

int fiveLed = 10; // LED PWM arduino pin for channel five

int sixLed = 11; // LED PWM arduino pin for channel six


#include <WProgram.h>
#include <DS1307.h> 
// written by mattt on the Arduino forum and modified by D. Sjunnesson



// Set up RTC

#include "Wire.h"

#define DS1307_I2C_ADDRESS 0x68



// RTC variables

byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year;



// Other variables. These control the behavior of lighting. Change these to customize behavior.

int minCounter = 0; // counter that resets at midnight. Don't change this.



int oneStartMins = 540; // minute to start channel 1. Change this to the number of minutes past midnight you want to start

int twoStartMins =420; // minute to start channel 2. Change this to the number of minutes past midnight you want to start 

int threeStartMins =540; // minute to start channel 3. Change this to the number of minutes past midnight you want to start 

int fourStartMins =420; // minute to start channel 4. Change this to the number of minutes past midnight you want to start 

int fiveStartMins =420; // minute to start channel 5. Change this to the number of minutes past midnight you want to start 

int sixStartMins =420; // minute to start channel 6. Change this to the number of minutes past midnight you want to start 


int onePhotoPeriod = 720; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int twoPhotoPeriod = 960; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day 

int threePhotoPeriod = 720; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fourPhotoPeriod = 960; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int fivePhotoPeriod = 960; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day

int sixPhotoPeriod = 960; // photoperiod in minutes, for this channel. Change this to alter the total legnth of the day


int fadeDuration = 180; // duration of the fade on and off for sunrise and sunset. Change

// this to alter how long the fade lasts.

int oneMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int twoMax = 255; // max intensity for this channel. Change if you want to limit max intensity. 

int threeMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int fourMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int fiveMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

int sixMax = 255; // max intensity for this channel. Change if you want to limit max intensity.

/****** LED Functions ******/

/***************************/

//function to set LED brightness according to time of day

//function has three equal phases - ramp up, hold, and ramp down

void setLed(int mins, // current time in minutes

int ledPin, // pin for this channel of LEDs

int start, // start time for this channel of LEDs

int period, // photoperiod for this channel of LEDs

int fade, // fade duration for this channel of LEDs

int ledMax // max value for this channel

) {

if (mins <= start || mins <= mins > start + period) {

analogWrite(ledPin, 0);

}// This is when the led's are off, thus ledVal =0

if (mins > start && mins <= start + fade) {

analogWrite(ledPin, map(mins - start, 0, fade, 0, ledMax));

}// This is sunrise. Leds slowly brighten to full intensity

if (mins > start + fade && mins <= start + period - fade) {

analogWrite(ledPin, ledMax);

}//This is when the led's are at maximum intensity

if (mins > start + period - fade && mins <= start + period) {

analogWrite(ledPin, map(mins - start - period + fade, 0, fade, ledMax, 0));

}// This is sunset. LEDs slowly fade out.

}



/***** RTC Functions *******/

/***************************/

// Convert normal decimal numbers to binary coded decimal

byte decToBcd(byte val)

{

return ( (val/10*16) + (val%10) );

}



// Convert binary coded decimal to normal decimal numbers

byte bcdToDec(byte val)

{

return ( (val/16*10) + (val%16) );

}



// 1) Sets the date and time on the ds1307

// 2) Starts the clock

// 3) Sets hour mode to 24 hour clock

// Assumes you're passing in valid numbers.



/* //remove the forward slash and asterisk at the far left to activate the time date setting code




void setDateDs1307(byte second, // 0-59 

byte minute, // 0-59

byte hour, // 1-23

byte dayOfWeek, // 1-7

byte dayOfMonth, // 1-28/29/30/31

byte month, // 1-12

byte year) // 0-99

{

Wire.beginTransmission(DS1307_I2C_ADDRESS);

Wire.send(0);

Wire.send(decToBcd(second));

Wire.send(decToBcd(minute));

Wire.send(decToBcd(hour));
Wire.send(decToBcd(dayOfWeek));

Wire.send(decToBcd(dayOfMonth));

Wire.send(decToBcd(month));

Wire.send(decToBcd(year));

Wire.endTransmission();



}

*/ //remove the forward slash and asterisk at the far left to activate the time date setting code



// Gets the date and time from the ds1307 via the I2C protocol.

void getDateDs1307(byte *second,

byte *minute,

byte *hour,

byte *dayOfWeek,

byte *dayOfMonth,

byte *month,

byte *year)

{

Wire.beginTransmission(DS1307_I2C_ADDRESS);

Wire.send(0);

Wire.endTransmission();



Wire.requestFrom(DS1307_I2C_ADDRESS, 7);


*second = bcdToDec(Wire.receive() & 0x7f);

*minute = bcdToDec(Wire.receive());

*hour = bcdToDec(Wire.receive() & 0x3f);

*dayOfWeek = bcdToDec(Wire.receive());

*dayOfMonth = bcdToDec(Wire.receive());

*month = bcdToDec(Wire.receive());

*year = bcdToDec(Wire.receive());

}



void setup() { 



// init I2C 

Serial.begin(9600);

Wire.begin();
} 
// these functions only occur once.



/***** Main Loop ***********/

/***************************/

void loop() { 





// get time from RTC and put in hrs and mins variables

getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);

minCounter = rtcHrs * 60 + rtcMins;

Serial.print(RTC.get(DS1307_HR,true)); //read the hour and also update all the values by pushing in true

Serial.print(":");

Serial.print(RTC.get(DS1307_MIN,false));//read minutes without update (false)

Serial.print(":");

Serial.print(RTC.get(DS1307_SEC,false));//read seconds

Serial.print(" "); // some space for a more happy life

Serial.print(RTC.get(DS1307_MTH,false));//read month

Serial.print("/");

Serial.print(RTC.get(DS1307_DATE,false));//read date

Serial.print("/");

Serial.print(RTC.get(DS1307_YR,false)); //read year 

Serial.println();


//set LED values

setLed(minCounter, oneLed, oneStartMins, onePhotoPeriod, fadeDuration, oneMax);

setLed(minCounter, twoLed, twoStartMins, twoPhotoPeriod, fadeDuration, twoMax);

setLed(minCounter, threeLed, threeStartMins, threePhotoPeriod, fadeDuration, threeMax);

setLed(minCounter, fourLed, fourStartMins, fourPhotoPeriod, fadeDuration, fourMax);

setLed(minCounter, fiveLed, fiveStartMins, fivePhotoPeriod, fadeDuration, fiveMax);

setLed(minCounter, sixLed, sixStartMins, sixPhotoPeriod, fadeDuration, sixMax);

// Get ready for next iteration of loop

delay(1000);

all that is in red under a message that says RTC was not declared in this scope . what am i doing wrong? thanks again for the help.


----------



## O2surplus (Jan 31, 2010)

skanderson said:


> ok i pasted it into my ardino oo23. when i try to verify or upload i get the following message/*
> 
> ```
> // ATMEG328P-AU Microcontroller LED lighting controller for aquarium use.
> ...


You probably don't have the needed "DS1307" Library installed in your arduino's library folder. Here's the library- just place the unzipped folder into your "library" folder and try again.


----------



## skanderson (Jul 25, 2010)

according to my library i have ds1037RTC as a CPP file in my ardino library. is that the wrong one? if it is the proper one why isnt it working?


----------



## O2surplus (Jan 31, 2010)

skanderson said:


> according to my library i have ds1037RTC as a CPP file in my ardino library. is that the wrong one? if it is the proper one why isnt it working?


Just toss in the one that I posted and see what happens.:biggrin:


----------



## skanderson (Jul 25, 2010)

put the new file you put up in there and still get the same error messages. clearly im screwing something up but i have no idea what.


----------



## O2surplus (Jan 31, 2010)

skanderson said:


> put the new file you put up in there and still get the same error messages. clearly im screwing something up but i have no idea what.


I sent you a PM. Have you tried uploading some simpler code, like the "blink" sketch? I'm just trying a little remote trouble shooting here.


----------

