# Arduino Controlled LED How-To Thread



## FDNY911 (Dec 6, 2009)

Awesome bro. Thanks. I might send him a pm on that forum for some help. I plan on using the 48p with the pwm but I wasn't sure if later on I could add an arduino to it or not.


----------



## mistergreen (Dec 9, 2006)

if you guys need coding help, just ask. I can write some pretty fast.


----------



## FDNY911 (Dec 6, 2009)

Awesome MisterGreen. I'm going to keep you in mind. I was planning on doing a sunrise/sunset once I figure out how I can add the Arduino after I finish my LED fixture. Thanks!


----------



## jcgd (Feb 18, 2004)

Using that guys part list and the info from the arduino forum plus code from mistergreen, the controller should be relatively simple to build.


----------



## mistergreen (Dec 9, 2006)

I built a color LED a while back but the PAR output wasn't enough.

sunrise









daylight


----------



## FDNY911 (Dec 6, 2009)

Wow that's pretty cool. So you have experience actually building the Arduino not just coding them?


----------



## jcgd (Feb 18, 2004)

Another neat link with some par reading and reef application. This guy made pendants for his reef that are really neat. No dimming though, he didn't see the need.

http://www.reefaddicts.com/content.php/70-LED-pendent-build


----------



## IWANNAGOFAST (Jan 14, 2008)

Man, I need to learn how to do this, this would be super awesome to have. All my LEDs are on constant current drivers but this would be sweet to implement.

So I read that first link, would you just hook up the drivers to the arduino board, load up some code and you're good to go?


----------



## jcgd (Feb 18, 2004)

IWANNAGOFAST said:


> Man, I need to learn how to do this, this would be super awesome to have. All my LEDs are on constant current drivers but this would be sweet to implement.
> 
> So I read that first link, would you just hook up the drivers to the arduino board, load up some code and you're good to go?


Me thinks that is correct. I'm not 100% sure on it yet. I find everybody is mentioning they are using the arduino boards but nobody is really saying how to do it. Hopefully this thread can blow it wide open.

The confusing part is that you can pretty much do whatever you want with the board. My understanding is that it pretty much allows you to create a custom PLC. Give it real world input, covert that signal to 0-5v and it can use that info to put out another 0-5v signal to do whatever you want. I think.

We don't need to do much so you can have it turn lights on/off a certain times, fade in/out, control fans to control the heat on you fixture, etc. Programming random storms should be relatively simple if you know how to code, but things like cloud cover would require individually controlled LEDs unless you want to simply dim one driver or a few drivers at a time. It would be more challenging to have a could 'float' over the tank a few LEDs at a time. 

I am not completely sure, but the limits of the arduino seem to be our imaginations, and $$$ of course.

I'm thinking that soon someone is going to figure out how to get the arduino ready so they can make a bunch up and sell them like people are selling regulator setups. It seems a board, the necessary resistors, transistors, clock, etc. for a dimmable sunrise/sunset fixture would run about $50 plus a hobby box if you want it nice and neat. Add in $30 bucks labour and you have a quick and dirty controller someone could sell in the SNS. If you are making a few at a time it should be easy to throw together. 

The fixture itself isn't the difficult part to figure out. Choosing LEDs can be tough, but once decided, throw them on a heat sink wired in series and wire your driver... good to go. Of course you can get into parallel runs and all that, but I'm not read up on how that works. Apparently you can somehow control each LED on it's own. I can't figure how that is done unless they are using a channel for every LED.

The really hard part is figuring out the part list and schematic for the controller itself. My first link at the top seems to have that covered. Those who know how to code can write up programs and give (or sell) the code to us who have no clue like anything else. Want moon cycles? Program for that. Thunder showers? Program for that.

It would seem most of use are using dimmable drivers with manual control because the reefkeeper and ALC is a touch too expensive. But if we already have the drivers running our LED strings, you can upgrade whenever you have an extra $100. As new upgrades become understood and commonplace you can upgrade without needing a new fixture.

Sunrise/sunset isn't needed by all, but if it's cheap and easy, who wouldn't _want_ it.


----------



## jcgd (Feb 18, 2004)

Parts

http://ca.mouser.com/


----------



## mistergreen (Dec 9, 2006)

FDNY911 said:


> Wow that's pretty cool. So you have experience actually building the Arduino not just coding them?


of course 
You have to learn the hardware too when playing with arduino. There are a few engineers floating around that could help way better than I can.

I don't see a timer interface for the ardiuno in the link provided by the op... You can set a clock for and set when the lights to turn on and off or fade in and out. You can do this with physical buttons & LED displays or hook up your laptop and control the times.

Or you can code it all but that makes it not flexible.


----------



## jcgd (Feb 18, 2004)

mistergreen said:


> of course
> You have to learn the hardware too when playing with arduino. There are a few engineers floating around that could help way better than I can.
> 
> I don't see a timer interface for the ardiuno in the link provided by the op... You can set a clock for and set when the lights to turn on and off or fade in and out. You can do this with physical buttons & LED displays or hook up your laptop and control the times.
> ...


He said somewhere he coded it while the clock wasn't being used but it lost a few minutes a day. In post #27 he list these parts for his clock:
DS1307+-ND Real Time Clock (ds1307 in schematic) .. 1
X1124-ND Crystal for RTC ... 1

Is that what you mean by a timer interface? I'm just not sure of the terminology for all this stuff yet.


----------



## O2surplus (Jan 31, 2010)

Hey everyone,

I've had an arduino Duemilanove micro controller running the led lighting on my tank for about a year now. For the time being,it is programmed to do sunrise/sunset dimming at a preset time each day. I'm still learning how to write code or "sketches" as their called in the Arduino IDE, but I have a small collection of working code that I can share with anybody that is interested. The Arduino Duemilanove/Uno outputs a 5 volt Pulse Width Modified signal that can be used to control led drivers/ motors ect... I built my own led drivers that can utilize the 5v PWM signal directly so connections are simplified for my use. Anyone running Meanwell dimmable drivers will need to add a simple switching transistor circuit between their drivers and the Arduino to raise it's output from 5vdc to the 10vdc needed by the meanwells. These controllers can be built for around $50.
I'm even building my own Arduino based controller from scratch that includes a LCD screen and menu driven controls.
Here's a photo of the PCB (from EAGLE PCB Designer) that I designed myself.


----------



## jcgd (Feb 18, 2004)

O2surplus said:


> Hey everyone,
> 
> I've had an arduino Duemilanove micro controller running the led lighting on my tank for about a year now. For the time being,it is programmed to do sunrise/sunset dimming at a preset time each day. I'm still learning how to write code or "sketches" as their called in the Arduino IDE, but I have a small collection of working code that I can share with anybody that is interested. The Arduino Duemilanove/Uno outputs a 5 volt Pulse Width Modified signal that can be used to control led drivers/ motors ect... I built my own led drivers that can utilize the 5v PWM signal directly so connections are simplified for my use. Anyone running Meanwell dimmable drivers will need to add a simple switching transistor circuit between their drivers and the Arduino to raise it's output from 5vdc to the 10vdc needed by the meanwells. These controllers can be built for around $50.
> I'm even building my own Arduino based controller from scratch that includes a LCD screen and menu driven controls.
> Here's a photo of the PCB (from EAGLE PCB Designer) that I designed myself.


Do you have any info on how do build your own drivers? Is it much cheaper than buying meanwells?

If anyone knows how to build a system step by step I would be very grateful. 

Also, how would someone learn how to write the code for the controller?


----------



## FDNY911 (Dec 6, 2009)

Thanks O2surplus,

I'm not ready for the Arduino just yet, so I am going to be using the PWM from RapidLED, when I am ready to use an Arduino, basically I'll just scrap the RapidLED PWM and replace it with an Arduino? Originally I thought the Arduino was just software that created different lighting options. I didn't know it was an advanced PWM. Am I correct in saying that?

Hector


----------



## IWANNAGOFAST (Jan 14, 2008)

So this arduino controller is just a cheaper way to do the sunrise/sunset thing than the PWM controller from rapidled?

I'm basically just looking for sunrise/sunset. Should I just go w/ the PWM for this than?


----------



## O2surplus (Jan 31, 2010)

justincgdick said:


> Do you have any info on how do build your own drivers? Is it much cheaper than buying meanwells?
> 
> If anyone knows how to build a system step by step I would be very grateful.
> 
> Also, how would someone learn how to write the code for the controller?


I built my own drivers mainly for fun and to add some additional features that are not available with commercial designs.My first led system used 90 Cree XRE's that would need to be driven by at least 8 Meanwell dimmable drivers that cost $42 each- just a year ago. Their price has come down since then, but I feel that I'm still money ahead. I use the OnSemi Cat4101 constant current driver IC in my design. It's small, cheap, and only requires a few additional parts to make it work. To build the drivers- I used to make my own printed circuit boards at home, but now I design them on my laptop and have my little friends in China produce them for me. I receive the bare boards from them and do the actual assembly soldering myself.You'll have to "run the numbers" to determine whether or not it is actually cheaper to produce your own drivers for your own build. One thing is sure though- you'll get exactly what you want when you DIY.
Here's a photo of one of my 4 channel drivers capable of driving 24 leds up to 1000Ma. It has a 12 volt regulator ( for cooling fans, Arduino power, ect..) and is PWM dimmable. I have another design that includes Analog dimming in addition to the PWM dimming coming from my board house right now. 







You can get the EAGLE PCB design software for free here- http://cadsoftusa.com/

and there is a nice Arduino tutorial here-Arduino Tutorial - Learn electronics and microcontrollers using Arduino! 

Here's a copy of the coding or "sketch" that will do a Sunrise/Sunset dimming program. Take a close look- it contains notes that will tell you whats going on inside the code.

```
//Custom LED Aquarium lighting control code.
#include <WProgram.h>
#include <DS1307.h>
// Set up RTC
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68

// RTC variables
byte second, rtcMins, oldMins, rtcHrs, oldHrs, dayOfWeek, dayOfMonth, month, year, psecond; 

byte bluePins[]      = {10,};      // pwm pins for blues// connect pwm control wire at pin10 for center array
byte whitePins[]     = {9,11,};    // pwm pins for whites// connect pwm control wires at pin9 and pin 11 for left and right arrays.

byte blueChannels    =       1;    // how many PWMs for blues (count from above)change this number for additional pins
byte whiteChannels   =        2;    // how many PWMs for whites (count from above)change this number for additional pins

int channelDelay     =        0;    // this sets the delay in minutes between strings
                                    // of the same color for simulating directional light.
                                    // 0 means all will ramp up at the same time. 


int blueStartMins    =        540;  // minute to start blues. Change this to the number of minutes past
                                    //    midnight you want the blues to start.
int whiteStartMins   =        555;  // minute to start whites. Same as above.


int bluePhotoPeriod  =        720;  // photoperiod in minutes, blues. Change this to alter the total
                                    // photoperiod for blues.
int whitePhotoPeriod =        695;  // photoperiod in minutes, whites. Same as above.


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

byte blueMax         =        255;  // max intensity for blues. Change if you want to limit max intensity.
byte whiteMax        =        255;  // max intensity for whites. Same as above.

// 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.

/****** LED Functions ******/
/***************************/
//function to set LED brightness according to time of day
//function has three equal phases - ramp up, hold, and ramp down
byte setLed(int mins,    // current time in minutes
            byte 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
            byte ledMax   // max value for this channel
            )  {
  byte ledVal = 0;
  if (mins <= start || mins > start + period)  {
   //this is when the LEDs are off, thus ledVal is 0;
    ledVal = 0;
  }
  if (mins > start && mins <= start + fade)  {
    //this is sunrise
    ledVal =  map(mins - start, 0, fade, 0, ledMax);
  }
    if (mins > start + fade && mins <= start + period - fade)  {
     //this is when the lights are on max (between sunrise and sunset)
      ledVal = ledMax;
  }
    if (mins > start + period - fade && mins <= start + period)  {
    //this is the sunset.
    ledVal = map(mins - start - period + fade, 0, fade, ledMax, 0);
  }
   analogWrite(ledPin, ledVal);

   return ledVal;  

} 
/***** 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.
//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();
//}

// Gets the date and time from the ds1307
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();
} 

/***** Main Loop ***********/
/***************************/
void loop(){
    getDateDs1307(&second, &rtcMins, &rtcHrs, &dayOfWeek, &dayOfMonth, &month, &year);
 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();


  if (psecond != second){
    psecond = second;
    // set LED states
    minCounter = rtcHrs * 60 + rtcMins;
    Serial.println(minCounter);
    update_leds();
  }
  delay(50);
 }


void update_leds( void ){
  int i;
  byte ledVal;
  for (i = 0; i < blueChannels; i++){
      ledVal = setLed(minCounter, bluePins[i], blueStartMins + channelDelay*i, bluePhotoPeriod, fadeDuration, blueMax);
  }
  for (i = 0; i < whiteChannels; i++){
      ledVal = setLed(minCounter, whitePins[i], whiteStartMins + channelDelay*i, whitePhotoPeriod, fadeDuration, whiteMax);
  }
}
```
I'm still a coding noob, but I'll do what I can to help.


----------



## O2surplus (Jan 31, 2010)

IWANNAGOFAST said:


> So this arduino controller is just a cheaper way to do the sunrise/sunset thing than the PWM controller from rapidled?
> 
> I'm basically just looking for sunrise/sunset. Should I just go w/ the PWM for this than?


The Arduino and a real time clock can be purchased for less than $40. It is a micro-controller capable of far more than just dimming some lights. Do a "YOUTUBE" search and you'll be blown away- by what it can be configured to do! It does take some study time and some electronic "know-how" to use but,If all you need is something to control your Meanwell drivers, then $59 for the RapidLed controller will work just fine.


----------



## IWANNAGOFAST (Jan 14, 2008)

hmm interesting. I will have to take a look at these videos when I get off work (work web filters)


----------



## jcgd (Feb 18, 2004)

Another link with lots of information and discussion: 

http://www.reefcentral.com/forums/showthread.php?t=1847680


----------



## IWANNAGOFAST (Jan 14, 2008)

http://www.reefledcontroller.com/

found this link, lots of info


----------



## jcgd (Feb 18, 2004)

IWANNAGOFAST said:


> http://www.reefledcontroller.com/
> 
> found this link, lots of info


The thread where lots of that info came from:
http://reefcentral.com/forums/showthread.php?t=1987110


----------



## Rockhoe14er (Jan 19, 2011)

wow I would love to do this but i think as for right now it seems a bit over my head.


----------



## IWANNAGOFAST (Jan 14, 2008)

yeah, I have no idea how to implement this. I'm waiting on you justincgdick to do this and I'll just copy you haha


----------



## FDNY911 (Dec 6, 2009)

+1000! totally going to copy. I'm ready to order all the parts for the fixture but I am not sure I totally understand the actual building process yet.


----------



## jcgd (Feb 18, 2004)

I contacted a guy on reef central and he told me to call him today I'm planning on calling after work. He for sure can help me build one, but I think will well also build a controller to order. I'm going to see what he can do. 

I know everything looks complicated but everyone is saying once you start working on it the anxiety fades. The electronics are very basic. If you can build lego, you can build these circuits. Or get the kids to do it for you!

You can make it as basic or complicated as you want. The reef guys do everthing with them.


----------



## audioaficionado (Apr 19, 2011)

Try not to look at the entire project at once and freak out. You know the old sayings... 'How do you eat an elephant? One bite at a time.' & 'The journey of a thousand miles begins with one step.'


----------



## mistergreen (Dec 9, 2006)

audioaficionado said:


> Try not to look at the entire project at once and freak out. You know the old sayings... 'How do you eat an elephant? One bite at a time.' & 'The journey of a thousand miles begins with one step.'


this is good advice.

DO one small thing at a time
Get beginning kits and you'll see how it all fits together

http://www.radioshack.com/product/index.jsp?productId=2103801
http://www.radioshack.com/product/index.jsp?productId=2734154


You first prototype your application AND then you can start soldering and such.
Here was my prototype.
prototype


----------



## jcgd (Feb 18, 2004)

mistergreen said:


> this is good advice.
> 
> DO one small thing at a time
> Get beginning kits and you'll see how it all fits together
> ...


Good point, and nice effect with the controller in you prototype. I'm going to work slow on the controller and work fast on the fixture. I have a design figured out and I picked up the aluminum to have some fun building it. I'm confident there.


----------



## audioaficionado (Apr 19, 2011)

I plan on manually controlled dimming at first, then I'll get into the wonderful world of Arduino computers. I've been building & tweaking PCs for years. It will be fun to build one that I also get to program too.


----------



## Arctangent (Feb 22, 2010)

So I haven't read the entire thread, but has anyone shown how to dim with Arduino PWM and NPN transistors? It's very simple and it's what I am doing with the ArcLED project.

BTW I would really advise against trying to build your own Arduino, you're likely to make errors that are not present in the 20 some odd dollar retail version.


----------



## jcgd (Feb 18, 2004)

I think you use the arduino to fire the gate on the transistor which is also connected to a wall wart supply. As the gate is fired it lets the 9-10v from the wall wart through to control the driver. 

You can parallel off the wall wart to control multiple transistors for multiple drivers. 

I think this is correct but I'm still learning. I also recommend buying a per build board that also has usb connection so you don't have to buy it separately.


----------



## Arctangent (Feb 22, 2010)

No reason to have the power supply on the transistor...unless you're using a wal-wart and current limiting resistors for the LEDs instead of a driver. Just place the transistor after LEDs on the ground side and send PWM to the base lead. It'll work like a solid state switch; opening and closing the circuit to ground. The hardest part is picking the correct transistor and the resistor between the arduino and the transistor. I'll do a write up if there is any interest??


----------



## O2surplus (Jan 31, 2010)

Arctangent said:


> No reason to have the power supply on the transistor...unless you're using a wal-wart and current limiting resistors for the LEDs instead of a driver. Just place the transistor after LEDs on the ground side and send PWM to the base lead. It'll work like a solid state switch; opening and closing the circuit to ground. The hardest part is picking the correct transistor and the resistor between the arduino and the transistor. I'll do a write up if there is any interest??



You really need to read the whole thread. The point being that other members wanted to know how to control dim-able led drivers with an arduino instead of an "off the shelf" controller. The question about needing an additional transistor arose because the arduino outputs a 5 volt PWM signal instead of the 10 pwm signal needed by the ever popular MeanWell ELN series led drivers. The transistor is used to raise the pwm signal from 5 volts to the required 10.


----------



## jcgd (Feb 18, 2004)

Arctangent said:


> No reason to have the power supply on the transistor...unless you're using a wal-wart and current limiting resistors for the LEDs instead of a driver. Just place the transistor after LEDs on the ground side and send PWM to the base lead. It'll work like a solid state switch; opening and closing the circuit to ground. The hardest part is picking the correct transistor and the resistor between the arduino and the transistor. I'll do a write up if there is any interest??


Nope, we are using Meanwell dimmable drivers. So the transistor in in series with the string of LEDs? I don't think I get it. The idea is to convert the 5v PWM from the arduino to 10V for the drivers right? And the driver itself adjust the current going out to the leds?

Are you saying we can forgo the dimmable driver, use a constant current and control the LED voltage directly? If you are varying the voltage to the LEDs themselves wouldn't you have a minimum amount of dimming before you are not able to fire the LEDs due to the forward voltage potential required?



O2surplus said:


> You really need to read the whole thread. The point being that other members wanted to know how to control dim-able led drivers with an arduino instead of an "off the shelf" controller. The question about needing an additional transistor arose because the arduino outputs a 5 volt PWM signal instead of the 10 pwm signal needed by the ever popular MeanWell ELN series led drivers. The transistor is used to raise the pwm signal from 5 volts to the required 10.


Now now, lets hear him out. Maybe he can save us some $$$.roud:


----------



## Arctangent (Feb 22, 2010)

justincgdick said:


> Nope, we are using Meanwell dimmable drivers. So the transistor in in series with the string of LEDs? I don't think I get it. The idea is to convert the 5v PWM from the arduino to 10V for the drivers right? And the driver itself adjust the current going out to the leds?
> 
> Are you saying we can forgo the dimmable driver, use a constant current and control the LED voltage directly? If you are varying the voltage to the LEDs themselves wouldn't you have a minimum amount of dimming before you are not able to fire the LEDs due to the forward voltage potential required?
> 
> ...


You got the Idea! Except you are not varying the voltage, but the duty cycle. I didn't know you were using the dimmable drivers, never messed with them myself because they _are_ expensive. Actually I _just_ started looking at them today (for my Dad's guitar shop).


What I'm trying to convey is that you can use non-dimmable constant current drivers, an Arduino (or a 555 timer if all you want is manual control), and a transistor to dim the LEDs. And yes, the transistor would be in series with the string of LEDs, it would go: Driver>LEDs>Transistor>Ground(driver); with a PWM signal on the third transistor leg. I'll do a detailed write up on the subject with good instructions and explinations, but it'll be Monday at the earliest because I'm moving back to college for summer school. If you did DIY drivers (LM-317) and a 555 timer you could have a VERY cheap dimmable driver, and with DX selling XR-Es @ ~$2.6, DIY LEDs in general are getting cheap.


----------



## Arctangent (Feb 22, 2010)

O2surplus said:


> You really need to read the whole thread. The point being that other members wanted to know how to control dim-able led drivers with an arduino instead of an "off the shelf" controller. The question about needing an additional transistor arose because the arduino outputs a 5 volt PWM signal instead of the 10 pwm signal needed by the ever popular MeanWell ELN series led drivers. The transistor is used to raise the pwm signal from 5 volts to the required 10.


 That seems bulky. Isn't there a POT version...nevermind, I'll just read the thread when I get a chance.


----------



## boink (Nov 27, 2006)

PWM Version are P type drivers and Analog are D types.


----------



## audioaficionado (Apr 19, 2011)

Don't arduinos have analog output modules too?


----------



## jcgd (Feb 18, 2004)

Yeah, they have both the PWM and the analog drivers. They both work with the arduino's PWM signal (once changed to 10V) BUT the analog driver technically shouldn't work and may not be good for it. I haven't found it why it works, it just does. It can't be good for the driver but nobody has done it long enough to find out if anything will go wrong. Who knows, it could be very dangerous. 

My previous understanding was that the most simple way to have computer controlled LEDs was to use the arduino board and modify the PWM from 5v to 10v with a transistor (transistor powered off a wallwart) for each output. You would have an output for each meanwell you wanted to control separately. Look at this diagram:









2 on the diagram goes to ground
VCC is your wall wart positive
The left side of the resistor goes to the arduino output

It seems complicated but all that is happening is you are hooking the max voltage up to the dimming control on the driver. The transistor is a switch that has a gate (the wire going to the resistor) that flicks the switch electronically. When the arduino puts out a pulse of voltage, the resister limits the current to the gate (it's sensitive but requires a minimum current to work) and it fires the transistor. The arduino changes the length of these pulses in order to control the circuit. Google pulse wave modulation to learn more about it. Simply put, the shorter the burst, the lower the voltage, longer the burst, higher the voltage. An analog signal actually varies, it can be off or different magnitudes of 'on'. A PWM signal is on or off.


----------



## jcgd (Feb 18, 2004)

Arctangent said:


> You got the Idea! Except you are not varying the voltage, but the duty cycle. I didn't know you were using the dimmable drivers, never messed with them myself because they _are_ expensive. Actually I _just_ started looking at them today (for my Dad's guitar shop).
> 
> 
> What I'm trying to convey is that you can use non-dimmable constant current drivers, an Arduino (or a 555 timer if all you want is manual control), and a transistor to dim the LEDs. And yes, the transistor would be in series with the string of LEDs, it would go: Driver>LEDs>Transistor>Ground(driver); with a PWM signal on the third transistor leg. I'll do a detailed write up on the subject with good instructions and explinations, but it'll be Monday at the earliest because I'm moving back to college for summer school. If you did DIY drivers (LM-317) and a 555 timer you could have a VERY cheap dimmable driver, and with DX selling XR-Es @ ~$2.6, DIY LEDs in general are getting cheap.


Okay, that makes a little more sense. I've been planning on using the maxwells cause it's all I know how to use. Cheaper is better. The whole idea is for any systems but LEDs end up being too expensive to not build your own. Add in the fact that you get sunrise/sunset, no changing bulbs, shimmer and energy efficiency, using anything but LED is silly.



Arctangent said:


> That seems bulky. Isn't there a POT version...nevermind, I'll just read the thread when I get a chance.


I don't know what POT is, so please do help out. You seem to be very knowledgable. I'm an electrician, just got my ticket fresh outta school and we touched on electronics. That's why I have somewhat of a grasp on these things, but anyone can figure it out with some googling.

I'm just trying to simplify everything down so much that anyone can make it so I'll take anything I can get. I'll keep adding new info to the 1st post as I get it.


----------



## audioaficionado (Apr 19, 2011)

I know the difference between PWM & analog outputs and how they work. I was just wondering if Arduino has any analog outputs or add on analog modules so those of us who start with a manually dimmed system using Meanwell D drivers can just adjust maximum set points to work with 5vdc. Using a transistor as a voltage amplifier isn't a big deal, but it's not as easy as plug & play modules.

POT is a potentiometer which is an adjustable resistor.


----------



## mistergreen (Dec 9, 2006)

Yes, arduino has one or a few analog read & write depending what board you get. It's good for POTs....


----------



## Arctangent (Feb 22, 2010)

> Don't arduinos have analog output modules too?


They have analog IN ports, and mimic analog OUT via PWM.

So Justin, please forgive my lack of exposure to meanwells, but from the diagram it looks like the driver requires DC input? And the LEDs fit between the driver and the transistor, or is that side of it not shown? 

Your diagram is very similar to what I'm talking about, except I am using the arduino/transistor to interrupt the main current (like a relay) instead of feeding a signal to a driver. I think some of the confusion here may stem from the fact that my drivers are AC input. My drivers (~$12 @ DX) have four wires: AC hot/neutral IN and DC positive/negative OUT. Here is how they are wired:










So you see: no reason to switch a 10V reference with this setup, you can apply PWM to the main circuit. The transistors I'm using are Fairchild TIP-112 (it's a darlington transistor...like two transistors piggybacked in one package), I am sending 400 microAmps from the arduino (PWM) and switching 1 Amp on the LED side.

Forget my comment about POTs, it would only work as manual control.


----------



## mistergreen (Dec 9, 2006)

Arctangent said:


>


This looked like my setup except I used PNP transistors and a resistor between the driver/power supply and the LED so the current doesn't fry the LED (safer than sorry).


----------



## jcgd (Feb 18, 2004)

Arctangent said:


> They have analog IN ports, and mimic analog OUT via PWM.


Is this output find do use on analog drivers?



Arctangent said:


> So Justin, please forgive my lack of exposure to meanwells, but from the diagram it looks like the driver requires DC input? And the LEDs fit between the driver and the transistor, or is that side of it not shown?


Not quite. My understanding is that the meanwells have 120VAC in, and 0-10VDC in as well. The driver varies the output depending on what you feed the DC input.



Arctangent said:


> Your diagram is very similar to what I'm talking about, except I am using the arduino/transistor to interrupt the main current (like a relay) instead of feeding a signal to a driver. I think some of the confusion here may stem from the fact that my drivers are AC input. My drivers (~$12 @ DX) have four wires: AC hot/neutral IN and DC positive/negative OUT.
> 
> No reason to switch a 10V reference with this setup, you can apply PWM to the main circuit. The transistors I'm using are Fairchild TIP-112 (it's a darlington transistor...like two transistors piggybacked in one package), I am sending 400 microAmps from the arduino (PWM) and switching 1 Amp on the LED side.
> 
> Forget my comment about POTs, it would only work as manual control.


Okay, this makes perfect sense. But is there any issues switching the actual circuit the LEDs are on? Wouldn't that wear out the PN junction? I know diodes last a long time because of the lack of moving parts, but if that transistor is turning that circuit off and on however many times per second, I would think that would be hard on the LEDs, no?


----------



## Arctangent (Feb 22, 2010)

justincgdick said:


> Is this output find do use on analog drivers?


I can't say for sure if PWM singnals are okay for the analog driver...I would like to say that it's fine.



> Okay, this makes perfect sense. But is there any issues switching the actual circuit the LEDs are on? Wouldn't that wear out the PN junction? I know diodes last a long time because of the lack of moving parts, but if that transistor is turning that circuit off and on however many times per second, I would think that would be hard on the LEDs, no?


Nah...solid state rocks...it's designed for that kind of stuff. I mean you're talking about electrons 'falling' into positive 'holes', losing energy and giving off light...all I'm doing is interupting the flow of electrons. 

The only thing that I'm concerned about is flyback, not sure how well founded it is, but it's a really easy fix...just a diode in reverse polarity acrosss the driver should do the trick.


----------



## jcgd (Feb 18, 2004)

Okay, I'm about to start ordering parts. How hard is it to make my own drivers? Is it expensive? I'm not sure how you would go about it whatsoever.


----------



## O2surplus (Jan 31, 2010)

Arctangent said:


> I can't say for sure if PWM singnals are okay for the analog driver...I would like to say that it's fine.
> 
> 
> 
> ...



I really hope you understand the "inner workings" of the *Non dim-able *MeanWell *Constant Current Driver *before adding the additional transistor to the circuit, and switching it via PWM from the arduino. I think the MeanWell's constant current circuitry will behave unpredictably and may just "let the smoke out" if your wrong. Play it safe- purchase a dim-able model- if you want dimming, they're probably more expensive for a good reason.


----------



## audioaficionado (Apr 19, 2011)

Yeah letting the magic blue smoke out makes 'em not magic anymore LOL.


----------



## jcgd (Feb 18, 2004)

O2surplus said:


> I really hope you understand the "inner workings" of the *Non dim-able *MeanWell *Constant Current Driver *before adding the additional transistor to the circuit, and switching it via PWM from the arduino. I think the MeanWell's constant current circuitry will behave unpredictably and may just "let the smoke out" if your wrong. Play it safe- purchase a dim-able model- if you want dimming, they're probably more expensive for a good reason.


I'm personally using the dimmable meanwells and using the arduino to control the dimming circuit, OR building my own constant current drivers with the LED circuit being switched for dimming. I believe the latter would be much cheaper, I could just use buck/booster pucks if it works the way I think it does or actually build drivers from scratch.

The thing that sucks with the meanwells is the price tag. I would like to have as many drivers as possible so I can have more control over the fixture for things like cloud cover. One thing that is somewhat important to me is matching the colour of the morning and evening sun. I really want to have a more yellow light in the morning similar to the warm glow the sun gives off and have the other colours slowly add in towards the end of the cycle for my preferred daylight colour.


----------



## audioaficionado (Apr 19, 2011)

I dunno... even at minimum wages doing a total component level DIY, the $30 price for a Meanwell sounds like a bargain.

YMMV


----------



## jcgd (Feb 18, 2004)

audioaficionado said:


> I dunno... even at minimum wages doing a total component level DIY, the $30 price for a Meanwell sounds like a bargain.
> 
> YMMV


Very true, but if the components are cheap enough, the time to build is hobby time. I think I will likely go with meanwells to keep it simple though. The more I read about the arduino and using it for control, the easier it seems. I was looking on ebay and you can get everything pretty cheap.


----------



## Arctangent (Feb 22, 2010)

This is all fine. If you feel uncomfortable with this method then dont do it. I'll say one last thing here on the subject: Think of putting a push-button switch which is normally open (off) in place of the transistor. You push the button it allows current thru, let up on it and current stops. This is the same function that the transistor plays. Would that let the blue smoke out? I can't say for absolute certainty (a very hard thing for anyone to do) but I seriously doubt it and I would be pissed at spending quality money for such a fraglie driver. I am confident enough in the idea to build my system this way (which is in progress and has passed preliminary testing). Again, flyback is the only issue I can think of but I'm all ears if anyone wants to collaborate. Also, once more, I am using generic drivers, not meanwells. So I dont claim to be some meanwell expert, and I only have a vauge idea of how they actually work internally.

Look for a write-up soon. If I start my own thread on control electronics I can be more encompassing; giving my background, disclaimers, fully developed thoughts, descriptions, ect. Then, if the OP likes it, he can link to it here on the first page.

Be patient tho, I'm very busy and a good write up may take some time.


----------



## jcgd (Feb 18, 2004)

I recieved my Arduino Duemilanove along with a real time clock, lcd screen and prototype board in the mail. I also recieved my resistors and transistors.

The prototype board, resistors and transistors were going to be used to build circuits to convert the 5v PWM signal the Arduino puts out, but I am going to be using drivers from a member on the board that will accept a 5v signal. This should simplify things a bit.


----------

