If it works, it works

I need transistors to power a common cathode RGB LED. If it were a common anode RGB LED, I would use NPN transistors on low side. Now I would need PNP on high side. But I read that the digital signal level needs to be at same level as the power source. Or I'd need an extra layer of transistors to drive the PNP transistors.
But I'm trying to use what I have and make it simple. So I tried this circuit:

The logic level is 3.3 V (Arduino Giga) and the source is 4*AA batteries or 6 V. The voltage drop on a green LED is around 3 V, so I need a 3 V drop in a restricting resistor. But this resistor becomes a load of its own, right? So I can place it on the high side and use my NPN transistors I happen to have (BC547). Since the voltage drop on a green LED is 3 V, the voltage at the emitter would be 3 V, which is below the base voltage, when the signal is high.

I tested this and it works. The current through the LED is 20 mA, which means optimal power. The current from the signal is 0.3 mA, according to my multimeter. But since I'm no expert on this stuff, I'm hoping for comments.

It should not.
If the Vf of the diode is 3V then the base voltage would have to be at least 3V + Vbe(sat) for the transistor to turn on. The minimum Vbe(sat) for a BC547 is probably no less than 0.6V, so the voltage on the 1K resistor would have to be greater than 3V + 0.6V = 3.6V but it is only 3.3V

Also the max current would be 15mA

So your measurements and calculations must be wrong.

Probably more close to 2.2V. Otherwise your circuit wouldn't work.
ps. try how it goes with blue LED..

You could look up "transistor emitter follower configuration" which you appear to be using and try to understand why it is not very appropriate in your switching application where the transistor base drive voltage is relatively low. You also do not need a base current limiting resistor in this configuration.

Green and blue would be very same. At least the Vf is alays listed as equal. So far the red and the green blink very nicely with the proper current through the leds and a very small current at the base. I'm going through everything one more time and test the blue, too.

Can be. Generally blue have higher forward voltage, but I have seen many RGB LEDs give same for both on specs...

As I pointed out your measurments don't correspond to the Vfs you claim.
This particular setup may work for this one LED but may not work for the next one you buy

If you do find that your circuit doesn't work correctly or consistently, and decide you need to more transistors, a simpler option might be UDN2981A. Ok, it's 8 channels and you only need 3. And it will have a higher voltage drop than PNP transistors, but with 6V supply you can afford that. But it is one chip replacing 6 transistors and several resistors. You will still need your LED series resistors, but you can use lower values to compensate for the higher voltage drop.

Have you tried powering the LEDs directly from 3.3V GPIO pins? It seems there is enough voltage. You would have different resistors on the three colors, and 20mA each would probably not be doable, but it might be worth seeing high bright it would be.

The optimal current for the leds is 20 mA, but the GPIO pins of the Giga may only provide 7 mA each. That might be enough to light up the leds, but I use the RGB LED for colour detection, together with an LDR. So I want the brightest possible.

Well, it does work. But as kmin probably suspected, the blue doesn't get very much current. Although I get all three colours, the blue is really much brighter, when I just light it up with a proper voltage and limiting resistor. Since I'm using what I have right now, instead of ordering the proper components for this, I'm going to use PNP transistors. And I'm leveling up the 3.3 V signal to 6 V with a 4 channel level switch I happen to have lying around.

Why you need to power the LED with 6V?

I think you are confusing that wit absolute max current.
There is no optimal current. Led current can be any thing between zero and absolute max, depending on required brightness. 1 to 5mA is usually enough brightness for modern LEDs.

The circuit in post#1 is just wrong. The LED should be in the collector line.
The 30k resostor has no function here, it can be removed.
A bleed resistor like that is only needed for mosfets.
Leo..

I need the 6 V for other things. It's powering the Giga, too. I might run into problems because of that, but that will be another issue.

I need to test the brightness with 7 mA. If my colour detection works fine with that, I'll power the leds directly from the GPIOs.
I thought 20 mA would be optimal, because 20 mA is used in the datasheet in all tables and charts. It might be labeled as "typical".

You always need a method of limiting the current through an LED and the resistor is the simplest way. If you don't use one then things will burn.

However your title "If it works, it works" is not true. It does not imply if it works then it is OK.

Exceeding recommended values for current.
Exceeding Limits for current
Undoubtedly they can be pushed, in electronics there is no such thing as a point where below is safe and above will destroy the chip. It is a continuum, there is a point where the chip or wires inside the chip will melt, however before you get to that point you enter the region where the chip deteriorates faster than it otherwise would. Where that point is you can't say because no absolute values are given in the data sheet. This can result in early failure or life shortening. It is just like smoking, damage is being done to you lungs all the time but you don't immediately drop dead, it is just that you don't live as long.

Do you know that smokers have a much lower chance of getting Alzheimer's disease, it's not because of any protective effect of smoking but simply smokers tend to die before they can develop it. The same with exceeding recommended values in electronics.

No, that is very much a typical maximum current for an LED, and an old one at that. Most LEDs made in the last 15 years have a much higher efficiency in turning current into light. This is because they use different sorts of doped semiconductors to make them.

See:- Wikipedia on LEDs

If you really need more current, and have unused pins, another option would be to power each color from two GPIO pins, or even three, each with its own resistor to provide 7mA.

Processors also have port (groups of 8 pins) current limitations.
Make sure you stay below that too.
Leo..

Hi, @Johan_Ha

Using your circuit, just so to show you how your circuit is possibly working, measure the voltages at points A to E with respect to GND.
Do this for blue LED, with the Arduino signal low and high states.

Thanks.. Tom.. Tom.... :smiley: :+1: :coffee: :australia:

Voltage at B is 30/31 * 3.3volt = 3.19volt, because of the voltage divider.
Actually a bit lower, because of the tiny base current.
Voltage at C is 3.19volt minus the BE diode drop, so about 2.5volt.
The circuit is an emitter follower, because emitter "follows" base voltage (-0.6-0.7volt).
This a constant voltage circuit (2.5volt), with 200 ohm current limiting.
Not good to drive a blue or white LED.
The LED should be used in the collector line, with the emitter grounded.
Leo..

That's a really good advice! I'm using a Giga, which has multynine pins. There's a total limit, not all pins can provide 7 mA at the same time. But sure I could have 2 * 7 mA to light one colour at a time.