The goal: saturation, not the active region
As a switch, a BJT must run in saturation. There VCE falls to 0.05–0.3 V and the transistor barely warms up.
With too little base current it stays in the active region. IC is capped at β·IB and VCE rises. The transistor dissipates VCE·IC, and the load does not get its full voltage.
Base resistor: step by step
- Know the load current. IC = Vload / Rload, or the datasheet current. Include inrush if there is any.
- Read hFE(min) at that current. Gain falls at high current: a 2N3904 has ≥ 100 at 10 mA but ≥ 30 at 100 mA. Use the table’s min value.
- Pick βforced: 10–20. Rule of thumb: IB = IC/10. βforced should be at most half of hFE(min).
- Compute RB. The resistor sees VGPIO − VBE(sat); VBE(sat) ≈ 0.7–0.9 V. If there is an RBE, add the current it steals.
- Round down to a standard value. A smaller RB means deeper saturation.
- Check the GPIO current. On most MCUs 8–12 mA is comfortable; ~20 mA is near the absolute limit.
- Check the dissipation. P ≈ VCE(sat)·IC + VBE·IB. In a TO-92 (≈ 200 °C/W), above 0.2–0.3 W is hot.
Low-side NPN switch calculator
The base pull-down resistor (RBE)
A 10–100 kΩ resistor from base to emitter does two jobs:
- Floating pin: during reset and boot the MCU leaves its pins as Hi-Z inputs. A floating base can half-turn-on from noise; RBE holds it at 0 V.
- Leakage: ICBO grows when hot and an open base multiplies it by β. RBE drains it to the emitter and speeds up turn-off.
The price: with the GPIO high, VBE/RBE flows into RBE instead of the base. Rule: RBE ≥ 5–10 × RB.
- Current stolen by 10 kΩI = 0.75 V / 10 kΩ75 µAnegligible at a few mA of IB, serious at 200 µA
- VBE when off, 47 kΩV = 1 µA · 47 kΩ47 mVfar below 0.5 V
PNP high-side: the trap and the fix
A PNP sits above the load with its emitter on the positive rail. It turns on when the base is pulled ~0.7 V below the emitter. To turn it off, the base must be pulled up to the emitter voltage.
If the load rail equals the GPIO voltage (3.3 V), the GPIO can do this directly: HIGH → off, LOW → on.
On a 12 V rail the PNP never turns off. The GPIO lifts the base to 3.3 V at most, leaving VEB = 8.7 V. Worse, base current flows through the pin’s ESD diode into the MCU’s 3.3 V rail.
The fix is an NPN level shifter. The GPIO drives the NPN, the NPN pulls the PNP base down. A pull-up resistor turns the PNP off.
12 V PNP high-side: direct GPIO vs NPN level shifter
Sizing the right-hand circuit
- PNP base currentIB = 200 mA / 1020 mA
- R2 (PNP base)R2 = (12 − 0.8 − 0.2) V / 20 mA≈ 560 ΩVEB(sat) 0.8 V, NPN VCE(sat) 0.2 V
- NPN base currentIB = 20 mA / 102 mA
- R1 (NPN base)R1 = (3.3 − 0.75) V / 2 mA≈ 1.2 kΩ
- Current stolen by the pull-upI = 0.8 V / 10 kΩ80 µAnegligible
Darlingtons and the ULN2003/ULN2803
A Darlington is two BJTs in cascade; the gain is β1·β2 (1000+). A GPIO can switch hundreds of mA with very little current.
The price: the output transistor cannot saturate. VCE(sat) becomes ≈ 0.9–1.6 V; the loss is 5–10 times that of a single BJT.
The ULN2003 (7 channels) and ULN2803 (8 channels) are Darlington arrays. Each input has a 2.7 kΩ base resistor, each output a flyback diode to COM. Always tie COM to the load supply.
| Option | IC per channel | VCE(sat) / VDS | Drive | Note |
|---|---|---|---|---|
| Single NPN (BC337) | ≤ 800 mA | 0.1–0.7 V | IC/10 | GPIO can’t supply enough at high current |
| Darlington (TIP120) | ≤ 5 A | ≈ 2 V @ 3 A | tiny (hFE ≥ 1000) | Runs hot; replace with a MOSFET |
| ULN2003A / ULN2803A | ≤ 500 mA | 0.9 V @ 100 mA, 1.3 V @ 350 mA | direct GPIO, internal 2.7 kΩ | Built-in flyback diodes; package loss limited to ~1 W |
| Logic-level MOSFET (AO3400A) | ≤ 5 A | I·RDS(on) ≈ 0.04 Ω·I | voltage, ~0 current | Best choice for most new designs |
| MOSFET array (TPL7407L) | ≤ 600 mA | ≈ 0.1–0.3 V | direct GPIO | ULN2003 pin-compatible, much lower loss |
Loss comparison: BJT, Darlington, MOSFET
Common mistake: using an emitter follower as a switch
An NPN above the load is not a switch but an emitter follower. The emitter follows ~0.7 V below the base. With a 3.3 V GPIO the load sees at most ~2.6 V; the rest of the 12 V turns into heat in the transistor.
The layout is tempting because the load stays grounded. An NPN high-side only works if the base can be driven above the load rail.
Low-side switch vs emitter follower side by side
Digital (pre-biased) transistors
Parts like DTC114E, PDTC114E or MUN2211 are “digital transistors”: small NPNs with a built-in R1 (base) and R2 (base–emitter). PNP versions are DTA…. One part saves space, and you can’t forget the resistors.
- Output current is small: typically 50–100 mA. Fine for relay coils, LEDs and small buzzers.
- The R1 = 10 kΩ (“114”) versions need ~3 V; marginal at 3.3 V. Pick the 4.7 kΩ (“143”) or 2.2 kΩ (“123”) version and check VI(on).
- The internal R2 is already the pull-down; no external one needed.
Worked examples
Example 1: How does an ESP32 (3.3 V) drive a 12 V, 80 mA relay coil?
2N3904 low-side switch, βforced = 10, 10 kΩ base pull-down.
- Load currentIC = 12 V / 150 Ω80 mA
- hFE(min) @ 80 mA60 at 50 mA, 30 at 100 mA≈ 40
- Base currentIB = 80 mA / 108 mA
- Overdrive40 · 8 mA / 80 mA4≥ 2 → good
- RB(3.3 − 0.8) V / (8 + 0.08) mA309 Ωnext lower E24 value: 300 Ω
- GPIO current(3.3 − 0.8) V / 300 Ω8.3 mAcomfortable for an ESP32
- Dissipation0.3 V · 80 mA + 0.8 V · 8 mA≈ 30 mWVCE(sat) ≈ 0.3 V
Why the popular “1 kΩ” choice is marginal:
- Base currentIB = (3.3 − 0.8) V / 1 kΩ2.5 mA
- Overdrive40 · 2.5 mA / 80 mA1.25
A BC547B also works, but its IC(max) is 100 mA, so 80 mA is close to the limit.
Example 2: Can a BC337 switch a 500 mA load from a GPIO?
The problem is not the transistor but the base current the GPIO can supply.
- Base current, βforced = 10IB = 500 mA / 1050 mAno GPIO can supply this
- Base current, βforced = 25IB = 500 mA / 2520 mAthe pin is at its absolute limit
- Overdrive40 · 20 mA / 500 mA1.6marginal
- DissipationP = 0.5 V · 0.5 A0.25 W
- Temperature rise (TO-92)ΔT = 0.25 W · 200 °C/W+50 °C
Other options: two stages (a small NPN feeds the BC337 base from V+) or a Darlington (over 1 V drop, ~0.6 W loss).