# Common cathode RGB LED from 3.3v

I have an RGB LED (common cathode) that I would like to trigger from the GPIO pins of an ESP8266 (3.3v). The device I am using (Wemos pro mini D1) has a 5V supply which I was planning on controlling via a transistor (I have some 2N3904).

From some reading I understand this can be achieved as follows (and I'm happy with the reasoning why):

Credit: here

However, I wanted to know if this was achievable using just one BJT? I've seen some people suggests just using one NPN and the load on the emitter and no resistor on the base but when I tried this out I had extremely low Ib which was insufficient to fully "switch" the BJT.

• It seems odd to me that the majority of RGB LEDs are common cathode if the method for driving them is more complex. Is anyone aware of why? Commented Jun 7, 2018 at 11:35
• A quick look at Digi-Key shows that they have 236 different common cathode and 709 different common anode LEDs.
– pipe
Commented Jun 7, 2018 at 11:38
• Actually, when filtering on RGB LEDs I can't find a single common cathode model - they are all common anode.
– pipe
Commented Jun 7, 2018 at 11:39
• That's odd! I was looking on RS Components and have the opposite issue... Rather confused now! Commented Jun 7, 2018 at 11:40
• Wonder if it's different between SMD and Through-hole parts.
– pipe
Commented Jun 7, 2018 at 12:01

I wanted to know if this was achievable using just one BJT?

Not so easily in your case, the issue is that the ESP8266's output is either 0 V or 3.3 V. Relative to the +5 V rail (where the switching transistor would be) that gives either 5 V - 0 V = 5 V or 5 V - 3.3 V = 1.7 V across the input of the transistor.

Switching on/off an NPN using 0 or 3.3 V can be done directly (as per your suggested 2 transistor circuit).

Switching on/off a PNP (since we switch the +5 V side) using 1.7 V or 5 V is less straightforward. It could be done for example using a zener diode to subtract about 1.7 V but it is cumbersome. The 2 transistor solution is just as easy, likely costs the same (only standard components needed, no zener needed) and more fail safe.

• Thanks, is there a name for this kind of setup (the one I included in my question)? Commented Jun 7, 2018 at 12:12
• Not really as far as I know. Having the PNP switch on/off the supply side is called "high side switching" so if you google that you might see similar circuits. Shifting the 3.3 V logic signal to a higher voltage (here 5 V) is done with a circuit called a "levelshifter". Your circuit is basically a combination of these two. Commented Jun 7, 2018 at 12:44

You can certainly drive low power LEDs with a single inverting transistor.

Keep in mind a few rules of thumb for low voltage LED drive since millivolt drops and impedance ratios matter in transistors.

• read and understand the LED datasheet throughly, especially the VI curves, same for transistor like P2N2222A
• Vce(sat) is always rated for 10% base current but at low current you can get away with 1% base current 0.1V rise in the P2N2222A. Meaning, as the transistor saturates, the hFE drops to 10 at two typical current levels.
• Include above in Ohms Law or KVL calculations.
• treat the transistor like a switch with series R or Rce ( resistance for CE as a switch is given in some datasheets at Diodes Inc.) but I just call it Equivalent Series Resistance or ESR where ESR~0.5 * 1/Pd rating ( @85'C also 2:1 mfg tolerance) so if rated for 0.5W @85'C then 1 Ohms. ESR applies to all logic devices too , and FETs (RdsOn) and caps and coils (DCR) So a 1W LED has 10x the ESR as a 10W LED (or any diode or transitor)

• 5V Logic starts around 50 Ohms and drops around 25 Ohms for 3.3V logic chips (50% tolerance) for direct drive scenarios. ( old 15V logic was around 300 Ohms)

• But before you reinvent the wheel, there are about 10 thousand different LED driver designs so read! often. https://www.digikey.ca/product-detail/en/issi-integrated-silicon-solution-inc/IS31FL3194-CLS2-TR/706-1598-1-ND/7564593

IS31FL3194 is a 3-channel LED driver which features two-dimensional auto breathing mode. It has Pattern Mode and Current Level Mode for RGB lighting effects. The maximum output current can be adjusted in 4 levels (40mA Max.).

In Current Level Mode, the current level of each output can be independently programmed and controlled in 256 steps to simplify color mixing. In Pattern Mode, the timing characteristics for output current - current rising (T1), holding (T2), falling (T3) and off time (TS, TP, T4), can be adjusted individually so that each output can independently maintain a pre-established pattern achieving mixing color breathing or a single color breathing without requiring any additional interface activity, thus saving valuable system resources.

ALSO

The following features are only partially or not supported by Espruino on the ESP8266:

No hardware I2C, however, the software I2C works OK.
PWM does not work, low speed software PWM is usable
No DAC: the esp8266 does not have a DAC.
No independently usable serial port (needs Espruino work)
GPIO16 is now supported in Espruino as a D16 without watch
but with all software functions like PWM/I2C/SPI/etc


Have you considered going one step further and drive the LED with 0 transistors?

The ESP8266 has 3.3V output and should allow 10-20mA per pin [Check the specs carefully though, check the limit per pin and the limit for pins combined]. LEDs light up, mostly depending on color, between 2.8V and 3.2V [Again check the specs of your LED, for each of the 3 colors]. LEDs also have a current limit, usually around 40mA, but 20mA is plenty bright. Given the voltage at which the LED lights up and the current allowed per pin (or for the LED, whatever is smaller) you can compute the needed resistor to keep everything within specs.

Example: The resistor has to bring the 3.3V down to what the LED needs. For a 3V (red) LED that means you have to burn of 0.3V. At 20mA current limit you get: R = V / I = 0.3 / 0.02 = 15 Ohm.

• From experience, while technically doable, it is a bad practice to drive something directly from a GPIO. If it is only a signal, then there is no problem. But, you never know when you will short something, overtax your controller or anything similar leading to hardware failure that could be avoided. Plus, it makes for a far less interesting learning experience when you learn electronics ;) Commented Jun 7, 2018 at 13:25