Author Options:

whats the best/cheapest way to drive 20 or 30 common cathode rgb leds with an arduino? Answered

i would like to drive 20 or 30 leds i got on ebay to put in my truck. i already got some code to change the color of the led with pwm using only one potentiometer, but i am not sure how to power the amount i need. it will need to use the 12 volts or so available in my truck.



Best Answer 9 years ago

Transistors! If all of the LEDs will be changing colour at the same time, you will need three, one for each colour. All of the cathodes will connect to ground through a current-limiting resistor (one for each LED), the value of which should be picked for the highest voltage drop (probably the blue LED). On each red anode, an additional resistor should be added to balance the colour mixing and get the current correct. Every colour anode will be connected together (all the reds, all the blues, all the greens). Those anodes will be controlled by one PNP transistor (or a P-channel low-Rds MOSFET) each. The base of the transistor (or the gate of the MOSFET) connects to the microcontroller through a current limiting resistor. When calculating the current limiting resistor values for the LEDs, make sure to take into account the voltage drop of the transistor as well (this is not necessary for a MOSFET, it will drop very little voltage).

do you have a particular mosfet in mind? is the 5 volts from the arduino enough for the mosfet? thanks for a fast answer!

The one you choose depends on the amount of power it has to switch, whether it should be through hole or surface mount, and how much you want to spend. Unfortunately I can't name a part number off the top of my head... The 5V from the arduino is enough to turn on the MOSFET, but only one with a low Rds. Another name for these devices is "logic-level compatible" MOSFETs, since they can be driven with low voltages in the +5V range (logic level). But really, either a transistor or a MOSFET would work.

I re-read my reply and realized I am describing two different features of a mosfet. The first feature is the logic-level compatible input, which determines whether the MOSFET can be driven directly by a microcontroller pin (through a small value resistor). The second feature is a low Rds On, which means that when the MOSFET is conducting from drain to source, it has a very low internal resistance - allowing it to run without dissipating a lot of heat.

sorry, i know this was a while back, but I was wondering, If you connect the RGB leds as you describe above (in best answer) don't you risk experiencing the 'hero device' effect? where one of the LEDs (for each color) will not be evenly matched with the others and end up syncing nearly all the current for the group? and to avoid this wouldn't you have to bias each color for each led with its own resistor? or am i missing something?
thanks in advance

what size are the LEDs? are they high output 1watt/350mA or small 20mA ones? ones do they have to be common cathode? 
do you want them all to change color at the same time? or each have it's own channel?  

if you want them all to change at the same time then you could possibility get a few mofsets search www.arduino.cc for "RGB LED Mofset" for some instructions or you could get a $25 RGB Amp that you can just connect to 3 of your PWM out pins and it has an opto-coupler and the mofsets built in, it will connect to your 12v battery and output to any 12v RGB Led modules or strips or if you have the small 20mA leds you will need to put a 760ohm resistor on each of the 3 (-) legs of each one.

if you want to control each by it's self there are some TTL driver boards that you can connect up to 32 RGB high power leds at 300mA with a 5-24v input for about $75

Actually the first thing you will want to use is shift registers, something like a 74HC595, these at the most basic level take 3 output pins (data,clock,latch) and convert them to many pins as the can be chained together from there you will probably want to drive the unit using a darlington array, probably ULN2008A this is basically a bank of 8 transistors and can sink ALOT more current then the registers or the UC