base resistor of pnp transistor

Thread Starter

skk

Joined Mar 15, 2011
31
I have an 8 LED driving circuit using a pnp transistor. I stole the design from somewhere, and I don't know what value to use for the base resistor, or even how to figure it out.

I tried to draw it in text but it didn't work out. Let me explain the circuit:

VCC ( 5v ) is connected to the emitter of the PNP transistor. The collector of the PNP is connected to the annodes of the 8 LEDs. The cathodes of the 8 LEDs are connected to the 8 row drive pins of the microcontroller. The base of the transistor is connected to another microcontroller pin via a base reistor.

Both row and column pins are active low.

How do I come up with a good value for the base resistor?





I never did understand transistors, how do I come up with the base resistor value? Is there anything else missing here, or a way to make the circuit better?
 
Last edited:

SgtWookie

Joined Jul 17, 2007
22,230
You didn't include the CODE blocks, so your schematic got all scrunched up to the left. I added them:
Rich (BB code):
              +/\/\/\/\-|>|--- micro controller pin 7
              |    ......................
vcc --\     /-+/\/\/\/\-|>|--- micro controller pin 0
       v   /
       -----
         |
         ------/\/\/\/\----- micro controller pin for the row
I also added current limiting resistors for the LEDs, because each will need one.
Use:
R >= ( Vsupply - LED_ForwardVoltage ) / DesiredCurrent
to calculate the LED current limiting resistors.

Basically (sic) Rbase ~= (Vcc - Vbe) / (Ic / 10)
Your Vcc needs to be the same as your uC's Vcc; if it's higher, you won't be able to turn the PNP transistor off.

So, if you have two LEDs in parallel that need 20mA current each, that is a total of 40mA collector current (Ic), and your base current will need to be 1/10th that much, or 4mA.

Vcc = 5v
Vbe is usually around 0.7v.
So, substituting:
Rbase ~= (Vcc - Vbe) / (Ic / 10)
Rbase ~= (5v - 0.7v) / (40mA / 10)
Rbase ~= 4.3 / 0.004
Rbase ~= 1,075 Ohms. You could use either 1.1k or 1k Ohms.

Keep in mind that for a single (non-Darlington) transistor, you need 1/10th of the collector current for the base current. Since most uC's are limited to ~20mA per I/O pin, the most collector current you should plan on is 200mA; in the case of LEDs that need 20mA, you could have up to 10 in parallel.

For a 200mA load, you could calculate:
Rbase ~= 4.3 / 0.02 = 215 Ohms. 220 Ohms is the closest standard value.

You can use 2N2907 transistors; they are common and inexpensive; good for up to about 500mA collector current as a practical limit, 2N3906 transistors are limited to around 100mA as a practical limit.

Also keep in mind that uC's have a package limit for current; some might be pretty low. You will need to read the electrical specifications table for your particular uC. If you exceed either the I/O pin limits or the total package limits, you may damage the uC permanently.
 

Thread Starter

skk

Joined Mar 15, 2011
31
Reading over your reply again I suspect there may be a problem with my design. I want to be able to turn on any number of the 8 LEDs together. They are all in parallel, so if I just turn on 1, it will have 8 times less current than if I have all 8 on. What can I do to work this problem?
 

SgtWookie

Joined Jul 17, 2007
22,230
If you have 8 LEDs in parallel, and you want 20mA current through each when it is selected, then you will need a maximum of 8 x 20 = 160mA collector current, so 16mA base current, which will require a (4.3/0.016) = 268.75 (use a 270) Ohm resistor on the base.

This will allow for any or all of the 8 LEDs to be on.

You will need to calculate the current limiting resistors for each LED as I showed above:
I also added current limiting resistors for the LEDs, because each will need one.
Use:
R >= ( Vsupply - LED_ForwardVoltage ) / DesiredCurrent
to calculate the LED current limiting resistors.
[eta]
Remember, you must check to make certain that your uC will support the total current sink required for that circuit; at 20mA per LED and 16mA for the base, that's 8 x 20mA + 16mA = 176mA sink current, which is a lot; that's beyond the capability of many microcontrollers.

You may need to either reduce the current for each LED by increasing the current limiting resistors, or use transistors or logic-level MOSFETs to sink the current from the LED cathodes. The 2N7000 MOSFET would be a good choice; they are pretty inexpensive, have a Vdss rating of 60v, and will sink up to 200mA current - and come in a TO-92 plastic package. They have an Rds(on) of ~6 Ohms when Vgs (voltage on the gate relative to the source terminal) is 4.5v.
 
Last edited:

dikraji

Joined Feb 13, 2023
1
You didn't include the CODE blocks, so your schematic got all scrunched up to the left. I added them:
Rich (BB code):
              +/\/\/\/\-|>|--- micro controller pin 7
              |    ......................
vcc --\     /-+/\/\/\/\-|>|--- micro controller pin 0
       v   /
       -----
         |
         ------/\/\/\/\----- micro controller pin for the row
I also added current limiting resistors for the LEDs, because each will need one.
Use:
R >= ( Vsupply - LED_ForwardVoltage ) / DesiredCurrent
to calculate the LED current limiting resistors.

Basically (sic) Rbase ~= (Vcc - Vbe) / (Ic / 10)
Your Vcc needs to be the same as your uC's Vcc; if it's higher, you won't be able to turn the PNP transistor off.

So, if you have two LEDs in parallel that need 20mA current each, that is a total of 40mA collector current (Ic), and your base current will need to be 1/10th that much, or 4mA.

Vcc = 5v
Vbe is usually around 0.7v.
So, substituting:
Rbase ~= (Vcc - Vbe) / (Ic / 10)
Rbase ~= (5v - 0.7v) / (40mA / 10)
Rbase ~= 4.3 / 0.004
Rbase ~= 1,075 Ohms. You could use either 1.1k or 1k Ohms.

Keep in mind that for a single (non-Darlington) transistor, you need 1/10th of the collector current for the base current. Since most uC's are limited to ~20mA per I/O pin, the most collector current you should plan on is 200mA; in the case of LEDs that need 20mA, you could have up to 10 in parallel.

For a 200mA load, you could calculate:
Rbase ~= 4.3 / 0.02 = 215 Ohms. 220 Ohms is the closest standard value.

You can use 2N2907 transistors; they are common and inexpensive; good for up to about 500mA collector current as a practical limit, 2N3906 transistors are limited to around 100mA as a practical limit.

Also keep in mind that uC's have a package limit for current; some might be pretty low. You will need to read the electrical specifications table for your particular uC. If you exceed either the I/O pin limits or the total package limits, you may damage the uC permanently.


Hi I know this is an old post . But i cant help myself not correct it. Your calculation and math is correct there is only one thing wrong. All (ok 99%) transistors have a MINIMUM Hfe of 100 AND NOT 10 as stated by you. In fact, if you see the datasheet of the 2n2907 that you have suggested you will see the minimum Hfe is 100 and max is around 300. So by taking an Hfe of 10 you are unnecessarily pushing more current in the base that necessary. Thereby uncessarily wasting precious current capability from the uC in this case. Dont get me wrong what you did will work but it is just a waste. Especially while using something like a uC which has limited current capabilities.

Oh for those of you who dont know what hfe is . It is the dc gain of a transistor. That is it is the ratio of collector current to base current. So if you have a collector current of 200mA then the base current is nothing but the collector current divided by Hfe. Now the hfe of a transistor varies and depends on many conditions. So the best thing is to assume the minimum value (100) . This would ensure that you are always having sufficient base current to saturate the transistor. So for our case (with Ic=200mA) that requires a base current of only 2mA (NOT 20mA as given above) . If you want your actual value of hfe you have to look at the datasheet and the will be a graph the shows the variation of Hfe with other parameters from there you can get the actual hfe for your condition. Though i have always found that doing that is a bit difficult and the graphs do have a error. So by assuming the minimum you are safe and you will always drive the transistor into saturation no matter what.

So yeah if you have a uC that can sink/source 20mA max , you can have a collector current of atleast 2A (Hfe of 100). That is much more that the 2n2907 can handle.

So for the above calculation

Vcc = 5v
Vbe is usually around 0.7v.
So, substituting:
Rbase ~= (Vcc - Vbe) / (Ic / 100)
Rbase ~= (5v - 0.7v) / (40mA / 100)
Rbase ~= 4.3 / 0.0004
Rbase ~= 10,750 Ohms.

Now for this case 10750 ohms is the max resistance you want. So choose a standard value of resistance that is slightly lower. In this case 10 K is a standard value. So with 10k you will have a base current of 4.3/10k or 430 microAmps. This is about 7.5% more than the 400 microAmps. Now remember this is with the assumption of minimum hfe. In your circuit there might be a chance that the actual hfe is say 200 (for example). So then your margin would be higher as the actual required base current would be much lower (only 200 micro A).

For a 200mA load, you could calculate:
Rbase ~= 4.3 / 0.002 = 2150 Ohms. 2K Ohms is the closest standard value that is lower than 2150 ohms.

Off course there are some people out there would talk about temperature variations and the fact that resistors have a tolerance and so your 2k resistor might be a 2.1k etc. So they recommend having a margin of atleast 20%. Though i think that while they are correct the fact that the hfe will almost always be more than 100 kind of compensates this. Anyway if you want the 20% margin then all you have to do is divide the resistance (10,750 or 2150 ) by 1.2 . Then just go to a website like the one below and see what is a standard value that is below the resistance you calculated.

So for our case the resistance would be 8958.33 ohms (so 8.2K is the next lower E24 standard value) and 1791.66 Ohms ( 1.6K ohms is the next lower E24 standard value)

Note most commonly available resistors are the E24 series. So choose a value from there. If you have a specialist store and they keeps E96 resistors then that would be the best as they have a very low tolerance .

https://www.electronics-notes.com/a...tor-values-e-series-e3-e6-e12-e24-e48-e96.php
 

crutschow

Joined Mar 14, 2008
34,428
Your calculation and math is correct there is only one thing wrong. All (ok 99%) transistors have a MINIMUM Hfe of 100 AND NOT 10 as stated by you.
Welcome to this forum, but No.
Unfortunately you are the one with this commonly incorrect idea.

The minimum Hfe is for operation in the linear region as it is specified at some significant Vce voltage, not the saturation volage.
For the 2N2907 it's 10V (below):
So to be sure the transistor is completely ON and saturated, you should to use a base current 1/10th of the maximum collector current.

1676310680144.png

Now note that saturation voltage is specified at an Hfe of 10 (below):

1676310897342.png

You are new to this forum and we do welcome all posters, but before you say someone else is wrong here, please do "help yourself" and be sure your information is correct. :rolleyes:
 

WBahn

Joined Mar 31, 2012
30,056
You are confusing the minimum hfe of the transistor under specific conditions when NOT saturated, with the hfe in saturation. These are not even close to the same thing.

Look at the the portion of the datasheet you (seem to be) pulling your information from:

1676310945596.png

That minimum hfe of 100 is when the junction is at room temperature AND the collector current is 150 mA AND the collector-emitter voltage is -10 V.

This circuit is operating from a 5 V supply, so it's not going to have anywhere near the -10 V for that specified minimum hfe to apply.

Also, look what happens to the minimum hfe if the collector current goes either up or down from that 150 mA. It drops significantly.

In order to properly set the LED current with a current limiting resistor, you need to have a good idea of what the transistor Vce is, that means pushing it firmly into saturation. You do NOT want it in the active region.

Referring to the datasheet:

1676311319204.png

You can see that the saturation voltage is specified at an hfe of 10. This has been the long-time industry standard for most small-signal transistors.

If the transistor is not in saturation, you have very little idea what the Vce is because it is now a function of an hfe that can vary all over the place, and thus you don't have a good idea what the voltage is across your current-setting transistor, and therefore don't have firm control of your LED current.
 
If you have 8 LEDs in parallel and want 20mA current through each when it is selected, you will need a maximum of 8 x 20 = 160mA collector current, which means a (4.3/0.016) = 268.75 (use a 270) Ohm resistor on the base.

This allows any or all of the eight LEDs to be turned on.


You must calculate the current limiting resistors for each LED as shown above:
I also added current limiting resistors for the LEDs, as each will require one.
To calculate the LED current limiting resistors, use: R >= (Vsupply - LED ForwardVoltage) / DesiredCurrent.
[eta]

Remember to double-check that your uC can handle the total current sink required for that circuit; at 20mA per LED and 16mA for the base, that's 8 x 20mA + 16mA = 176mA sink current, which is a lot; many microcontrollers can't handle that.

You may need to either increase the current limiting resistors for each LED or use transistors or logic-level MOSFETs to sink the current from the LED cathodes.The 2N7000 MOSFET is a good choice because it is relatively inexpensive, has a Vdss rating of 60v, and can sink up to 200mA current - all in a TO-92 plastic package. They have a Rds(on) of 6 Ohms when Vgs (voltage on the gate relative to ground) is applied.
 
Top