beginner

Transistors as Switches

Use a transistor to switch loads a logic pin cannot drive: BJT and MOSFET basics, the three regions of operation, sizing the base resistor with a forced beta, logic-level MOSFETs and Rds(on), flyback protection, low-side and high-side switching, and power dissipation.

60 min

1. A switch you control with a signal

A transistor uses a small signal at one terminal to control a larger current between the other two. It is the building block of every amplifier and every digital chip. As a switch it lets a 3.3 V logic pin turn on a motor, a relay, a strip of LEDs or a buzzer.

BJT (bipolar junction transistor) MOSFET
Terminals Base, Collector, Emitter Gate, Drain, Source
Controlled by A current into the base A voltage on the gate (almost no current)
Types NPN, PNP N-channel, P-channel
Typical small parts 2N2222, BC547, 2N3904 2N7000, IRLZ44N, AO3400
Strengths Cheap, simple for small loads Very low on-resistance, efficient at high current

2. Three regions of operation

A BJT works in three regions:

Region Condition Behaviour
Cutoff V_BE below about 0.6 V No base current, no collector current: the switch is off
Active V_BE about 0.7 V, collector voltage mid-range Collector current ≈ β × base current: an amplifier
Saturation Plenty of base current V_CE falls to about 0.1 to 0.3 V: the switch is fully on

For a switch you want only cutoff and saturation, never lingering in the active region (high voltage and high current together means heat).

3. Sizing the base resistor

A transistor’s gain β (also hFE) varies widely between parts, temperature and current, so we do not rely on it. We use a forced beta of about 10 for saturation, which guarantees the transistor is fully on:

I_B = I_C / 10          R_B = (V_drive − 0.7 V) / I_B

Example. Switch a 100 mA load from a 5 V logic pin: I_B = 100 / 10 = 10 mA; R_B = (5 − 0.7) / 0.01 = 430 Ω (use 390 Ω). For a 3.3 V pin the same load gives (3.3 − 0.7) / 0.01 = 260 Ω, but check the pin can deliver 10 mA at all (many cannot).

A pull-down resistor (10 kΩ) from base to ground makes sure the transistor stays off when the pin is floating, such as during reset.

Load wiring (low-side switch, NPN):

+V ---[load]---+ collector
                |
Pin ---[RB]--- base      emitter --- GND

For an inductive load add the flyback diode across it (previous lesson).

+12 VLoad / coilRbPinflybackdiodeQlow-side switch
An NPN low-side switch: base resistor from the pin, load to the supply, emitter to ground.

4. MOSFETs as switches

A MOSFET needs almost no gate current, only a gate voltage above its threshold. For switching, you need the gate-source voltage (V_GS) high enough that the part is fully on, where it behaves like a very small resistor, R_DS(on).

  • Logic-level MOSFETs (such as IRLZ44N or many SMD parts) specify R_DS(on) at V_GS = 4.5 V or 2.5 V. Standard parts like the IRF540 need about 10 V and may barely turn on at 3.3 V.
  • Power lost in the transistor when fully on: P = I² × R_DS(on). At 2 A through 50 mΩ: 4 × 0.05 = 0.2 W, so no heat sink is needed.
  • Gate resistor (about 100 Ω) limits the charging current of the gate and tames ringing; add a 10 kΩ pull-down from gate to source so it does not float.
  • Body diode: a MOSFET has an intrinsic diode between source and drain. Do not wire the load so that this diode conducts by mistake.
  • N-channel low-side switching (load between supply and drain, source to ground) is the simplest. High-side switching (switching the positive supply) uses a P-channel MOSFET or an N-channel with a gate driver.

5. Heat, ratings and protection

  • Check ratings from the datasheet: maximum V_CE (or V_DS), collector or drain current, and power dissipation, with a safety margin (at least 50 percent).
  • Saturated BJT loss: P = I_C × V_CE(sat) = 0.1 A × 0.2 V = 20 mW, negligible. Partly on, 0.1 A × 6 V = 600 mW, which would overheat a small part. Make switching decisive.
  • Always put a flyback diode across inductive loads.
  • Keep the ground of the logic and the load supply common, or the switch will not work.
  • For a motor, add a capacitor across it and keep wires short to limit noise that resets the microcontroller.

6. On your bench

  1. Build 5 V → LED + 330 Ω → NPN collector, emitter to ground, with the base through 1 kΩ to a switch to 5 V. Measure V_BE (about 0.7 V) and V_CE when on (about 0.1 to 0.3 V).
  2. Calculate the base resistor for a 100 mA load with forced beta 10 and compare it with what you built. Try a 100 kΩ base resistor and see the transistor come out of saturation (V_CE rises, the load dims).
  3. Swap the LED for a small 5 V relay coil with a flyback diode across it. Remove the diode and observe the transistor temperature and any glitches on the supply with a scope (only if you have one).
  4. Switch an LED strip with a logic-level MOSFET and a 10 kΩ gate pull-down, and measure the MOSFET’s drain-source voltage when on, to find R_DS(on) = V / I.

7. Hands-on lab: sizing a transistor switch

Base resistor, load current and heat — Python 3
WHAT TO DO
base_resistor(vin, ic_ma, forced_beta): the base resistor in ohms for a saturated NPN switch with V_BE of 0.7 V: (vin - 0.7) divided by the base current (collector current divided by the forced beta), rounded to 1 decimal place. load_current_ma(vcc, rload, vce_sat): the load current in milliamps when the transistor is on: (vcc - vce_sat) / rload * 1000, rounded to 1 decimal place. switch_power_mw(ic_ma, vce): the power in the transistor in milliwatts, collector current times collector voltage, rounded to 1 decimal place. bjt_state(vbe, vce): "cutoff" when vbe is below 0.6, "saturation" when vce is 0.3 or less, otherwise "active" (check in that order). rds_loss_mw(i_a, rds_mohm): the power in a MOSFET in milliwatts, i squared times R_DS(on) in milliohms, rounded to 1 decimal place. max_ic_ma(ib_ma, hfe): the largest collector current the base current can support, base current times gain, rounded to 1 decimal place.
YOUR CODE (edit here, then press Run)
Ctrl/⌘ + Enter
OUTPUT

8. Common mistakes

Mistake Better
No base resistor Always limit the base current
Using the datasheet gain instead of forced beta 10 Design for saturation with margin
No flyback diode on a coil Diode across every inductive load
Using a standard-threshold MOSFET with a 3.3 V pin Pick a logic-level part and check R_DS(on) at your V_GS
Floating gate or base at start-up Add a 10 kΩ pull-down
Separate grounds for logic and load Join the grounds

9. Key takeaways

  • A transistor lets a small signal switch a large current: BJT by base current, MOSFET by gate voltage.
  • Use cutoff and saturation; avoid the active region for switching.
  • R_B = (V_drive − 0.7) / (I_C / 10) for a BJT; pull-down on the base or gate.
  • Logic-level MOSFETs have low R_DS(on) at 3.3 to 5 V; loss is I² × R_DS(on).
  • Add a flyback diode, check ratings, and share the ground.
A 12 V, 400 mA motor is switched with a 2N2222 from a 5 V pin. Which base resistor value and what else do you add?

Base current = 400 / 10 = 40 mA, which is more than a typical pin can supply and too much for a 2N2222’s comfort at this load. Better: use a logic-level N-channel MOSFET (gate current almost zero), a 100 Ω gate resistor, a 10 kΩ pull-down, and a flyback diode across the motor. If you still want a BJT, use a Darlington or a small driver stage.

Can You Explain It?

Close the lesson and answer these without looking back. The goal isn't the wording — it's whether you've formed a usable mental model.

  • Explain cutoff, active and saturation and which ones a switch uses.
  • Show how to choose a base resistor using forced beta.
  • Describe how a logic-level MOSFET differs and how to calculate its heat loss.

🧪 Want to practise this on your own computer? See how to set up your lab →

🤖

Need clarification? Ask GT

Hi, I'm GT — your AI tutor for Transistors as Switches. What would you like to know?
📝

Knowledge Check

1 of 4

Why do we use a transistor to drive a relay coil from a microcontroller pin?

Official References

Report a problem

About: /lessons/efc-transistors-as-switches