Switching common anode RGB led?

Thread Starter

k1ng 1337

Joined Sep 11, 2020
100
Hi I have 12 common anode RGB leds where each respective cathode and its current limiting resistor (red, green and blue) is tied to the output of 3 arduino pwm signals - red, green and blue. From here I would like to create an enable function to light any one or all at the same time using transistors. These transistors would have to go in between the positive terminal and the load.

1) Should I use npn or pnp? Since I'm switching the positive terminal and not the load(s) it would be pnp?

2) Will there be voltage issues on the pwm signal if there are many sources trying to sink their current at the same time, up to 12? The arduino pin can sink 40ma and I will design for 20ma.

3) Anything else I failed to consider?

Regards,
 
Last edited:

Ian0

Joined Aug 7, 2020
2,632
If it's common anode, you'll be switching the common positive terminal, so use PNP.
If you have up to 12 LEDS all of which can be on at the same time, then your current limiting resistor must limit the current to 1.67mA, which isn't very bright
The output resistance of the GPIO is 25Ω, so that may cause brightness variations when changing from single to multiple LEDs.
 

Thread Starter

k1ng 1337

Joined Sep 11, 2020
100
If it's common anode, you'll be switching the common positive terminal, so use PNP.
If you have up to 12 LEDS all of which can be on at the same time, then your current limiting resistor must limit the current to 1.67mA, which isn't very bright
The output resistance of the GPIO is 25Ω, so that may cause brightness variations when changing from single to multiple LEDs.
Shouldn't the GPIO output resistance only become an issue once 200ma (5v) is exceeded? Assuming of course I'm only ever jumping from 0-20ma

I'm considering writing a scheme where if only LED is active then its getting 20ma (or some constant brightness) and if 12 LEDs are lit then they still get 20ma globally (or an equal brightness to only the one LED). Easier said then done? I think its a bad idea because 3 pwm signals govern the colour and therefor brightness but I could be wrong on the mechanics.
 

Irving

Joined Jan 30, 2016
1,838
You need NPN Switching transistors to control the cathode side of the LED. Its considered bad practice and you should never power more than a couple of LED from a GPIO pin. Arduino is limited to 20mA per GPIO but <200mA total for the chip. You would be better off with N-channel MOSFET for switching cathode and P-channel MOSFET for switching anodes. This way you can multiplex any number of LEDs and choose any drive voltage/current you desire. You can make either the P- or N- switches into constant current sources/sinks for more precise brightness control, removing the need for lots of resistors.
 

Ian0

Joined Aug 7, 2020
2,632
I may have misunderstood. . . .
Are the cathodes of the 12 LEDs all connected to three pins (i.e. 12 greens to one pin, 12 reds to another), or are they connected to 36 pins?
 

Irving

Joined Jan 30, 2016
1,838
I may have misunderstood. . . .
Are the cathodes of the 12 LEDs all connected to three pins (i.e. 12 greens to one pin, 12 reds to another), or are they connected to 36 pins?
There aren't 36 pins available... So...?

It's clear from his 1st paragraph that it's 3 pins.
 

Irving

Joined Jan 30, 2016
1,838
A more crucial question is: Are the LEDs going to be displaying a line or a 4 x 3 matrix as this has implications on the best way to multiplex them...

What's the overall intention?
 

ericgibbs

Joined Jan 29, 2010
13,227
hi,
This is another example on how a simple sketch of the TS's scheme would help us, help him.

So K1337 please post a sketch.;)

E
 

Ian0

Joined Aug 7, 2020
2,632
There aren't 36 pins available... So...?
I didn't think so, so I was right in the first place. I'd agree with you. Bipolar transistors would work, but if any multiplexing is required above about 1kHz, MOSFETs would be required because of the slow turn-off of a bipolar transistor.
 

Thread Starter

k1ng 1337

Joined Sep 11, 2020
100
I may have misunderstood. . . .
Are the cathodes of the 12 LEDs all connected to three pins (i.e. 12 greens to one pin, 12 reds to another), or are they connected to 36 pins?
12 of each colour is the plan for 36 total each with a resistor unless I can consolidate. I am building a clock with random led programs in between time updates.

As Irvine suggested I do intend to multiplex and somehow drive different colours at the same time but for now I am content with a one colour for the whole set. Since I have 6 pwm pins available ill split the 12 leds into two groups

and to ericgibbs, I laughed at your comment, I do have the tendency to be vauge and assume my teachers can improvise ;)

ill draw up the schematic now since it pleases the crowd
 

Thread Starter

k1ng 1337

Joined Sep 11, 2020
100
Draw it for your own benefit as well!
All manner of potential problems are not obvious until it's down on paper (and some not obvious until it's built).
A circuit that only exists in your mind always works.
I only did three numbers because life is too short, and I got the red and blue pwm mixed up.

Also is the formula R = Vs - Vf / If appropriate in this situation? I already have a scheme that outputs an 8 bit number set by three potentiometers, so picking and setting the colours is done digitally.. I'm not sure how a pwm signal, an led and resistor behave especially when the pwm signal is sinking current and how to select the appropriate resistor size.
 

Attachments

Last edited:

Irving

Joined Jan 30, 2016
1,838
I only did three numbers because life is too short, and I got the red and blue pwm mixed up.

Also is the formula R = Vs - Vf / If appropriate in this situation?
Not quite.

R = (Vs - Vf - Vce(pnp) - Vlo)/If
Vs = 5v
Vf = 2 - 3v depending on colour
Vce(pnp) = 1 - 2v depending on transistor, collector current, base current
Vlo = max low voltage of arduino (~0.3v), depends on sink current.

It could be that you don't have the voltage to meet Vf on some colours.

MOSFETs would be better as would higher than 5v source with a constant current drive. A lot will depend on your PWM scanning/matrixing strategy. eg PWM RGB on a single LED will vary current through the PNP so Vce will vary depending on total current draw, so colour will not be consistent with brightness. Using a higher constant current drive, faster PWM and 'one colour at a time' strategy will give much more consistent colour v brightness by runniing each LED harder but with lower duty cycle.

Not sure how you do a clock with 12 RGB LED though.
 
Last edited:

Thread Starter

k1ng 1337

Joined Sep 11, 2020
100
Not quite.

R = (Vs - Vf - Vce(pnp) - Vlo)/If
Vs = 5v
Vf = 2 - 3v depending on colour
Vce(pnp) = 1 - 2v depending on transistor, collector current, base current
Vlo = max low voltage of arduino (~0.3v), depends on sink current.

It could be that you don't have the voltage to meet Vf on some colours.

MOSFETs would be better as would higher than 5v source with a constant current drive. A lot will depend on your PWM scanning/matrixing strategy. eg PWM RGB on a single LED will vary current through the PNP so Vce will vary depending on total current draw, so colour will not be consistent with brghtness.

Not sure how you do a clock with 12 RGB LED though.
why is Vce so high? I thought it was nominal 0.7v and I'm not familar with the Vlo paremeter can you elaborate? And what resistor values might you suggest?
 

Ian0

Joined Aug 7, 2020
2,632
That value for Vce(sat) does look high. For a medium current transistor like a BC807 it can manage 0.07V at 100mA.
The output of the GPIO is pretty close to being a 25Ω resistor, so ignore Vlo and subtract 25Ω from the value you calculate.
(That only works if you have only one LED switched on a time)
 

Irving

Joined Jan 30, 2016
1,838
why is Vce so high? I thought it was nominal 0.7v and I'm not familar with the Vlo paremeter can you elaborate? And what resistor values might you suggest?
You're thinking of Vbe, which is a nominal 0.7v. Vce varies with Ic and how saturated transistor is. A MOSFET would be better.

Vol or Vo(low), from ATMEL datasheet..

1619866645779.png

At 20mA, you'll lose 0.8v toground in GPIO pin.
 

Ian0

Joined Aug 7, 2020
2,632
That value for Vce(sat) does look high. For a medium current transistor like a BC807 it can manage 0.07V at 100mA.
The output of the GPIO is pretty close to being a 25Ω resistor, so ignore Vlo and subtract 25Ω from the value you calculate.
(That only works if you have only one LED switched on a time)
 

Irving

Joined Jan 30, 2016
1,838
That value for Vce(sat) does look high. For a medium current transistor like a BC807 it can manage 0.07V at 100mA.
The output of the GPIO is pretty close to being a 25Ω resistor, so ignore Vlo and subtract 25Ω from the value you calculate.
(That only works if you have only one LED switched on a time)
Agreed certain devices may have typical Vce(sat) much lower, but we don't have the full picture yet.
 

ericgibbs

Joined Jan 29, 2010
13,227
hi Irving,
I disagree with your Vce values, far too high.
Also the 20mA via the GPIO pin, the 0.8 is also too high.
[corrected text]
E
ESP_ 179.png
 

Thread Starter

k1ng 1337

Joined Sep 11, 2020
100
Not quite.

R = (Vs - Vf - Vce(pnp) - Vlo)/If
Vs = 5v
Vf = 2 - 3v depending on colour
Vce(pnp) = 1 - 2v depending on transistor, collector current, base current
Vlo = max low voltage of arduino (~0.3v), depends on sink current.

It could be that you don't have the voltage to meet Vf on some colours.

MOSFETs would be better as would higher than 5v source with a constant current drive. A lot will depend on your PWM scanning/matrixing strategy. eg PWM RGB on a single LED will vary current through the PNP so Vce will vary depending on total current draw, so colour will not be consistent with brightness. Using a higher constant current drive, faster PWM and 'one colour at a time' strategy will give much more consistent colour v brightness by runniing each LED harder but with lower duty cycle.

Not sure how you do a clock with 12 RGB LED though.
Now that I see the schematic it's obvious the pwm signals should be driving mosfets to sink the current.. this takes care of current problems for the io pins. I have enough logic n and p channel for the pwm signals but not the enable transistors.

The clock output concept is simple (for now): 12 leds in a row, if its 5:37 then flash 5 flash 3 flash 7

also I'm using 2n3906, cheap LEDs and 350ma logic level mosfets
 
Top