# Calculating base resistor value

I've looked around on the internet, but there's so much conflicting advice on how to find the value for the necessary resistor between the base of the transistor and the microcontroller. I'm completely at a loss at this point.

The microcontroller I'm using is a the huzzah ESP8266 breakout board from adafruit, and the transistors are TIP41C's.

Here's a schematic: • Could you point me to some of these conflicting information? – pipe Dec 31 '17 at 12:33
• What is the maximum current each transistor must be able to conduct? What is the logic high voltage coming out of the digital part? How much current can each digital output source? Is 12 V really the maximum the transistors must switch? Especially if this LED strip current is reasonably high, why not the more obvious solution of using N channel MOSFETs instead of NPN transistors? – Olin Lathrop Dec 31 '17 at 13:15

First you have to determine what the maximum collector current is that the transistor needs to support when on.

Divide this collector current by the gain of the transistor to get the minimum required base current. The gain of a BJT varies with operating point, so you have to look at the datasheet carefully to see what gain value you can assume at your maximum collector current.

Once you know the minimum required base current, it's just a matter of Ohm's law to find the base resistance. The B-E junction of the transistor looks like a diode to the driving circuit. Figure it will drop around 700 mV when the base current is flowing. Subtract that from the logic high level to find the voltage across the base resistor. By Ohm's law, the resistance is the voltage divided by the current.

Remember that this calculation was based on the minimum required base current. That means the result is the maximum allowed base resistance. It's usually good to round down the resistance one or two standard values to leave some margin.

Now that you've picked a base resistance, work backwards to find the actual base current, and check to make sure the digital output can deliver that. If not, that transistor in that circuit won't work.

That all said, why not use a FET? It seems you only need to switch 12 V. It looks like the IRLML2502, for example, would work nicely here. Then you don't need a base resistor at all. The on-state voltage drop will also be lower.

• you still need a gate resistor though – Vinzent Dec 31 '17 at 13:17
• @Vin: No, you don't. In high speed switching applications a few Ohms of gate resistance is sometimes required. Any normal digital output simply doesn't have the drive capability to cause the problem a gate resistor would solve. – Olin Lathrop Dec 31 '17 at 13:20
• @Cas: First, a FET is a transistor. Second, read the datasheet instead of guessing. The IRLML2502 is specified for 80 mOhms Rdson at 2.5 V gate drive. It does better (45 mOhms) with 4.5 V gate drive, but 80 mOhms is good enough for many applications. At 1 A, it would only drop 80 mV and dissipate 80 mW. That's a lot better than any BJT can do. – Olin Lathrop Dec 31 '17 at 13:27
• @Cas: A FET (field effect transistor) is a transistor, but not all transistors are FETs. – Olin Lathrop Dec 31 '17 at 13:29
• At your low voltage of 12 V, there are a number of MOSFETs that can switch nicely driven from 0 to 3.3 V logic. Just because you selected a inappropriate FET doesn't mean all FETs are inappropriate. If the LED current is higher and you can tolerate 150 uA leakage, then the IRLML6344 is a even better choice. It is guaranteed not to exceed 37 mOhms with 2.5 V gate drive. – Olin Lathrop Dec 31 '17 at 13:33

An NPN transistor is a current amplifier, it allowes a current to flow between collector and emitter that is hFe times greater than the current flowing from base to emitter. this allowes you to controll the current through the collector by controlling the current that flows through the base.

If you want to use an NPN transistor as a current amplifier the base current Ib you need is the collecter current Ic divided by the hFe of the transistor found in the datasheet so

$$I_b=\frac{I_c}{h_{Fe}}$$

If the transistor is used as a current amplifier it will not be able to pull the voltage completely to ground, in order to do that you have to be in the regon of operation of the transistor where you are allowing enough current though relatively, to allow the transistor to switch completely ON. the way you do that is that you raise the base current by a factor of 5, so now the equation for using a bjt transistor as a switch becomes

$$I_b=\frac{5I_c}{h_{Fe}}$$

Now you know the base current needed if you know the current you need to switch on though the collector-emitter path.

now you can calculate the resistor needed if you know the supply voltage it is

$$R_b = \frac{V_{cc}-V_d}{I_b}$$

where Vcc is the supply voltage and Vd is the diode voltage of the base diode typically $V_d=0.66V$.

In conclusion

$$R_b = \frac{h_{Fe}(V_{cc}-V_d)}{5I_c}$$

The scaling by a factor of 5 is just a rule of thumb but you can always analyze from the datasheet how much current you need though the base to switch it on.

• Would this work? (12-0.6)*30/5*0.3=228 228 Ohms? – Casper Dec 31 '17 at 12:47
• If those are your values, eg. 12v, 30gg, 300mA.. well then yearh it would work. but are you really supplying the mcu with 12v? and 228ohm resistor value doesn't sound far off when you considder that you are switching 300mA with a transistor that has a hFe of only 30 which is very low, something else i would wory about is 12v/228ohm=53mA thats quite a large current to be putting out from an mcu output – Vinzent Dec 31 '17 at 12:59
• Unfortunately, your answer is working backwards to an Ib that may not be available, as it isn't here. Would be good to rework your answer to first calculate the required hFE from the required Ic and available Ib, then look up hFE(min) from the datasheet, then show the maximum available Ic if hFE(min) isn't up to it. (If I wasn't on a phone keyboard, I would have posted such an answer :-) ) – TonyM Dec 31 '17 at 13:14
• The question wasn't about how to choose the right transistor the question was how to find the base resistor value, to select a base resistor you will allways need to know the base current. I just showed the general idea/equation – Vinzent Dec 31 '17 at 13:22
• Sorry, Vcc is 3.3V is then. I mistook the Vcc as 12V (for the LED strip) going across the transistor. – Casper Dec 31 '17 at 13:59

I'll risk going off topic - change your NPNs, use a darlington pair or use N-MOSes.

TIP41C has a minimum gain of 15. Low(ish) LED strip are 4.8W per meter - that's 400mA. On the other hand ESP8266 has a maximum GPIO current of 12mA. If you do the calculations 12mA/(400mA/15/3) you end up with a maximum length od 1.35 meter.

I took extreme values - IRL it should work with roughly 2 to 2.5 meters (7 to 8 feet) of a LED strip but that's all.

For your actual question - you already have two good answers, so I'm not gonna repeat them.