# Transistor driving LED

I have already asked a question regarding this problem but it was about a different thing, slightly. Here is the drawing of a LED driving circuit. The problem I have encountered with traditional resistor circuit is that I need a very precise current to run through that LED so it produces the desired amount of light.

Lets say 8 bit precision (255 steps). Since LED's Vd can vary with a current I thought that a simple resistor circuit woukdn't be able to give the precision in the desired range, just because there is no way to mathematically express the voltage drop of a LED.

So I came up with the circuit that is shown above. When I showed it to some people they told me that it is a terrible idea to do so without any explanation and looking at me like I am an idiot.

So far the transistor works as a current limiter, it limits current to lets say 20mA perfectly no matter what LED Vd is. It is always going to be the desired current. One problem I ran in to is that a transistor now has a current depending on Vd from its base to emitter. Which again puts me in a situation where I need to mathematically express that and again there is no such a way to do so, because of too many factors I can't control - for example, manufacturing process.

Why do I need such a precision ? I am trying to make LED that displays a color. RGB value. So for example 0.00007843137 Amps is Red = 1 and 0.00015686274 Amps is Red 2 (8 bit colors).

My question is how to precisely express this voltage drops in a transistor or LED in order to manipulate such a small current.

• For RGB and assuming you'd like to vary the color from the perception of humans, the better way to go is to use a current source for each color. Each current source should be adjustable (use a pot, if you want.) You turn on all three LEDs and adjust the three different current sources to produce a bright white value that you like. (Or set them to 25% of what will become their peak values -- which is what I do -- and then do the same.) Once you've established your "white" you then simply PWM each of the three LEDs from 0% to 100% to adjust color. This provides a way to match one RGB to another. – jonk Nov 10 '18 at 10:13
• whats the difference Current source or battery or voltage source ? – Anton Stafeyev Nov 10 '18 at 10:38
• Any circuit that depends on an exact value for Hfe will be unreliable. No two transistors will have exactly the same Hfe - not even two transistors of the same model made one right after the other. They will be close, but never identical. – JRE Nov 10 '18 at 10:53
• So how do humans build reliable electronics then ? how do we get reliable PC monitors for example. as it is some kind oif a poormans LED screed, – Anton Stafeyev Nov 10 '18 at 10:54
• For analog circuits we use negative feedback to correct for non-linearities in the devices. For digital circuits we use on/off control and various techniques such as PWM which only require the fully-on or fully-off states. – Transistor Nov 10 '18 at 10:59

A simple way to accurately control RGB LEDs is with a 3-channel shift register PWM driver.

All you do is use one resistor to set the maximum current for all three LEDs and then program the grey scale values for each LED.

The Texas Instruments TLC5973 has 4096 brightness levels for each LED. The device is programed with a single serial wire. The device has an internal oscillator so no clock is required for the serial data.

I would recommend using 50 mA LEDs for increased brightness resolution. My question is how to precisely express this voltage drops in a transistor or LED in order to manipulate such a small current.

The volt drops in the transistor and LED are subject to temperature variations and are also not constant between one device and the next. You won't get precision and control trying to use the hFE (current gain) of a BJT; to get precision you need feedback.

So, if you want precision, I would consider using a driver with an op-amp like this: - The op-amp ensures that the current through the sense resistor produces a voltage across it that matches Vin hence, the current through the LED is held reasonably constant. This is feedback and it overcomes the temperature dependent variations in both the LED and BJT.

A slightly simpler circuit that drives the LED directly from the op-amp is this: - But you need to use an op-amp that can drive the LED current and this limits the devices that are available should current be in excess of 20 mA.

i would like to know how to calculate Vbe which depends on current. it could be 0.6 or 0.7 according to a datasheet. but what it exactly because 0.001 Vbe will affect the LEDS brightness if lets say Hfe is 150

It depends on: -

• Base current
• Temperature
• Variations between one device and the next

It has an exponential formula if you are interested: - All three above are generally referred to as the Ebers-Moll equations and $$\V_T\$$ in the denominator of the exponential is the temperature dependency factor. $$\I_S\$$ is the reverse saturation current and this will vary between one BJT and the next.

• well it doesn't matter what is before that transistor. the question i ask is how to put all together using Ohms law and calculate the precision. i am driving this transistor with PWM signal. but to get that resolution i would like to know how to calculate Vbe which depends on current. it could be 0.6 or 0.7 according to a datasheet. but what it exactly because 0.001 Vbe will affect the LEDS brightness if lets say Hfe is 150 – Anton Stafeyev Nov 10 '18 at 10:34

The problem i have encountered with traditional resistor circuit is that i need a very precise current to run through that LED so it produces the desired amount of light. Lets say 8 bit precision (255 steps).

The simple and accurate way to do this is to use PWM and vary the on/off ratio of the LED. Figure 1. Pulse-width modulation (PWM) of 80%, 20% and 80%.

Since LED's Vd can vary with a current i thought that simple resistor circuit wont be able to give the precision in the desired range, just because there is no way to mathematically express the voltage drop of a LED.

There is a mathematical method but VF varies from LED to LED so we don't use that. We control the current instead.

So i came up with a circuit that is shown above.

There are a few problems with your circuit.

There is no current limiting for the LED. If the transistor turns on more than expected due to a difference in gain, etc., the current through the LED may destroy it. Nobody does it this way.

So far the transistor works as a current limiter, it limits current to lets say 20 mA perfectly no matter what LED Vd is. it is always going to be the desired current.

No. The current gain will vary from transistor to transistor and will vary with temperature.

Why i need such a precision ? i am trying to make LED that displays a color. RGB value. so for example 0.00007843137 amps is Red = 1 and 0.00015686274 amps is Red 2 (8 bit colors).

Using seven significant digits is just silly. With standard 1% tolerance components you won't get anywhere close to such precision. You are working with 8-bit control and you will hardly notice the change in intensity for each step.

My question is how to precisely express this Voltage drops in a transistor or LED in order to manipulate such a small current.

You can use a programmable constant current source such as that shown by Andy aka or use PWM. The big advantage with PWM is that the LED is either fully on or fully off. You don't need any analog circuitry and variations in LED Vf are taken care of by the fixed series current limiting resistor.

so i am driving an LED with PWM wave and lets say at a given time i need 18.037289 mA.

Let's use sensible numbers. You are looking for 18.0 mA.

... which is straight forward ohms law isnt it ? well i am afraid thats the point i will not be able to apply any kind of ohms law.

You use Ohm's law to calculate the series resistor required for the 'on' current. So, for a 5 V supply, 0.2 V drop across the transistor and a Vf of 2.2 V at 20 mA we calculate

$$R = \frac {V}{I} = \frac {5 - 0.2 - 2.2}{0.02} = 130 \ \Omega$$ simulate this circuit – Schematic created using CircuitLab

Figure 2. For a low-current LED a buffer can be used (a) or direct GPIO connection (b). Either allows full 0 to 100% dimming by PWM.

... so it doesnt matter if i use PWM or not.

Incorrect. With the above setup you get 20 mA at 100% PWM and if you want 5 mA average current then you use 25% PWM.

So another method is to controll current. thats what i am doing with this transistor with 16.5k ohm resistor attached to it. and a 5V P W M input.

As explained previously this will give poor control. You are assuming an accurate and stable current gain and this is unrealistic.

• Use PWM. so lets say i am using PWM, which is obvious but lets assume it. so i am driving an LED with PWM wave and lets say at a given time i need 18.037289 mA. which is straight forward ohms law isnt it ? well i am afraid thats the point i will not be able to apply any kind of ohms law. so it doesnt matter if i use PWM or not. So another method is to controll current. thats what i am doing with this transistor with 16.5k ohm resistor attached to it. and a 5V P W M input. – Anton Stafeyev Nov 10 '18 at 10:26
• See the update. – Transistor Nov 10 '18 at 10:42
• i think you dont get the point. if i want 18mA i will need to look at leds datasheet and see what its Vfd first before making any calculations. and for each 1,2,3,4,5,6,7,8,9 mA i i will need to do the same. i can not assume that Vfd will remain constant for a range of currents. from 0 to 20mA. and it can be a big difference, same goes for a transistor. and i was talking abouit Vbe not Vce.but same applies to Vce – Anton Stafeyev Nov 10 '18 at 10:47
• No. With PWM you calculate current and series resistor for your 100% value only. Read my update again. You calculate for 20 mA and to give an average current of 18 mA you switch on full 20 mA for 90% of the time. The $V_{f}$ remains constant. The transistor is driven hard into saturation to get minimum $V_{CE}$ and it remains very constant. This is all standard practice. – Transistor Nov 10 '18 at 10:55
• right.... cool that solves the problem then. – Anton Stafeyev Nov 10 '18 at 10:58

An interesting problem and I don't see any of the answers providing you with much of the help you may need for implementation.

Firstly let's assume that the solution you need can use PWM to set the light output of the three LEDs in a linear fashion. I'll also assume that you are creating a small point source element since the current is so low (perhaps an optical medical application?). So I'll proceed from there.

You need:

1. A calibratable current drive is required for the LEDs. You don't need to be concerned with the value of 1 bit, and here you specified 0.00007843137A or 78.43137uA as the value (it is practically impossible to achieve this current or current step resolution with any analog or D/A solution). However the full scale value, in your case 255 * 0.00007843137 = 0.019999905 or approximately 2mA, this is a much better value to deal with in the design. Remember that you will have difficulties getting super accurate current flow based on fixed resistors, but you can calibrate an adjustable driver.
2. The light output of each individual LED will vary due to manufacturing tolerances, and temperature, so there will not be an absolute current value you could specify for each LED. If you are able to have each LED adjustable around the 2mA target point in #1 then you could set the white value at the highest current (in each LED), and then use a PWM top achieve lower values. This of course assumes that your target sensors for this white value is either the human eye or some sensor with integration that will not 'see' the PWM rate flashes. I've assumed below that you will be using an LED such as this KingBright APTF1616LSEEZGKQBKC which has an exceptionally linear current to luminosity curve for the individual LEDs.
3. Assuming #1 and #2 are met, then your PWM would only need to be capable of 8bit resolution. This is easily achievable with most small MCUs at up to several kHz frame rate, but at very small PWM widths you may run into linearity problems with your LEDs. You may have to accepts a limited range based on the current to light output capability of your LEDs. You should however be able to achieve at least 90-95% linear range IMO.

The design therefore simplifies to a full scale (approx. 2mA) CC driver that is adjustable and stable around a target current. For example it might be possible to achieve your results with a CC driver adjustable from 1.75 - 2.25 mA for each of the LEDs. You'd have to test this based on the LEDs you use and the RGB current ratios needed to achieve White of course.

I'd suggest a schematic such as this below may suit your needs: simulate this circuit – Schematic created using CircuitLab

Note that I used an SCR symbol for the ATL431.

You could use either an ATL431 or a TL431. The ATL431 has slightly better stability, and much lower turn on current and ref current so it is a better choice.