Using NPN transistor for either load control (LEDs) or digital signal (WS2812)

Good morning/evening,

Writing here as we're a little bit stumped on what I thought was a simple design, but turns out to be much more complicated.

We want to have an arduino based system controlling either a high current load (such as high power LEDs), or a digital device (such as WS2812 ledstrip).This would be SW controlled of course.

Our original plan was to use an NPN transistor, with a design similar to this one:

Don't pay attention to the resistor values, they are just here as a reference

Design is quite simple really, 3.3V on the output of the Arduino (it's actually an ESP12, but from the principle it does not really matter as far as I understand), and 5V on the output.

Output GPIO of the ESP12 has an internal pull-up to 3.3V, so we don't need to add it on the gate (well... in theory)

To provide even more flexibility, we would like to be able to switch between 5V and 3V and 12V on the output reference voltage (using DIP switches)

Except that:

  • We can indeed drive loads with this setup, works fine
  • However digital logic does not work in most cases. We can make it work for one reference voltage (ie 3.3V output), using appropriate tuned resistor values (and of course we need to pay attention to the signaling, since it's inverted, but that works), but we can't make it work with a 5V output with the same value.

What we don't get is why:

  • Why would resistor values have such an impact
  • Why would reference voltage have such an impact
  • Why would the resistor values depending on the reference voltage ?

It's been many years since I looked into NPN transistor design (plus I was abysmal anyway at analog circuitry design - as proven here), but I would have assumed I could resolve this. No luck.

Again, we can drive a load so we know the transistor does activate when input pin is driven high (so output pin is driven low - we drive the load by the ground)

It's digital logic (frequency is at 800khz) which eludes us. WS2812 input is high impedance, so we tried to add a serie resistor on the output of the transistor to attenuate signal integrity issues, but that did not resolve the issue

Next step would be to add a scope and see what's wrong, but as a starting point : any guidance you could give ?


I assume this circuit drives the data-input to the WS2812? In that case, your driver circuit doesn't handle any significant current.

The WS2812 want's a 5V data signal. If Vcc is 5V, your transistor circuit will "boost" (and invert) the 3.3V signal.

Are you sure? A "regular Arduino" output pin is driven high or driven low so you don't need pull-ups or pull-downs.

What's "output voltage"?

The 1K resistor shouldn't be critical because of the WS2812's high input impedance.

R1 may be too high to fully-saturate the transistor. I'd suggest about 10 times R2.

What's "reference voltage"?

Quite simply do not attempt to use this circuit to drive WS2812s.

For WS2812s, you use a 74HCT14 with two gates cascaded to drive them from your 3.3 V logic.

You want a true logic-level FET to drive higher current LED strips.

These are two entirely different circuits, not "switchable". :roll_eyes:

Saturating the transistor is exactly why this circuit is totally useless for driving WS2812s. :astonished:


The goal is to have a dual purpose output circuit using the same output pin

Use case 1/ : drive a load. This needs flexibility on the output voltage, in my diagram above this is VCC. It could be 12V or 5V or 3.3V, depending on what we need to drive

Use case 2/ : drive a WS2812. In this case this becomes a pure logic circuit, VCC is set to 5V. Data signaling is inverted, so we need to use a custom WS2812 library, but that's fine we have that already

So to come back on Paul_B answer, I can't use a 74HCT14, as it would not be able to drive a load.

So I would welcome some information.

First to understand why this would not work. Purely for my education, I fully trust your assessment, but I'd like to understand the how and why,

Second, is there an alternative to this circuit that would work for the purpose indicated above ?


Use the 74HCT14 for the WS2812's, and a transistor circuit for the others.

Fast logic chips like the WS2812 need fast logic edges to work reliably - a single general purpose BJT like the 2N3904 is probably too sluggish for the timing requirements, especially single-ended like this.

To get the maximum speed from a BJT for a 5V logic signal this sort of circuit might fare better:
The base resistor to ground helps the turn-off speed, the Schottky diode prevents saturation (helping the turn-off speed even more), and the low load impedance (220 ohms) means the rise-time will be crisp.

Using a small signal MOSFET like the 2N7000 might be another way.


Plus it will INVERT the WS2812 signal.

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

Can someone explain why "Random Nerd" is happy with this circuit for WS2812?

The fritzy.

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

Because it 'may' work. You see the omitting of the resistor, which usually is fine until something breaks. And the direct driving using 3.3v, which may work, or you can seek help on a forum like this.

But there are open-collector versions of that either schmitt-trigger (which is not required) or normal, and either inverting or just buffer. In that case all you would need is a pullup (i'd go for 1K but anything up to 10K is probably fine) . If that can not provide sufficient power, you can go for a mosfet, if needed with an inverter
before it, There will always be limits to the size of the load, and you just need to make sure that the parts that you use can handle the 800KHz of the WS281x

And what use is an open-collector version? :roll_eyes:

Why do you need such "universal" circuit? It leads to partially conflicting requirements - high current low frequency or low current high frequency is easy. When you need both it is hard. Also what "load" you want drive? Motor? LEDs? How much current? Maybe some half H-bridge would do the trick.

It can sink more current ? i mean really, check the datasheet and compare.

No, exactly the same. Are you thinking perhaps, of the 74HC05, the open-collector version of the 74HC04? Exactly the same specs with the omission of the "±".

And note the diode to Vcc on the output circuit for the HC05. It will not allow the output to rise (meaningfully) more than the supply voltage, so no use for controlling higher voltage loads.

So this is quite useless for driving/ level-converting WS2812s as it is missing the active pull-up. :roll_eyes:

Oh well, then those are rather useless i guess.