BJT as a Switch Calculator (Base Resistor)
BJT as a Switch Calculator (Base Resistor)
Base resistor for an NPN transistor switching a lamp, relay or motor from a microcontroller pin — with the overdrive factor that keeps it saturated, the nearest standard value rounded down, and a check that the pin can supply the base current.
BJT switch base resistor
100 mA load on 12 V, driven from a 5 V pin, hFE 100, VBE(sat) 0.9 V, VCE(sat) 0.2 V, overdrive 5×
Base resistor for a saturated switch
- hFE
- DC current gain at the collector current you are actually using, from the datasheet
- overdrive
- forced-beta factor: 5 to 10 times the minimum base current, so the transistor stays bottomed out
- VBE(sat)
- base-emitter voltage when hard on — higher than the 0.7 V of an active-region transistor
- VCE(sat)
- what is left across the transistor when on; everything else reaches the load
Worked example
100 mA load on 12 V, driven from a 5 V pin, hFE 100, VBE(sat) 0.9 V, VCE(sat) 0.2 V, overdrive 5×
Minimum base current = 100 mA ÷ 100 = 1 mA
Target with 5× overdrive = 5 mA
Rb = (5 V − 0.9 V) ÷ 5 mA = 4.1 ÷ 0.005 = 820 Ω, which is itself an E24 value
Base current with 820 Ω = 4.1 ÷ 820 = 5 mA, an overdrive of 5.00×
Collector dissipation = 0.2 V × 100 mA = 20 mW; the base resistor turns 20.5 mW into heat; the load gets 1.18 W
The pin supplies 5 mA of its 20 mA budget, leaving 15 mA
How hFE collapses with current — a 2N3904 from a 5 V pin
| Load current | hFE (datasheet min) | Ib minimum | Ib at 5× | Exact Rb | Nearest E24 below | Ib you get |
|---|---|---|---|---|---|---|
| 1 mA | 70 | 14.29 µA | 71.43 µA | 57.4 kΩ | 56 kΩ | 73.21 µA |
| 10 mA | 100 | 100 µA | 500 µA | 8.2 kΩ | 8.2 kΩ | 500 µA |
| 50 mA | 60 | 833.3 µA | 4.167 mA | 984 Ω | 910 Ω | 4.505 mA |
| 100 mA | 30 | 3.333 mA | 16.67 mA | 246 Ω | 240 Ω | 17.08 mA |
Driving a transistor as a switch
An NPN transistor switching a load on the low side sits between the load and ground: the load goes from the supply to the collector, the emitter goes to ground, and the microcontroller pin drives the base through a resistor. The transistor is a current amplifier, so the base current sets the collector current — up to the point where the collector runs out of voltage and the transistor bottoms out at VCE(sat). That bottomed-out state is saturation, and it is where you want a switch to live, because the dissipation is then VCE(sat) × IC, a fraction of a watt, instead of the several watts a half-on transistor would burn.
Why overdrive. The bare minimum base current is IC ÷ hFE, but driving exactly that leaves the transistor on the edge. hFE is a datasheet minimum that varies by a factor of three between samples, falls with temperature and falls steeply with current — onsemi specifies a 2N3904 at 100 minimum at 10 mA but only 30 minimum at 100 mA. Multiplying the base current by five to ten (a “forced beta” of hFE ÷ 5 to hFE ÷ 10) buys the margin. The cost is pin current and a slightly slower turn-off, because stored charge in the base has to be removed.
Rounding down. The page rounds the base resistor down to the next standard value, not to the nearest. A smaller resistor means more base current, which means more overdrive and more margin; a larger one eats into it. For a 100 mA load at 5× overdrive the exact figure is 820 Ω — itself an E24 value — and the real base current is 5 mA. This is the opposite of the rule on the LED series resistor calculator, where rounding up keeps the current at or below the target: there the resistor protects the part, here it drives it.
Can the pin do it? This is the check people skip. Microcontroller pins are specified for a modest current and often for a smaller total across a whole port; exceeding it does not usually kill the chip outright but it does drag the output voltage down, which reduces the base current further. Enter your own part’s limit above. If the base current does not fit, the answer is a higher-gain transistor, a Darlington pair, or — usually the right answer today — a logic-level MOSFET, which needs no steady gate current at all. The MOSFET loss calculator does the conduction and switching losses for that case.
High side, PNP and inductive loads. An NPN on the low side switches the ground end of the load, so the load never sits at ground potential when off. To switch the supply end instead you need a PNP (or P-channel MOSFET) with its emitter at the supply — and its base has to be pulled below the supply, which a 3.3 V pin cannot do to a 12 V rail without a second transistor to level-shift. For a relay, solenoid or motor, always fit a flyback diode across the load with its cathode to the supply: the inductance will otherwise produce whatever voltage it needs to keep its current flowing when the transistor opens, and that voltage destroys transistors. Choose the load type above and the diagram shows it. For the resistor colours, see the resistor colour code calculator; for the arithmetic of the load itself, the Ohm’s law calculator.
Frequently asked questions
How do I calculate the base resistor for a transistor switch?
Take the load current, divide by the hFE at that current to get the minimum base current, multiply by 5 to 10 for overdrive, then Rb = (pin voltage − VBE(sat)) ÷ base current. For 100 mA with hFE 100 from a 5 V pin at 5× overdrive that is 820 Ω.
What is the overdrive factor and why does it matter?
It is how many times the bare minimum base current you supply. hFE is a datasheet minimum that varies between samples and falls with current and temperature, so driving exactly Ic ÷ hFE leaves the transistor half on, dropping volts and getting hot. Five to ten times forces it hard into saturation.
Should I round the base resistor up or down?
Down. A smaller resistor gives more base current and more overdrive, which is the safe direction for a switch. Rounding up reduces the base current and can take the transistor out of saturation.
Can an Arduino pin drive a transistor base directly?
Through a base resistor, yes, as long as the base current fits inside the pin’s rated current — check your own datasheet, and the limit for the whole port as well as the pin. If it does not fit, use a higher-gain transistor, a Darlington, or a logic-level MOSFET, which needs no steady current.
Do I need a diode across a relay or motor?
Yes. When the transistor turns off, the inductance keeps pushing current and generates a large reverse voltage that will destroy the transistor. A flyback diode across the load, cathode to the supply, gives that current somewhere to go.
Related calculators
References
- onsemi. 2N3903, 2N3904 general purpose transistors, publication order number 2N3904/D. hFE at VCE = 1 V: 40 min at 0.1 mA, 70 min at 1 mA, 100 min / 300 max at 10 mA, 60 min at 50 mA, 30 min at 100 mA; VCE(sat) 0.2 V max at 10 mA/1 mA and 0.3 V max at 50 mA/5 mA; VBE(sat) 0.65–0.85 V at 10 mA/1 mA, 0.95 V max at 50 mA/5 mA; IC 200 mA continuous.
- Horowitz P, Hill W. The Art of Electronics, 3rd ed. Cambridge University Press, 2015. §4.2.1 the inverting amplifier, §4.2.2 the noninverting amplifier, §4.4 a detailed look at op-amp behaviour — gain–bandwidth product, slew rate and the departures from the ideal op-amp.
- IEC 60063:2015. Preferred number series for resistors and capacitors (E6, E12, E24, E48, E96 and E192). International Electrotechnical Commission.
- Horowitz P, Hill W. The Art of Electronics, 3rd ed. Cambridge University Press, 2015. Chapter 2 on bipolar transistors: the transistor as a switch, saturation, and why a switch is driven with far more base current than β alone requires.
