Skip to content
Omnikalc

BJT base resistor calculator

Size the base resistor that saturates an NPN transistor switching a relay, LED strip or motor from a microcontroller pin, with the base current, the nearest standard value and the current drawn from the pin.

Updated on
Your inputs
V

Value out of range

V

Value out of range

mA

Value out of range

Value out of range

Overdrive factor for hard saturation

Results

Nearest standard E12 value at or below

820 Ω

Base current with the standard resistor

5.24 mA

Within what most microcontroller pins can supply
Calculated base resistor
860 Ω
Forced gain Ic ÷ Ib
19.1
Power in the base resistor
22.5 mW

Using a BJT as a switch

A small NPN transistor such as a 2N2222, BC337 or 2N3904 lets a microcontroller pin switch a relay coil, an LED strip or a small motor. To act as a good switch the transistor must be saturated: fully on, with only about 0.1 to 0.3 V across it. That requires enough base current, set by the base resistor.

The formulas

  • Base current needed: I_b = I_c ÷ h_FE(min) × overdrive factor
  • Base resistor: R_b = (V_in − V_be) ÷ I_b

The minimum h_FE from the datasheet is used, at the actual collector current, because gain varies widely between parts and with temperature. An overdrive factor of 3 to 10 guarantees saturation; many designers aim for a forced gain I_c ÷ I_b of about 10 to 20.

Example

Switching a 100 mA load from a 5 V pin with h_FE(min) = 100 and 5× overdrive needs 5 mA of base current, so R_b = (5 − 0.7) ÷ 0.005 = 860 Ω. Choosing the next lower standard value, 820 Ω, gives 5.24 mA, a forced gain of 19 and 22.5 mW in the resistor.

Check the drive pin

  • Most microcontroller pins supply 10 to 20 mA at most, and much less in total across all pins.
  • A 3.3 V pin needs a smaller resistor: (3.3 − 0.7) ÷ 0.005 = 520 Ω, so 470 Ω.
  • Above a few hundred milliamps, the base current gets large. A Darlington transistor, a logic-level MOSFET or a driver chip such as the ULN2003 is usually better.

Don’t forget

  • Put a flyback diode across relay coils and motors to absorb the voltage spike when the transistor turns off.
  • Add a 10 to 100 kΩ pull-down from base to ground so the transistor stays off while the microcontroller boots.
  • The transistor dissipates about V_ce(sat) × I_c, small when saturated but large if it is only partly on.
  • For a PNP high-side switch, the same calculation applies with the base pulled low.

Frequently asked questions

How do I calculate a transistor base resistor?

Divide the load current by the minimum hFE, multiply by an overdrive factor of 3 to 10, then R = (drive voltage − 0.7 V) ÷ base current.

Why use an overdrive factor?

Gain varies between parts and falls at high currents. Extra base current guarantees the transistor saturates, so it stays cool and drops little voltage.

Can an Arduino pin drive a relay directly?

Usually not. Relay coils often need 50 to 100 mA, more than a pin should supply, so use a transistor with a base resistor and a flyback diode.

What value should I pick if the result is between standard values?

Choose the next lower standard value so the base current stays at or above what you calculated, while checking the pin can supply it.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.