Transistor Base Resistor Calculator: NPN Switch Base Current, E24 Resistor and MCU Pin Limit
An NPN transistor can switch a load connected between the positive supply and its collector, with the emitter connected to ground. This calculator estimates the base current and resistor needed to drive it from a logic output. It rounds the resistor down to the next E24 value and checks the base current against your MCU pin limit.
The formula
Ib = overdrive factor × Ic ÷ hFE
Rb = (Vlogic − VBE) ÷ Ib
Use amperes for current when calculating resistance in ohms. The overdrive factor increases base current above the active-region estimate to help drive the transistor into saturation. The effective forced gain is hFE divided by the overdrive factor.
Example: with a 5 V logic high, 100 mA load, minimum hFE of 100, VBE of 0.7 V, and an overdrive factor of 5, the target base current is 5 mA. The exact resistor is (5 − 0.7) ÷ 0.005 = 860 Ω. The nearest E24 value below this is 820 Ω, giving (5 − 0.7) ÷ 820 ≈ 5.244 mA. Both currents are below the example 20 mA pin limit.
Practical notes
- Check saturation in the datasheet. Minimum hFE is an active-region specification, not a guarantee of saturation. Use the collector/base current ratio specified for VCE(sat) to choose an appropriate overdrive factor. VBE also varies with current and temperature.
- Check the logic output under load. Use its guaranteed high-level voltage at the required source current. The 20 mA default is an example limit; use the recommended operating limit for your MCU and check port and total-current limits too.
- Rounding down increases base current. The warning checks both the target current and the current with the selected resistor. If either exceeds the pin limit, consider a logic-level MOSFET or a Darlington driver. A Darlington needs a higher VBE setting and has a larger on-state voltage drop.
- Check the hardware ratings. Resistor tolerance and voltage variation affect base current. Check resistor power, transistor collector current, voltage, and dissipation. Connect logic ground and emitter ground together; add a flyback diode across an inductive load such as a relay coil.
More calculators: Tools page.
Worked examples
A 5 V logic output switching a relay
Suppose a relay has a 5 V, 70 mA coil, switched by a 2N2222 NPN transistor. For this calculation, enter logic high = 5 V, minimum hFE = 100, VBE = 0.7 V, overdrive factor = 10, and a permitted pin current of 10 mA. Treat these as design inputs to verify for the selected hardware.
First calculate Ib = 10 × 70 / 100 = 7 mA. Convert that to amperes for the resistor calculation: Rb = (5 − 0.7) / 0.007 ≈ 614.2857 Ω.
The widget chooses the largest E24 resistance at or below the exact result: 560 Ω. Although 620 Ω is nearby, it exceeds the calculated resistance and is therefore rejected.
With 560 Ω, Ib_actual = (5 − 0.7) / 560 × 1000 ≈ 7.678571 mA. The widget displays 7.679 mA. Relative to the 7 mA target, current error is (7.678571 / 7 − 1) × 100 ≈ +9.69%. Both target and resulting currents remain below the entered 10 mA limit.
Practical caveat: relay contacts have their own load ratings. A successful coil-driver calculation does not establish what the contacts can safely switch.
A 3.3 V controller switching an LED module
Consider a 5 V LED module drawing 20 mA, with its own current limiting, switched by an NPN transistor from a 3.3 V GPIO. Enter minimum hFE = 100, VBE = 0.7 V, overdrive factor = 10, and a pin-current limit of 4 mA.
The requested base current is Ib = 10 × 20 / 100 = 2 mA. Next, Rb = (3.3 − 0.7) / 0.002 = 1300 Ω.
Choose 1.3 kΩ, an E24 value already equal to the ideal result. The widget's downward-selection rule retains an exact standard value; it does not step down again.
Substitution gives Ib_actual = (3.3 − 0.7) / 1300 × 1000 = 2 mA. Nominal base-current error is 0%, and the resulting current is below the entered 4 mA limit. Here the load supply is 5 V, but the base-resistor equation correctly uses the 3.3 V logic output.
Practical caveat: verify that the LED module tolerates switching its ground connection, especially if it also has signal connections to other circuitry.
Common mistakes
- Assuming every transistor sold under the same family name has the same lead order; check the exact package pinout.
- Putting the calculated base resistor in the collector path instead of between the GPIO and base.
- Using the load-supply voltage as the logic-high input when the controller operates at another voltage.
- Assuming a GPIO remains actively low during startup; provide a defined base state while the pin is high impedance.
Comments
Post a Comment