Pages: [1]   Go Down
Author Topic: Running RGB LEDs direct from an arduino  (Read 627 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello, im sure I cant be the first to ask this but I have had a look around and not seen it.

The idea is simple, use an arduino to control RGBs. At the minute I'm just testing, so simple on off in all colours is all I need. Later I will want to fade between them, presumably with PWM.

The issue I have is that the ones I am using have a common anode. So I have 5V going to this from the breadboard. But surely the digital pins need to connect to the anode? elseif I connect the cathodes to a digital pin of the arduino and tie it LOW, ?it will switch on? (or break?) but then if I tie it HIGH surely you have 5V coming from 2 directions and a short circuit?
http://www.technobotsonline.com/7.6mm-piranha-rgb-led.html

So how do I get around this? Is using the arduino HIGH to trigger a transitor to open to ground the answer? IS there an easier way?

Many thanks in advance, David
Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 121
Posts: 4598
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The issue I have is that the ones I am using have a common anode.

No problem.

So I have 5V going to this from the breadboard. But surely the digital pins need to connect to the anode? elseif I connect the cathodes to a digital pin of the arduino and tie it LOW, ?it will switch on?

Yes.

(or break?)

Only if you don't use a resistor...
Logged

No, I don't answer questions sent in private messages...

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

im having trouble figuring out how to make my LED light strip to light up inside a drum when struck with a drum stick. can anyone help?
Logged

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

im having trouble figuring out how to make my LED light strip to light up inside a drum when struck with a drum stick. can anyone help?

I'd guess you could have a small microphone inside, hooked up to the analogue input of the arduino, then code it to using the analogue read function and  an if function, so that if the value from the microphone went above a certain level (as in the volume of the bang) then trigger a digital output to HIGH and that would fire a relay. You would have to fiddle with values alot so that only bangs set it off an not music volume.

 
The issue I have is that the ones I am using have a common anode.

No problem.

So I have 5V going to this from the breadboard. But surely the digital pins need to connect to the anode? elseif I connect the cathodes to a digital pin of the arduino and tie it LOW, ?it will switch on?

Yes.

(or break?)

Only if you don't use a resistor...


Ok so i can do this and the arduino will actually take it, cool. I had thought i'd better check before blowing it up. I looked for this in the learning section but didnt see it mentioned anywhere.

So its simply a resistor in series so drop the current like with any other LED? (Though for some reason, the red on this runs on a lower voltage than blue and green, so i guess its 3 (2 values) resistors, all between the cathodes and the arduino?

Thanks for the reply!
Logged

Offline Offline
God Member
*****
Karma: 3
Posts: 813
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Each different LED process has a different forward voltage drop, and each LED kind will typically have a different target current, too.

Thus, a low-current red LED with 1.8V forward voltage drop and 2 mA design current would need a 1.6 kOhm resistor from a 5V output ((5.0-1.smiley-cool/0.002.) A medium-current green LED with 2.1V forward voltage drop and 10 mA design current would need a 290 Ohm resistor ((5.0-2.1)/0.010.) A high-current blue LED with 3.0V forward voltage and 25 mA design current would need a 80 Ohm resistor ((5.0-3.0)/0.025.)

You can find the forward voltage and current needs for your LED by reading the data sheet.

However, it turns out that most LEDs will do fine with significant over- and under-currents. Thus, a 220 Ohm or 470 Ohm resistor or even a 1.0 kOhm resistor may be "good enough" for most LEDs to make some light and not immediately burn out. Thus, many tutorials will recommend one of these resistors without going into how that value was derived.

When it comes to running a common anode LED, that's not that different from anything else. As you noticed, driving the pin low will make the AVR CPU sink current, and will turn the LED on, if the LED anode is at +5V. It may also burn out the LED if you don't have a current limiting resistor, and may even burn out the Arduino if the LED current consumption is too high. The Arduino is acting as a "low side switch" here, which is not particularly uncommon in modern electronics.

However, your description of driving the pin high is not accurate. Setting the output to +5V on one end, and connecting the anode to +5V from the other end, will not "drive the LED from both sides." Any component only sees the voltage differential between its sides, and when both sides are at +5V, the differential is 0V, and there will be no current flowing. Thus is the same thing as tying both ends to ground -- the differential would be 0V, and no current would flow.

To close the loop here, a "high" output pin from an Arduino is actually more like 4.75V-4.8V, because of losses in the transistors that turn the ports on/off and other internal circuitry in the AVR controller. Thus, if you tie the anode to +5V, and drive the other pin high in an output, you will see a voltage differential of 0.25V. However, this is sufficiently below the forward voltage drop of the diode, that effectively no current will flow, and the diode will not turn on. Even if you replaced the diode with a resistor, it would be OK, because the AVR can take a slight overvolt on output pins, as long as the current isn't higher than specified (25 mA typical, 40 mA max.) It's a very robust microcontroller -- don't expect every chip to be that nice! The Arduino Due is reported to be much less robust (and reading the data sheet, that would make sense.)


Logged

Valencia, Spain
Offline Offline
Faraday Member
**
Karma: 121
Posts: 4598
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So its simply a resistor in series so drop the current like with any other LED? (Though for some reason, the red on this runs on a lower voltage than blue and green, so i guess its 3 (2 values) resistors, all between the cathodes and the arduino?

Yep.

Red LEDs are usually lower voltage than other colors so red will need a slightly bigger resistor.
Logged

No, I don't answer questions sent in private messages...

UK
Offline Offline
Newbie
*
Karma: 0
Posts: 22
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for the clarity there Jwatte, if only all datasheets could explain things that clearly!

fungus. All is working now, thanks for the help! smiley
Logged

Pages: [1]   Go Up
Jump to: