Transistor Switch Base Resistor Calculator
Find the base resistor for driving a load such as a relay, motor or LED through an NPN transistor from a microcontroller pin.
Formula and cautions
Ib = k·Ic / hFE, Rb = (Vdrive − Vbe) / Ib. A switch should be driven hard into saturation to stay cool, so the base current is the datasheet minimum hFE requirement times an overdrive factor. Always put a flyback diode across coils such as relays and motors.
Frequently asked questions
Why not just use hFE to size the base current?
hFE varies widely between parts and drops at high current. Designing with the minimum hFE times an overdrive factor (a forced beta of about 10 to 20) makes sure the transistor saturates and runs cool.
Can an Arduino pin drive the base directly?
Yes, through the resistor, as long as the base current stays well within the pin's limit (around 20 mA recommended on an Uno). For larger loads use a logic-level MOSFET or a Darlington.