Use a transistor as a switch (and pick the base resistor)
By Mihai Dumitru · 11 October 2026 · 6 min read
On this page
A microcontroller pin can give maybe 20 mA. A motor wants a few hundred. A transistor sits in between: a small current into its base switches a much bigger current through it.
Set your drive voltage and load below. It tells you the base resistor.
Transistor switch calculator
Switch a motor, lamp or LED strip from a weak control pin. Get the base resistor.
- Use this resistor (rounded down)
- 820 Ω
- Exact resistor
- 860 Ω
- Base current needed
- 1 mA
- Real base current
- 5.24 mA
How the switch works
An NPN transistor has three legs: collector, base and emitter. Wired as a switch:
- The load (motor, lamp, LED strip) goes between the plus of its supply and the collector.
- The emitter goes to ground.
- Your control pin connects to the base through a resistor.
Pin high, a little current flows into the base, and the transistor lets a big current flow from collector to emitter. The load turns on. Pin low, no base current, load off.
The base resistor, step by step
- How much current does the load need? Say 100 mA.
- What's the gain? The datasheet calls it hFE. Use the low number. 100 is a reasonable start for small transistors.
- Minimum base current: load ÷ gain = 100 ÷ 100 = 1 mA.
- Overdrive it. Give 5 times more, 5 mA. This makes sure the transistor is fully on, not half on.
- Resistor: (drive voltage − 0.7 V) ÷ base current. On 5 V: 4.3 ÷ 0.005 = 860 Ω. Round down to 820 Ω.
Why down, when for LEDs we round up? Here a smaller resistor means a bit more base current, which keeps the transistor solidly on. That's the safe side.
On a 3.3 V pin the same load needs 2.6 ÷ 0.005 = 520 Ω, so 470 Ω. Still only about 5.5 mA from the pin, which is fine.
Why "fully on" matters
A transistor that's fully on (saturated) has only about 0.2 V across it, so it barely gets warm: 0.2 V × 100 mA = 20 mW. Half on, it can have several volts across it and turn a lot more power into heat. Underdriven transistors are the ones that get hot and die.
Things that kill transistors
- Too much load current. A BC547 is rated for 100 mA, keep it well under that. A 2N2222 handles a few hundred mA. For amps, use a logic-level MOSFET instead.
- No diode on motors and relays. When a coil switches off, it kicks back a voltage spike. Put a diode across the load, stripe towards plus. It takes the spike instead of the transistor.
- No base resistor. The base then pulls too much from your pin and can damage both the pin and the transistor.
- Pins mixed up. Different packages put the legs in different order. Check the datasheet pinout, don't guess.
The base resistor is the same Ohm's law as the LED resistor, just rounded the other way.
VoltTrial has a transistor part. Build a battery, a lamp and a transistor, drive the base through a resistor and press Run. Change the base resistor and watch the lamp go from dim to full.
Try it in VoltTrial