An LED driver is an electronic circuit that utilises a transistor to switch power to an LED. Usually, the signal from a microcontroller, or logic gate, does not possess sufficient drive current to power an LED directly. If the LED has a higher power requirement, then it is best to use an NPN transistor as a driver. A driver circuit is also very useful if you are experimenting with pulse-width modulation (PWM) techniques, where the goal is to control the brightness, to create a dimming and fading effects.
As a beginner, you may have already created a circuit using the Raspberry Pi or Arduino to blink an LED. For us Brits, it is a very big step to be able to make a blinking circuit; however, the next stage is to control its brightness to make a fading effect.
I was just recently experimenting PWM to control an LED. This is where power transfers to the LED through extremely fast switching action of the transistor, and was impressed with the performance of the old 2N2222 transistor. It was a general-purpose transistor in a TO-18 package, which looked like a metal can. I remember using it to drive LEDs and relays back when I was a whippersnapper.
The PN2222A, and P2N2222A come in a plastic TO-92 package and have an absolute maximum collector rating of 600 mA. Realistically though, I would not draw more than half an ampere, which is more than enough for switching high-power LEDs and small relay coils.
Note the differences in the pinouts between the P2N2222A, and PN2222A versions of this transistor. The pinouts are with respect to the flat side facing towards you.
If you have some power MOSFETs in your recycle box, then those are usually much better performing, however I am going to use widely available and cheap components so that everyone can follow. The P2N2222A is one of the cheapest, and I can get a bag of 10 for a pound on eBay, hence I shall be using those.
For the LED, I shall be using a high efficiency Kingbright LED that will operate on a current as little as 2 mA. The absolute maximum drive current it can accept is 30 mA, and it has a forward voltage of 1.7 V.
5 V TTL System
The common-emitter follower circuit consists of an NPN transistor, which drives an LED through a series resistor. You use this circuit when you want to drive an LED or relay that requires more current than the logic gate can provide.
Calculating the Series Resistance RL
In this circuit, I have decided to drive the LED with a current of 20 mA (0.02 A) because electricity is expensive these days.
Assuming the transistor conducts fully in saturation, there will be negligible resistance across its emitter-collector junctions, and therefore the voltage across the series resistor RL will be 3.3 V. This is very simple to deduce because the forward bias voltage of the LED is 1.7 V, and if the power supply voltage is 5 V, then there has to be 3.3 V across RL.
Since we now have the voltage across resistor RL, which is 3.3 V, and the current passing through it, which is 0.02 A, we can use Ohm’s Law to calculate the value of the resistor RL.
R = V / I
Therefore RL = 165 Ω, and it just so happens that you can get a resistor that is precisely that value.
Calculating the Base Resistance RB
To calculate the base resistance RB, we use the following standard formula.
RB = 0.2 × RL × hFE
Note that this is a standard textbook formula where the 0.2 is a constant that remains the same for all circuits. It is a shortcut formula, which enables you to calculate the base resistance without requiring much mathematics or any understanding of saturation curves. Its derivation is outside the scope of this article.
From the P2N2222A documentation, we select a suitable minimum current gain value (hFE) of the transistor as 100. We know that the load resistance RL is 165, therefore the following calculation should provide the value of the base resistor.
0.2 × 165 × 100 = 3300
Therefore, the value of the base resistor is 3300 Ω, and it just so happens that you can buy a resistor that is precisely 3.3 kΩ.
3.3 V CMOS System
The Raspberry Pi and Arduino are usually 3.3 V systems, which provide 3.3 V logic signals. Hence, the value of the current limiting series resistance, and base resistance, will be different. However, the steps to calculate them are the same as before.
I have chosen the drive current for the LED to be 20 mA (0.02 A). The forward bias voltage of the diode is 1.7 V, and the power supply is 3.3 V, therefore the voltage across the series resistor RL is 1.6 V. Using Ohm’s Law, the value of the series resistor RL is found to be 80 Ω. Hence, the closest resistor with a standard value of 82 Ω is good enough.
To calculate the base resistance RB, we use the same standard formula (1) shown above, and hFE is still 100. Therefore, the following calculation gives us the value of the base resistor.
0.2 × 82 × 100 = 1640
Therefore, the value of the base resistor is 1640 Ω, and it just so happens that you can buy a resistor that is 1.65 kΩ.
Keeping it Simple
These calculations are an approximation to keep everything simple. In practice, the transistor will exhibit a small voltage drop of around 0.2 V across its junctions, and there will be a small current leakage in the order of nano amperes. These factors are negligible and taken into consideration when designing high-end audio amplifier, however for blinking LEDs and driving relay coils it is good enough.
The components are on Google and easily found. They are usually at the top of the search listings.
- “25x 2N2222 P2N2222A NPN”
- “Farnell PN2222ATA”
- “NPN transistor, P2N2222A 0.6 A Ic 10Vce”
This Article Continues…
Driving LEDs by CMOS or TTL Outputs Driving an LED using a Transistor Current Sinking and Sourcing in TTL Circuits Current Limiting Series Resistance Calculator for LEDs