#### Equip your Genius

Welcome to the Parallax Discussion Forums, sign-up to participate.

# How to calculate the transistor base resistor value to switch a load

Posts: 2,332
edited July 2012
I have a 12V LED strip that draws 120mA and I want to control it with a BS2 and a NPN transistor (e.g. 2N2222)

How do you calculate the value for the resistor between the transistor base and the BS2 pin?

The load will be connected between the collector and +12V and the emitter will be connected to GND.

I know that since it is not an inductive load, I will not need a diode.

Also, I am not sure what the minimum hFE is from the 2N2222 spec sheet...

## Comments

• 30 Comments sorted by Date Added Votes
• Posts: 20,602
edited July 2012
The minimum current gain for a PN2222 driving a 150mA is around 100. So the base current in your case has to be at least 120mA/100 = 1.2mA. You're not going to be operating it in its linear region, though, but in saturation. So, in order to keep VCE(sat) as low as possible, you should drive the base a lot harder than that, say, at 15mA. For a BS2, that would equate to a 270-ohm base resistor: (5 - 0.7)/.015 == 286.

-Phil
Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away.

-Antoine de Saint-Exupery

We had many discussions at the galley table and there had been many honest attempts to understand each other's thinking. There are several kinds of reception possible. There is the mind which lies in wait with traps for flaws, so set that it may miss, though not grasping it, a soundness. There is a second which is not reception at all, but blind flight because of laziness, or because some pattern is disturbed by the processes of the discussion. The best reception of all is that which is easy and relaxed, which says in effect, "Let me absorb this thing. Let me try to understand it without private barriers. When I have understood what you are saying, only then will I subject it to my own scrutiny and my own criticism."  This is the finest of all critical approaches and the rarest.

The smallest and meanest of all is that which, being frightened or outraged by thinking outside or beyond its pattern, revenges itself senselessly; leaps on a misspelled word or a mispronunciation, drags tricky definition in by the scruff of the neck, and, ranging like a small unpleasant dog, rags and tears the structure to shreds.

-John Steinbeck, The Log from the Sea of Cortez
• Posts: 2,332
edited July 2012
The minimum current gain for a PN2222 driving a 150mA is around 100. So the base current in your case has to be at least 120mA/100 = 1.2mA. You're not going to be operating it in its linear region, though, but in saturation. So, in order to keep VCE(sat) as low as possible, you should drive the base a lot harder than that, say, at 15mA. For a BS2, that would equate to a 270-ohm base resistor: (5 - 0.7)/.015 == 286.

-Phil

Thanks Phil, but where does the 0.7v constant come from?

- Ron
• Posts: 20,602
edited July 2012
0.7V is the base-emitter voltage.

-Phil
Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away.

-Antoine de Saint-Exupery

We had many discussions at the galley table and there had been many honest attempts to understand each other's thinking. There are several kinds of reception possible. There is the mind which lies in wait with traps for flaws, so set that it may miss, though not grasping it, a soundness. There is a second which is not reception at all, but blind flight because of laziness, or because some pattern is disturbed by the processes of the discussion. The best reception of all is that which is easy and relaxed, which says in effect, "Let me absorb this thing. Let me try to understand it without private barriers. When I have understood what you are saying, only then will I subject it to my own scrutiny and my own criticism."  This is the finest of all critical approaches and the rarest.

The smallest and meanest of all is that which, being frightened or outraged by thinking outside or beyond its pattern, revenges itself senselessly; leaps on a misspelled word or a mispronunciation, drags tricky definition in by the scruff of the neck, and, ranging like a small unpleasant dog, rags and tears the structure to shreds.

-John Steinbeck, The Log from the Sea of Cortez
• Posts: 2,332
edited July 2012
Works great!
Before I got your first reply, I was trying different values. It worked with a 1k resistor but I'm sure it wasn't enough to reach the saturation point. It was only drawing 4mA.

Thanks again.
• Posts: 17,244
edited July 2012
With GP 2N2222-ish switching transistors, I always grab the first 220 or 330 ohm resistor I find. Conveniently, BS2 HW boards have 220 ohm resistors on all the IO pins, and that's close enough for me. No additional resistor necessary.
“Simplicity is the ultimate form of sophistication.”

-Leonardo da Vinci
• Posts: 12,537
edited July 2012
Okay, I am now wondering more about saturation. Do we really need it or not?

My preference is to drive the transistor with LESS current in order to run the microcontroller with less stress - lets say that generally means 2-5ma per pin.

But youall are insisting on driving the transistor to saturation (which in theory makes the Rce close to 0 ohms. I presume the idea is that the transistor runs cooler and less overall energy is wasted.

This tends to point back to using Darlington pairs to have the best of both worlds, rather than taxing the micro-controller. Or of course, going over to MOSfets.
Hwang Xian Shen, Puddleby-on-the-Marsh.
All things considered, I can live and thrive without Microsoft products. LINUX is just fine.
• Posts: 1,330
edited July 2012
@Phil Pilgrim. What is Vce(sat)? 15mA / 1.2mA = 12.5! That's a big difference.
I use a 12V lead acid battery to power my motors and I would think a large base resistor would keep things cooler.
Larry

If the grass is greener on the other side...it's time to water your lawn.
• Posts: 2,554
edited July 2012
There is currently a very similar discussion going on at eevblog.com

http://www.eevblog.com/forum/beginners/transistor-calculations/
- Rick
• Posts: 414
edited July 2012
I have a 12V LED strip that draws 120mA and I want to control it with a BS2 and a NPN transistor (e.g. 2N2222)

How do you calculate the value for the resistor between the transistor base and the BS2 pin?

The load will be connected between the collector and +12V and the emitter will be connected to GND.

I know that since it is not an inductive load, I will not need a diode.

Also, I am not sure what the minimum hFE is from the 2N2222 spec sheet...

Did you need a current limiting resistor to drive the LED strip, to me this is more important than turning "on" a transistor. Almost any resistor at the base of the transistor would be fine as long as a current limiting resistor is installed in series with the 12V LED strip. In fact you don't even need a resistor at the base of the transistor to be using it as a switch - not the best idea, but proves a point.

Also a LED strip cant be an inductive load - unless you are entering the world of calculus and want to know the inductance of the LED strip.
[h=2]I would love to change the world, but they won't give me the source code![/h]
• Posts: 22,342
edited July 2012
You need to limit the current both at the collector and at the base. Most likely the 12V LED strip has its own current limiter since (I assume) it's supposed to be able to be connected directly to a 12V power supply. The base of the transistor needs a current limiting resistor since the base-emitter junction appears mostly like a (forward biased) diode which will conduct any amount of current available once the voltage goes over about 0.7V. I believe a BS2 I/O pin can supply about 25mA and more than that starts to cause thermal stress and other problems if continued. A 2N2222's base can pull way more than that if you don't limit the current with a base resistor.
• Posts: 414
edited July 2012
I respectfully disagree with you and here is why.

If the LED strip has a current limiting resistor then the base resistor of the transistor is not important. Fully saturated or not the current is limited with the LED strip resistor.
[h=2]I would love to change the world, but they won't give me the source code![/h]
• Posts: 22,342
edited July 2012
The problem really has little to do with the LED strip and would exist even if the 2N2222 collector were not connected. It has to do with the Stamp output driving essentially a silicon diode that can easily draw over 50mA once the forward voltage (0.7V) is passed. The Stamp (PIC) I/O pin output structures are rated for an absolute maximum current of 25mA. They don't specify what will happen if you draw more than that, but there's a variety of damage that will occur. It's possible to design I/O pin output structures that can self-limit output current and survive a short circuit indefinitely. The Propeller's I/O pin circuitry is one example of that, but the PIC used in the BS2 doesn't do it. If you short-circuit a Stamp I/O output pin for any length of time (seconds), it will be damaged.
• Posts: 12,537
edited July 2012
@Phil
I just cannot seem to see a good reason to drive at 25ma. Am I not understanding something?
Even 15ma is better if saturation is an optimal condition.

@Bits
I see your point of view -- but without any resistor on the base, a thoughtless reconfiguration or a short circuit might damage the micro-controller. By always having 240ohms or more, the micro-controller's individual pin is protected regardless of what happens.

~~~~~~~~~~~~~~~~
I DO indeed understand that the BasicStamp can tolerate 25ma on an individual pin, but if all the pins are in use that would not work as the Port of 8 pins would likely be overloaded (8x25ma=200ma) and it gets even more bizarre with claiming 40ma is reasonable for the Propeller.

So I am trying to determine if driving to saturation is really worthwhile. I believe the 2N2222 has a gain of about hfe =100 in this context. So 3ma X 100hfe = 300ma, but not saturated. Lets say we go to 5ma to drive a bit over 5v/.005a = 1000ohms.
Hwang Xian Shen, Puddleby-on-the-Marsh.
All things considered, I can live and thrive without Microsoft products. LINUX is just fine.
• Posts: 22,342
edited July 2012
Saturation is the condition where Vce is at a minimum and any further increases in base current would have no effect. The transistor's power dissipation is mostly determined by Vce and Ic. If you're happy with the voltage drop across the transistor and the power dissipation is easily handled, there's no need to drive the transistor into saturation. For switching, it's the most efficient to just barely drive the transistor into saturation. There's less heating of the transistor and you get the widest voltage swings on the output.
• Posts: 12,537
edited July 2012
[QUOTE=There's less heating of the transistor and you get the widest voltage swings on the output.[/QUOTE]

That is what I was wanting to know. The 2n2222 pdf has 150ma at 30V saturated by being driven at 15ma. SEE Switching characteristics.
Hwang Xian Shen, Puddleby-on-the-Marsh.
All things considered, I can live and thrive without Microsoft products. LINUX is just fine.
• Posts: 20,602
edited July 2012
Bits,

You're partially right about omitting the base resistor. Consider the following three circuits:

In circuit A, the base current is limited by the same resistor that limits the emitter current, and by the gain of the transistor. The current through the resistor is:
IC = (VB - 0.7) / R

But most of that is collector current, due to the transistor's gain. The portion allocated to the base is approximately:
IB ~ (VB - 0.7) / (R * hFE)

Incidentally, this is a good circuit to use if you want to control the load current without using an LM317 or transistor/op-amp combo. It's not as accurate, though.

In circuit B (an emitter follower), the same principle applies, except that the base current is further limited by the resistance of the load.

In circuit X (the circuit this thread concerns -- a common emitter configuration), there is nothing in either the base circuit or emitter circuit to limit the base current (i.e. the resistor is no longer in the base-current path). If the base voltage is above 0.7V, the base current is essentially infinite -- or whatever the base driver is able to force through it. This will damage either the transistor, the driver, or both. That's why you need a resistor in the base circuit to limit the base current in this configuration.

-Phil
Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away.

-Antoine de Saint-Exupery

We had many discussions at the galley table and there had been many honest attempts to understand each other's thinking. There are several kinds of reception possible. There is the mind which lies in wait with traps for flaws, so set that it may miss, though not grasping it, a soundness. There is a second which is not reception at all, but blind flight because of laziness, or because some pattern is disturbed by the processes of the discussion. The best reception of all is that which is easy and relaxed, which says in effect, "Let me absorb this thing. Let me try to understand it without private barriers. When I have understood what you are saying, only then will I subject it to my own scrutiny and my own criticism."  This is the finest of all critical approaches and the rarest.

The smallest and meanest of all is that which, being frightened or outraged by thinking outside or beyond its pattern, revenges itself senselessly; leaps on a misspelled word or a mispronunciation, drags tricky definition in by the scruff of the neck, and, ranging like a small unpleasant dog, rags and tears the structure to shreds.

-John Steinbeck, The Log from the Sea of Cortez
• Posts: 2,332
edited July 2012
The LED strip was designed to be powered directly from a 12V source - it has 18 blue LEDs and several resistors along it's length.

It did seem to work fine when I used a 1k ohm resistor - the 2n2222 did not get warm and was only drawing 4mA from the BS2.

@Phil,

Thanks for the previous post - it helps to better understand the various circuit configurations.
• Posts: 1,330
edited July 2012
@Mike Green. Thanks for the explanation of Vce. It'll help me design a better circuit next time.
My steppers got very warm even though I ran them at the rated 12V. I used an 8Ω ceramic resistor which works fine but I think there is a better way.
Larry

If the grass is greener on the other side...it's time to water your lawn.
• Posts: 5,909
edited July 2012
A bipolar transistor officially enters saturation at the point where its collector-emitter voltage drops below the base-emitter voltage. It is not a sharp transition. The gain of the transistor falls steadily as it approaches and enters saturation. The gain of a bipolar transistor is not well-controlled in manufacturing. So if you go through a handful of 2N2222s, you will find a few that require much less base current to be fully saturated, and also a few that have to be pushed really hard. For a one-off, you at liberty to select the best one.

A nice alternative to the 2N2222 (if you are not going to use a mosfet) is a ZTX1049. It's gain is much higher, typically x400, and it saturates down to less than 50mV with 10mA of base current and 0.5A of collector current. Margin of safety. It is in a thermally enhanced TO92 package that lets it take pulses of current up to 4A.

You can also get a high current gain with a darlington connection. That takes 1 or 2 mA of base current from the Stamp or Prop. The saturation voltage of a Darlington is around 0.7V.
• Posts: 414
edited July 2012
Ah ha! I got it. Thanks Mike and Phil - I was not clear enough on the circuit and should have keep my big mouth shut. Well done.
[h=2]I would love to change the world, but they won't give me the source code![/h]
• Posts: 2,332
edited July 2012
I measured the base current and LED strip current using 270 vs 1k ohm resistors.

[TABLE="width: 250"]
[TR]
[TD]1k[/TD]
[TD]4.1 mA[/TD]
[TD]116.5 mA[/TD]
[/TR]
[TR]
[TD]270[/TD]
[TD]14.5 mA[/TD]
[TD]117.5 mA[/TD]
[/TR]
[/TABLE]

Using the 1k did reduce the LED strip current slightly but dropped the base current by 10 mA.

That could really help limiting the load on a BS2 pin bank...
• Posts: 1,539
edited July 2012
With high current switching you desire saturation to reduce the dissipation in the transistor - this allows a smaller transistor, smaller heatsink, no heatsink, etc. For instance the newer superbeta transistors make excellent switches as they can achieve saturation voltages of less than 0.1V or so under reasonalby high currents.

Many older circuits that used darlingtons on heatsinks to get enough current gain can be replaced by a much smaller modern device such as a superbeta switching transistor or a MOSFET. The ZTX1049 is a nice example there, and my favorite is the ZTX851, 5A contin, 20A peak, 50mV at 1A, all in a tiny e-line package... And unlike power MOSFETs you don't have to worry about being logic-level!
• Posts: 12,537
edited July 2012
@Phil
Thanks, now that I see the drawings, placing the resistor does certainly seem an issue on restricting current to the base

And for the power hungry,

Here is a nice TO-92 packaged Darlington to go beyond the 2n2222

NPN 2N5308 hfe = 7000 to 20000

Not sure about a PNP mate

Power output is about 50% higher than the 2n2222 , but using in similar power situations these will bring the micro-controller into being able to drive power on lots of pins at the same time.

One could go to the TIP120 and TIP125, but those T0-220 packages are too big - even without heat sinks.

The idea here is to use saturation to gain speed and not to heat the package until it glows.

@Tracy Allen
I always am at a loss to the fact that transistors just don't fall in line with the specification parameters. But you are right, they are sloppy little devils and I hope these Darlingtons will offer some head room for people that want to have a design where EVERYTHING runs cool.
Hwang Xian Shen, Puddleby-on-the-Marsh.
All things considered, I can live and thrive without Microsoft products. LINUX is just fine.
• Posts: 1,539
edited July 2012
I measured the base current and LED strip current using 270 vs 1k ohm resistors.

[TABLE="width: 250"]
[TR]
[TD]1k[/TD]
[TD]4.1 mA[/TD]
[TD]116.5 mA[/TD]
[/TR]
[TR]
[TD]270[/TD]
[TD]14.5 mA[/TD]
[TD]117.5 mA[/TD]
[/TR]
[/TABLE]

Using the 1k did reduce the LED strip current slightly but dropped the base current by 10 mA.

That could really help limiting the load on a BS2 pin bank...

I've just realized there are two ways to optimize the choice of base current: you can choose the base drive where further increases in base current cause a smaller increase in collector current (dynamic gain below 1). Driving any harder is "throwing good money after bad" perhaps.

You could also (and more logically) choose the base current where the total losses in the base resistor and the transistor are a minimum. You need the graph of saturation voltage against collector and base currents for that. By minimum I mean the local minimum when the transistor is on (the true minimum is with it switched off of course).
• Posts: 17,244
edited July 2012
kraj8995 wrote: »
While transistors have many uses, one of the less known uses by amateurs is the ability for bipolar transistors to turn things on and off. While there are limitations as to what we can switch on and off, transistor switches offer lower cost and substantial reliability over conventional mechanical relays.

What if I use a transistor to turn on a relay? :)
“Simplicity is the ultimate form of sophistication.”

-Leonardo da Vinci
• Posts: 12,537
edited July 2012
I suppose we are getting close to the day when MOSfets will actually replace mechanical relays, but I am not sure we are quite there.

Transistors and MOSfets generally switch DC in power switching.

Relays are quite handy for 120VAC and 240VAC at 12amps or more. Relays may be noisy and may create voltage spikes, but they can provide complex switching logic with DPDT or other mechanical configurations. For example -- One DPDT relay can work as the equivalent of an H-bridge.

Power transistors just get too hot and may actually have thermal runaway. Relays are generally running cool - no heat sinks required. This may be an excellent reason for use on a vehicle or in a robot.

And yes, I would use a transistor to turn on a relay.

I posted a Darlington in a TO-92 as an alternative to a Beta-transistor. Even at saturation, the Darlington will still have a .7V drop across CE due to the pair. It really isn't that great if you are switching 5-6volts. A saturated Beta-transistor might be better. The main point is that we all have to deal with what is available and what is absurdly costly. There is no one right answer.

In many contexts, a micro-controller may actually do very little power switching, but a lot of communications and sensing. In such situations, relays are a very good alternative and there are a lot of high amperage 12VDC relays that were created for the automotive industry that have proven durability in hostel environments with extreme temperature ranges. Why bother building something that is elegant, but not robust?
Hwang Xian Shen, Puddleby-on-the-Marsh.
All things considered, I can live and thrive without Microsoft products. LINUX is just fine.
• Posts: 20,602
edited July 2012
Relays arc, causing contact pitting, and eventually wear out. There are very robust, fault-proof, high-side semiconductor drivers available to the auto industry that eliminate the problems cause by relays. As to AC, triacs are an obvious replacement.

-Phil
Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away.

-Antoine de Saint-Exupery

We had many discussions at the galley table and there had been many honest attempts to understand each other's thinking. There are several kinds of reception possible. There is the mind which lies in wait with traps for flaws, so set that it may miss, though not grasping it, a soundness. There is a second which is not reception at all, but blind flight because of laziness, or because some pattern is disturbed by the processes of the discussion. The best reception of all is that which is easy and relaxed, which says in effect, "Let me absorb this thing. Let me try to understand it without private barriers. When I have understood what you are saying, only then will I subject it to my own scrutiny and my own criticism."  This is the finest of all critical approaches and the rarest.

The smallest and meanest of all is that which, being frightened or outraged by thinking outside or beyond its pattern, revenges itself senselessly; leaps on a misspelled word or a mispronunciation, drags tricky definition in by the scruff of the neck, and, ranging like a small unpleasant dog, rags and tears the structure to shreds.

-John Steinbeck, The Log from the Sea of Cortez
• Posts: 12,537
edited July 2012
Everything wears out, the advantages are in how and which is most useful before doing so.

I believe that triacs have difficulties with inductive loads. Am I correct?

Admittedly, solid-state just keeps getting better and better - but when you are trying to handle 30amps of 240AC, the heat sink for a solid-state relay is rather large and the mechanical relay is relatively small.

Also, pitting in relays is more of a problem with DC as all the metal migrates in only one direction. With AC, the metal actually travels back and forth and with good engineering seems to last quite long.

And I personally have yet to see a solid-state replacement for a starter solenoid. Do they really make such beasts? They need to switch 80 or more amps.
Hwang Xian Shen, Puddleby-on-the-Marsh.
All things considered, I can live and thrive without Microsoft products. LINUX is just fine.
• Banned Posts: 5,065
edited July 2012
I believe that triacs have difficulties with inductive loads. Am I correct?

No.
A snubber is required across the TRIAC (MT1 to MT2), unless it's a "snubberless" TRIAC.
Sign In or Register to comment.