Skip to content
Electronics 21 min read

Transistor Base Resistor Calculation: Use Forced Beta

Observation recorded
Cinematic poster of a prototype test rig of circuit boards and wiring, with an oscilloscope behind it, with the title "The Base Resistor" in large condensed type and the line "Drive the switch hard.".

Take a 12 V relay with a 360 Ω coil, a 2N2222 and an Arduino pin. Follow the formula on most calculator pages (load current divided by an hFE of 100) and you get a 13 kΩ base resistor. Build it with a transistor whose gain sits at its guaranteed minimum and our model says the relay coil gets 8.3 V instead of 12 V, while the transistor burns 86 mW doing a job it should do for 2 mW. On a cold morning it may not click at all.

The fix is a one-line change in the recipe. Stop using the datasheet's current gain, and size the base current for a forced beta of about 10. This post shows where that number comes from, what happens to the collector voltage as base current falls, and three worked designs with real datasheet numbers.

Quick answerFor a transistor used as a switch, set IB=IC(max⁡)/10I_B = I_{C(\max)}/10, then RB=(Vdrive−VBE(sat))/IBR_B = (V_{drive} - V_{BE(\mathrm{sat})})/I_B, with VBE(sat) about 0.75 to 0.9 V. Round down to a standard value. A 33 mA relay from a 5 V pin needs about 1.2 kΩ, so use 1 kΩ. Do not divide by the datasheet hFE.
Infographic: What base resistor for a transistor? A TO-92 2N2222A switches a 12 V relay through a 1 kΩ base resistor. For a 33 mA relay from a 5 V pin, the forced-beta recipe gives about 1.2 kΩ, so use 1 kΩ; the common hFE-of-100 formula gives 13 kΩ. Minimum hFE falls from 75 at 25 °C to 35 at −55 °C. A log-scale chart of base resistor against load current shows the hFE recipe about ten times above the forced-beta lines, and marks 20 mA of base current near 200 mA, where a MOSFET is better. Tiles: 0.3 V maximum saturation voltage; 4.25 mA from the pin; 2.2 kΩ for a BC547 LED driver.
Tap the image to view it full size. View the accessible, editable SVG.

What does the usual base resistor formula get wrong?

The formula on page one of the search results is RB=(Vin−0.7 V)/(IC/hFE)R_B = (V_{in} - 0.7\ \mathrm{V})/(I_C/h_{FE}). One calculator works a 2 mA load at a gain of 100 from 9 V and lands on 415 kΩ. Some pages add "then divide by 2 to 10 for margin", which is the right instinct with no explanation of why. Forum answers often add "use a gain of 10 for power transistors and 20 for small ones." That rule of thumb is closer to the truth than the formula it is patched onto.

The problem is what hFE means. Read the 2N2222A datasheet from onsemi and every hFE line has a test condition attached:

hFE(min⁡)=35at IC=0.1 mA, VCE=10 VhFE(min⁡)=75at IC=10 mA, VCE=10 VhFE(min⁡)=35at IC=10 mA, VCE=10 Vat TA=−55 ∘C\begin{aligned}h_{FE(\min)} &= 35 \\ &\text{at } I_C = 0.1\ \mathrm{mA},\ V_{CE} = 10\ \mathrm{V} \\ h_{FE(\min)} &= 75 \\ &\text{at } I_C = 10\ \mathrm{mA},\ V_{CE} = 10\ \mathrm{V} \\ h_{FE(\min)} &= 35 \\ &\text{at } I_C = 10\ \mathrm{mA},\ V_{CE} = 10\ \mathrm{V} \\ &\phantom{\text{at }} T_A = -55\ ^\circ\mathrm{C}\end{aligned}
hFE=100 to 300at IC=150 mA, VCE=10 VhFE(min⁡)=50at IC=150 mA, VCE=1.0 VhFE(min⁡)=40at IC=500 mA, VCE=10 V\begin{aligned}h_{FE} &= 100\text{ to }300 \\ &\text{at } I_C = 150\ \mathrm{mA},\ V_{CE} = 10\ \mathrm{V} \\ h_{FE(\min)} &= 50 \\ &\text{at } I_C = 150\ \mathrm{mA},\ V_{CE} = \mathbf{1.0\ V} \\ h_{FE(\min)} &= 40 \\ &\text{at } I_C = 500\ \mathrm{mA},\ V_{CE} = 10\ \mathrm{V}\end{aligned}

Three things jump out. The gain is measured with 10 V across the transistor, which is the opposite of a switch: a switch is supposed to have almost nothing across it. Dropping VCE from 10 V to 1 V halves the guaranteed gain at 150 mA. And temperature alone takes the minimum from 75 to 35. The BC547 is worse for spread: onsemi lists hFE from 110 to 800 at 2 mA for the unbinned part, a ratio above 7 between units you could pull from the same reel.

So hFE is an amplifier parameter: collector current per unit of base current when the transistor is not switched fully on. Using it to design a switch is like sizing a car's brakes from its top speed.

What is forced beta, and why 10?

When a bipolar transistor saturates, the collector current stops being set by the transistor. It is set by the load: a 360 Ω coil on 12 V can only draw 12 V/360 Ω=33.3 mA12\ \mathrm{V}/360\ \Omega = 33.3\ \mathrm{mA} however hard you drive the base. The ratio IC/IBI_C/I_B is then whatever your circuit makes it. That ratio is called the forced beta, βforced, and the transistor is saturated as long as βforced is comfortably below the gain the transistor would have in its active region. Fiore's open textbook puts the rule plainly: the ratio of saturation current to base current must be "much less than β," and "a value of 10 or so would guarantee hard saturation."

The datasheets agree, and this is the real reason for 10. The 2N2222A saturation voltages are specified at exactly that ratio:

VCE(sat)≤0.3 V  (βforced=10)at IC=150 mA, IB=15 mAVCE(sat)≤1.0 V  (βforced=10)at IC=500 mA, IB=50 mAVBE(sat)=0.6 to 1.2 V at 150 mAVBE(sat)≤2.0 V at 500 mA\begin{aligned}V_{CE(\mathrm{sat})} &\le 0.3\ \mathrm{V}\ \ (\beta_{\mathrm{forced}} = 10) \\ &\text{at } I_C = 150\ \mathrm{mA},\ I_B = 15\ \mathrm{mA} \\ V_{CE(\mathrm{sat})} &\le 1.0\ \mathrm{V}\ \ (\beta_{\mathrm{forced}} = 10) \\ &\text{at } I_C = 500\ \mathrm{mA},\ I_B = 50\ \mathrm{mA} \\ V_{BE(\mathrm{sat})} &= 0.6\text{ to }1.2\ \mathrm{V}\ \text{at } 150\ \mathrm{mA} \\ V_{BE(\mathrm{sat})} &\le 2.0\ \mathrm{V}\ \text{at } 500\ \mathrm{mA}\end{aligned}

The BC547 family uses a forced beta of 20 instead: VCE(sat) is 0.09 V typical and 0.25 V maximum at 10 mA with 0.5 mA of base current, and 0.2 V typical, 0.6 V maximum at 100 mA with 5 mA. If you drive the part at the ratio the manufacturer tested, the guaranteed maximum applies to your circuit. Drive it at a forced beta of 60 and the datasheet guarantees nothing at all.

Schematic: a 5 volt microcontroller GPIO pin drives the base of a 2N2222 NPN transistor through a 1 kilohm base resistor, with a 10 kilohm resistor from base to ground. The emitter is grounded. The collector connects to the bottom of a 360 ohm relay coil whose top goes to plus 12 volts, with a 1N4148 flyback diode across the coil, anode at the collector and cathode at plus 12 volts. Annotations give base current about 4.2 milliamps, collector current about 33 milliamps, forced beta about 8 and saturation voltage about 0.06 volts.
Figure 1. The low-side relay driver used in the worked example. RB sets the base current; RBE keeps the transistor off while the pin floats; the diode catches the coil's turn-off spike.

What happens if the base current is too small?

The transistor does not fail gracefully into "slightly less on." It slides out of saturation into its linear region and becomes a variable resistor sharing the supply with your load. Figure 2 shows this for the relay circuit in Figure 1. To draw it we built a small Gummel-Poon transistor model in Python (Ebers-Moll junctions plus high-injection gain roll-off and 1 Ω of collector resistance, with parameters from the widely circulated Q2N2222 SPICE model), loaded it with 360 Ω on 12 V, and solved for VCE at each base current. The three curves differ only in the transistor's low-current gain.

Log-log plot of collector-emitter voltage from 0.03 to 15 volts against base current from 0.03 to 10 milliamps for a 2N2222 driving a 12 volt 360 ohm relay coil. Three curves for gains 256, 75 and 35 each stay near 10 volts at low base current, then drop steeply at a knee near 0.13, 0.45 and 1 milliamp respectively, and settle below 0.2 volts. A dashed orange line at 0.33 milliamps marks the 13 kilohm design, where the gain-75 part still has 3.8 volts and the gain-35 part 8 volts across it. A dashed green line at 4.2 milliamps marks the 1 kilohm design, where all three are below 0.07 volts.
Figure 2. Collector voltage against base current for the relay load, from our transistor model. Each curve has a sharp knee at roughly IB=IC/hFEI_B = I_C/h_{FE}. The hFE recipe puts the operating point right on the knee; forced beta puts it well past every knee.

The orange dashed line is the hFE recipe's 13 kΩ resistor, which gives about 0.33 mA of base current. Read the curves where it crosses them:

Typical part (model gain 256):

VCE=0.13 V, IC=33.0 mAP=4 mW (works)\begin{aligned}V_{CE} &= 0.13\ \mathrm{V},\ I_C = 33.0\ \mathrm{mA} \\ P &= 4\ \mathrm{mW}\ (\text{works})\end{aligned}

Gain exactly 100:

VCE=1.25 V, IC=29.9 mAP=37 mW\begin{aligned}V_{CE} &= 1.25\ \mathrm{V},\ I_C = 29.9\ \mathrm{mA} \\ P &= 37\ \mathrm{mW}\end{aligned}

Gain 75 (datasheet minimum at 25 °C):

VCE=3.75 V, IC=22.9 mAP=86 mW\begin{aligned}V_{CE} &= 3.75\ \mathrm{V},\ I_C = 22.9\ \mathrm{mA} \\ P &= 86\ \mathrm{mW}\end{aligned}

Gain 35 (datasheet minimum at −55 °C):

VCE=8.0 V, IC=11.1 mAP=89 mW\begin{aligned}V_{CE} &= 8.0\ \mathrm{V},\ I_C = 11.1\ \mathrm{mA} \\ P &= 89\ \mathrm{mW}\end{aligned}

With a gain-75 part the relay coil sees 12−3.75=8.25 V12 - 3.75 = 8.25\ \mathrm{V}, which is 69% of its rating. Many relays need about three quarters of rated voltage to pull in reliably, so whether this circuit works becomes a lottery on the transistor and the temperature. The prototype on your bench will probably work, because a typical 2N2222 has a gain well above 100. The hundredth unit, or the one in an unheated shed, may not.

Source note The relay coil values (360 Ω, 33.3 mA for a 12 V Omron G5LE) come from distributor listings; the coil table in the Omron PDF I downloaded did not extract as text, so I could not read it directly. The "about 75% of rated voltage to pull in" figure is a typical value for small PCB relays that I did not confirm for this part. The transistor model parameters (IS = 14.34 fA, BF = 255.9, BR = 6.09, IKF = 0.285 A) are from the commonly shared Q2N2222 SPICE model, not a file I obtained from onsemi.

Push the base current past every knee, as the green line does, and the spread disappears. At 4.2 mA all three transistors sit between 0.060 and 0.067 V. That is the point of a switch: the outcome no longer depends on a parameter that varies 7 to 1.

How to calculate the base resistor step by step

Here is the recipe, applied to the relay driver in Figure 1.

Step 1: worst-case collector current.

IC=12 V/360 Ω=33.3 mA (nominal)I_C = 12\ \mathrm{V}/360\ \Omega = 33.3\ \mathrm{mA}\ (\text{nominal})

Coil resistance is typically ±10%, and a cold coil reads low, so design for:

IC(max⁡)=12 V/324 Ω≈37 mAI_{C(\max)} = 12\ \mathrm{V}/324\ \Omega \approx \mathbf{37\ mA}

Step 2: base current at a forced beta of 10.

IB=37 mA/10=3.7 mAI_B = 37\ \mathrm{mA}/10 = \mathbf{3.7\ mA}

Step 3: voltage across RB.

VBE(sat)≈0.75 VV_{BE(\mathrm{sat})} \approx 0.75\ \mathrm{V} at 37 mA (our model; the datasheet gives 0.6 to 1.2 V at 150 mA, so it is lower here).

VRB=5.0 V−0.75 V=4.25 VV_{RB} = 5.0\ \mathrm{V} - 0.75\ \mathrm{V} = 4.25\ \mathrm{V}

Step 4: resistor.

RB=4.25 V/3.7 mA=1.15 kΩ→round down to 1 kΩ (E12)\begin{aligned}R_B &= 4.25\ \mathrm{V}/3.7\ \mathrm{mA} = 1.15\ \mathrm{k\Omega} \\ &\to \text{round down to } \mathbf{1\ k\Omega}\ (\text{E12})\end{aligned}

Actual base current and forced beta:

IB=4.25 V/1 kΩ=4.25 mAβforced=33.3/4.25=7.8 (nominal load)\begin{aligned}I_B &= 4.25\ \mathrm{V}/1\ \mathrm{k\Omega} = 4.25\ \mathrm{mA} \\ \beta_{\mathrm{forced}} &= 33.3/4.25 = 7.8\ (\text{nominal load})\end{aligned}

Rounding down matters: rounding up raises the forced beta and eats the margin you designed in. Now check the parts around the resistor, because the transistor is rarely the weak link here.

Pin current: 4.25 mA. ATmega328P: absolute maximum 40 mA per pin, VOH≥4.1 VV_{OH} \ge 4.1\ \mathrm{V} at 20 mA. Fine.

Low-VOH check: if the pin only reached 4.1 V:

IB=(4.1−0.75)/1 kΩ=3.35 mAβforced=9.9 (nominal load)\begin{aligned}I_B &= (4.1 - 0.75)/1\ \mathrm{k\Omega} = 3.35\ \mathrm{mA} \\ \beta_{\mathrm{forced}} &= 9.9\ (\text{nominal load})\end{aligned}

Still saturated.

RBE = 10 kΩ steals 2% of the drive, which is negligible:

0.75 V/10 kΩ=0.075 mA0.75\ \mathrm{V}/10\ \mathrm{k\Omega} = 0.075\ \mathrm{mA}

Collector dissipation:

0.06 V×33 mA≈2 mW0.06\ \mathrm{V} \times 33\ \mathrm{mA} \approx 2\ \mathrm{mW}

The 2N2222A is rated 625 mW in TO-92.

Resistor dissipation:

(4.25 mA)2×1 kΩ=18 mW(4.25\ \mathrm{mA})^2 \times 1\ \mathrm{k\Omega} = 18\ \mathrm{mW}

Any 0.125 W part.

From a 3.3 V microcontroller the same steps give RB=(3.3−0.75)/3.7 mA=690 ΩR_B = (3.3 - 0.75)/3.7\ \mathrm{mA} = 690\ \Omega, so use 680 Ω, which pulls 3.75 mA from the pin. Check that your chip can source that. The batch post on how much current an Arduino pin can supply covers how the output voltage sags with load, and the reasoning is the same one we use when choosing a pull-up resistor value: the resistor has to fit the weakest pin, not the typical one. Do not leave out the flyback diode either; why a relay needs a flyback diode works through the turn-off spike you get without it.

Why does saturation voltage barely care about forced beta?

A natural worry is that a forced beta of 10 wastes current and that 30 would do. Figure 3 shows what you gain and lose. It holds the collector current at 150 mA (the datasheet test point) and raises the forced beta from 2 to 200, using the same model.

Plot of VCE(sat) from 0 to 0.6 volts against forced beta from 2 to 200 on a log axis at 150 milliamps collector current. Three curves for low-current gains 50, 100 and 256 all start near 0.17 volts and rise slowly, then shoot upward at forced betas of about 33, 65 and 168, where dashed vertical lines show the transistor leaving saturation. A shaded green band covers forced beta 5 to 20, and a green dot marks the datasheet maximum of 0.3 volts at forced beta 10.
Figure 3. Model VCE(sat) at 150 mA. Between βforced = 5 and 20 the curve is almost flat. The wall on the right sits at the transistor's actual gain at 150 mA, which high-level injection pulls well below its low-current hFE (the bracketed numbers).

Two things are worth reading off it. First, over the shaded band from 5 to 20 the saturation voltage changes by only a few tens of millivolts: there is little to gain by driving harder than βforced = 10, and little to lose by relaxing to 15 or 20. Second, the wall arrives sooner than the hFE label suggests. A part labelled with a gain of 100 runs out at about 65 when it carries 150 mA, because gain falls at high current. That is the same effect that makes onsemi guarantee only 40 at 500 mA. A forced beta of 10 puts you below the wall for every 2N2222A the datasheet allows, at every current it specifies.

Our model gives 0.19 V at the datasheet test point against the guaranteed maximum of 0.3 V. That gap is the manufacturer's margin for process spread and is another reason not to trust a single model, ours included, for the last tenth of a volt.

Worked example: BC547 driving an LED from 3.3 V

A 20 mA indicator LED on a 5 V rail, switched by a BC547B from a 3.3 V microcontroller. The BC547 datasheet specifies saturation at a forced beta of 20, so we use that.

IC=20 mA, βforced=20IB=1.0 mARB=(3.3 V−0.75 V)/1.0 mA=2.55 kΩ→round down to 2.2 kΩ\begin{aligned}I_C &= 20\ \mathrm{mA},\ \beta_{\mathrm{forced}} = 20 \\ I_B &= 1.0\ \mathrm{mA} \\ R_B &= (3.3\ \mathrm{V} - 0.75\ \mathrm{V})/1.0\ \mathrm{mA} \\ &= 2.55\ \mathrm{k\Omega} \\ &\to \text{round down to } \mathbf{2.2\ k\Omega}\end{aligned}

Actual base current and forced beta:

IB=2.55 V/2.2 kΩ=1.16 mAβforced=17\begin{aligned}I_B &= 2.55\ \mathrm{V}/2.2\ \mathrm{k\Omega} = 1.16\ \mathrm{mA} \\ \beta_{\mathrm{forced}} &= 17\end{aligned}

VCE(sat): between 0.25 V max (at 10 mA) and 0.6 V max (at 100 mA); allow 0.2 V typical.

LED resistor:

R=(5.0−2.0−0.2) V/20 mA=140 Ω150 Ω⇒18.7 mA\begin{aligned}R &= (5.0 - 2.0 - 0.2)\ \mathrm{V}/20\ \mathrm{mA} \\ &= 140\ \Omega \\ 150\ \Omega &\Rightarrow 18.7\ \mathrm{mA}\end{aligned}

Compare the hFE recipe with the part's 200 minimum gain: IB = 0.1 mA and RB = 25 kΩ. That works for a BC547B at room temperature. Swap in an unbinned BC547 (110 minimum) or a BC547A and the LED dims noticeably, and there is no way to see why without a meter on the collector. The LED's own series resistor is a separate calculation, covered in why LEDs need a resistor.

When does a bipolar transistor stop being the right switch?

Figure 4 turns the recipe into a chart. Read across from your load current to the resistor for your drive voltage and forced beta.

Log-log design chart of base resistor from 50 ohms to 20 kilohms against load current from 5 to 500 milliamps. Four straight lines fall with slope minus one: 5 volt drive at forced beta 20 and 10, and 3.3 volt drive at forced beta 20 and 10. A dot marks the relay example at 33 milliamps and 1.26 kilohms. The region above 200 milliamps is shaded orange where base current at forced beta 10 exceeds 20 milliamps.
Figure 4. RB=(Vdrive−0.8 V)/(IC/βforced)R_B = (V_{drive} - 0.8\ \mathrm{V})/(I_C/\beta_{\mathrm{forced}}), with a fixed 0.8 V for VBE(sat). Above about 200 mA the base current at βforced = 10 passes 20 mA, which is more than a typical microcontroller pin should source.

The shaded corner is where the method breaks down. Switching 500 mA with a 2N2222A at its datasheet point needs 50 mA of base current, and even then the guaranteed numbers are poor:

IB=500 mA/10=50 mAI_B = 500\ \mathrm{mA}/10 = 50\ \mathrm{mA}

That is more than the ATmega328P's 40 mA absolute maximum per pin.

VCE(sat)≤1.0 VPC≤1.0 V×0.5 A=0.5 W\begin{aligned}V_{CE(\mathrm{sat})} &\le 1.0\ \mathrm{V} \\ P_C &\le 1.0\ \mathrm{V} \times 0.5\ \mathrm{A} = 0.5\ \mathrm{W}\end{aligned}

Temperature rise at RθJA = 200 °C/W:

ΔT=0.5 W×200=100 ∘C above ambient\begin{aligned}\Delta T &= 0.5\ \mathrm{W} \times 200 \\ &= 100\ ^\circ\mathrm{C}\ \text{above ambient}\end{aligned}

That is a transistor running at 125 °C on a 25 °C bench, before any base dissipation. Past roughly 100 to 200 mA from a logic pin, a logic-level MOSFET is usually the better switch: its gate draws no steady current, and its on-resistance can be tens of milliohms. The gate still needs a series resistor for other reasons, explained in choosing a MOSFET gate resistor value. A Darlington pair solves the drive problem but not the heat, because its saturation voltage can never fall below one VBE plus the first transistor's VCE(sat), which puts it near 1 V before the load current adds anything. For bidirectional motor loads the same trade-off shows up in the H-bridge motor driver, where bipolar bridges lose several volts and MOSFET bridges lose tenths.

Does too much base current cause problems?

Within the ratings, mostly it costs speed. A heavily saturated transistor stores extra charge in its base, and that charge must be removed before the collector current can start to fall. The 2N2222A datasheet guarantees a storage time of at most 225 ns at 150 mA, and it measures that with IB1=IB2=15 mAI_{B1} = I_{B2} = 15\ \mathrm{mA}: the base is actively pulled negative with 15 mA during turn-off. With only a resistor to ground removing the charge, expect a slower turn-off than the datasheet figure. For a relay that switches a few times a second, nobody cares. For PWM at tens of kilohertz, overdriving at βforced = 3 is a mistake, and 10 to 20 is a sensible compromise.

The other limit is the base-emitter junction's reverse rating, only 6 V on both the 2N2222A and BC547. A base driven from a 12 V square wave through a capacitor can exceed that on the negative swing. A plain logic pin through a resistor cannot.

Finally, the base-emitter resistor. During reset a microcontroller pin floats, and leakage or pickup on the base can turn the transistor partly on, so the relay chatters at power-up. 10 to 100 kΩ from base to emitter holds it off for the 75 µA calculated above. RB and RBE form a divider, the same arithmetic as in why a voltage divider is a poor power supply, so with a low RBE subtract its current from the drive.

Is a switching transistor different from an amplifying one?

Physically, no. An amplifier keeps the transistor out of saturation, where hFE and transconductance are exactly the right parameters; our companion post on how a transistor amplifies draws both regions on one load line. A switch lives in the corner of that load line where gain has stopped mattering, which is why the switch recipe should not contain the gain at all, except as a check that βforced sits well below it.

The bench version: worst-case IC÷10=IBI_C \div 10 = I_B. (Vdrive−0.8 V)÷IB=RB(V_{drive} - 0.8\ \mathrm{V}) \div I_B = R_B, rounded down. Check the pin can supply IB. Add 10 kΩ base to emitter. If IB comes out above about 10 to 20 mA, use a logic-level MOSFET instead.

FAQ

How do you calculate the base resistor for a transistor switch?

Take the worst-case load current, divide by a forced beta of 10 (or up to 20 for small-signal parts at low current) to get the base current, then divide the drive voltage minus about 0.75 to 0.9 V by that current. Round down to the next standard value. For a 33 mA relay driven from 5 V this gives about 1.2 kΩ, so use 1 kΩ.

Why not use the hFE from the datasheet to size the base resistor?

hFE is measured with the transistor out of saturation, typically at 5 or 10 V across it, and it varies by a factor of several between units and with temperature. A 2N2222A is only guaranteed 35 at −55 °C. If you size the base current from a typical hFE, many parts never saturate and drop volts instead of tenths of a volt.

What is forced beta?

Forced beta is the ratio of collector current to base current that you impose on a saturated transistor, IC/IBI_C/I_B. It is set by the circuit, not the transistor. Datasheets specify saturation voltage at forced betas of 10 or 20, so designing to those ratios lets you use the guaranteed VCE(sat) figures.

Can too much base current damage a transistor?

Within the ratings, extra base current mainly wastes drive current and slows turn-off because more charge is stored in the base. The real limits are the microcontroller pin current, the transistor's base current rating where one is given, and the base-emitter reverse voltage, which is only 6 V on parts like the 2N2222A and BC547.

Do I need a resistor from base to emitter?

It is good practice. A 10 to 100 kΩ resistor from base to emitter holds the transistor off while the microcontroller pin floats during reset or programming, and it helps remove base charge at turn-off. At 10 kΩ it steals only about 75 µA from the base drive.

Sources

  1. onsemi, P2N2222A Amplifier Transistor datasheet, Rev. 7 (hFE at each test condition, VCE(sat) and VBE(sat) at IC/IB=10I_C/I_B = 10, storage time 225 ns, 600 mA, 625 mW, RθJA 200 °C/W, VEBO 6 V): onsemi.com/pdf/datasheet/p2n2222a-d.pdf
  2. onsemi, BC546B/BC547A, B, C/BC548B, C datasheet, Rev. 8 (hFE 110 to 800, VCE(sat) 0.09/0.25 V at 10 mA/0.5 mA and 0.2/0.6 V at 100 mA/5 mA, VBE(sat) 0.7 V, 100 mA): onsemi.com/pdf/datasheet/bc546-d.pdf
  3. Microchip (Atmel), ATmega328P automotive datasheet 7810D (40 mA per pin absolute maximum, VOH ≥ 4.1 V at 20 mA and 5 V): microchip.com ATmega328P datasheet PDF
  4. James Fiore, Semiconductor Devices: Theory and Application, section 4.7 "BJT Switching and Driver Applications" (ratio "much less than β", "a value of 10 or so would guarantee hard saturation"): eng.libretexts.org
  5. DigiKey TechForum, "Digital Switching: Transistor Saturation and Forced Beta" (relay driver designed at IB=10% of ICI_B = 10\%\ \text{of}\ I_C): forum.digikey.com
  6. Omron, G5LE PCB power relay datasheet (contact ratings; coil table not machine-readable in my copy): omronfs.omron.com G5LE PDF
  7. Typical page-one calculator using hFE (2 mA at gain 100 from 9 V gives 415 kΩ, "divide Rb by a factor of 2 to 10"): calculate.co.nz transistor base resistor calculator

Method note: Figures 2 and 3 come from our own Python implementation of a simplified Gummel-Poon model (no Early effect, no quasi-saturation, 25 °C) with Q2N2222 SPICE parameters, with the forward gain parameter changed to represent low- and high-gain units. Treat the curves as shape and order of magnitude, and the datasheet limits as the design numbers.

Header image: NASA (image jsc2025e015689), regraded for this article.

Related observations
Electronics 555 Timer Frequency Formula: Where 1.44 Comes From Electronics ADC Resolution vs Accuracy: ENOB, INL and the Reference Projects Building Your Own Quadcopter Drone: Essential Parts and Specifications in India
Transmit