Electronics / Theory / Transistors
Theory 05

Transistors A small signal controlling a large current. Used at the extremes — fully off or fully on — it is a switch, and that is the version you need first: the thing that lets a 20mA microcontroller pin drive a motor, a relay or a strip of LEDs.

needs Resistors, Diodesbase resistor calculator
Tier 0 · Groundtwo families

BJT and MOSFET

Module 0.1

Current-controlled vs voltage-controlled

The distinction that decides which one you buy
BJT (2N3904, BC547)MOSFET (IRLZ44N, AO3400)
TerminalsBase, Collector, EmitterGate, Drain, Source
Controlled byBase currentGate voltage
Control currentContinuous, ~1/100 of loadAlmost none once switched
Loss when on~0.2V drop (Vce_sat)Very low resistance (Rds_on)
Good forSmall loads, simple, forgivingReal current, efficient
Watch out forNeeds a base resistor, gain variesMust be logic-level for 3.3V/5V gates

Both come in two polarities. NPN / N-channel switch the ground side of a load (low-side switching) and are the easy, common case. PNP / P-channel switch the positive side (high-side), which is more awkward to drive from a microcontroller and is best left until you need it.

Module 0.2

The low-side switch

The circuit to internalise
+5V │ [ LOAD ] (relay, motor, LED strip) │ ├──────▶|─┐ flyback diode, cathode to +5V │ C │ pin ─[R]─B NPN │ R = base resistor │ E │ GND ───────┘

Everything in that diagram earns its place:

  • The base resistor limits current into the base. Without it, the base-emitter junction is effectively a forward-biased diode across your output pin, and one of the two will die.
  • The flyback diode absorbs the reverse spike when an inductive load switches off. Non-negotiable for relays, motors and solenoids.
  • The common ground between the microcontroller and the load supply. The transistor switches the ground path; without a shared reference nothing works.
Why not drive the load directly? A microcontroller pin supplies roughly 20mA, and the whole chip has a combined limit too. A small DC motor draws hundreds of milliamps at start-up. Connect one directly and the best case is a brownout reset; the usual case is a dead pin.
Tier 2 · Choosesizing

Getting the values right

Module 2.1

Sizing the base resistor

Saturation, and why you deliberately overdrive
// switching 60mA with hFE (gain) around 100
I_base minimum = 60mA / 100 = 0.6mA
// drive 5-10x harder to guarantee full saturation
I_base chosen  = 5mA
R_base = (V_pin − 0.7) / 0.005 = (3.3 − 0.7) / 0.005 = 520Ω -> 470Ω

The 0.7V is the base-emitter drop, essentially fixed for silicon. Overdriving ensures the transistor is fully saturated — behaving like a closed switch with a small voltage drop — rather than partly on and dissipating the difference as heat. Datasheet gain figures are quoted at a particular current and vary enormously between individual parts, so designing at exactly the minimum is asking for a transistor that runs warm and switches unreliably.

Base resistor calculator

Module 2.2

Choosing a MOSFET

The logic-level trap

MOSFETs are voltage-controlled, so the gate draws essentially no steady current and a good one has very low on-resistance — far more efficient for real loads. Three specifications decide the choice:

  • V_GS(th) and the R_DS(on) test condition. This is the trap. A classic IRF540 needs about 10V on the gate to turn fully on; driven from a 3.3V pin it is barely conducting, runs hot, and behaves confusingly. You want a part explicitly specified with R_DS(on) measured at V_GS = 2.5V or 4.5V — that is what "logic-level" means. The IRLZ44N and AO3400 are common logic-level choices.
  • R_DS(on) — the on-resistance. Multiply by your load current squared for the heat: 0.02Ω at 2A is 0.08W, negligible. The same 2A through 0.5Ω is 2W and needs a heatsink.
  • Current and voltage ratings — with the usual generous margin, and remembering motors draw several times their running current at start-up.

Two practical additions: a gate resistor of 100–220Ω limits the current spike as the gate capacitance charges, and a 10kΩ pull-down from gate to ground keeps the MOSFET off while the microcontroller boots and its pins are still floating. Without the pull-down, motors twitch on power-up.

Drill 1

You drive an IRF540 MOSFET from a 3.3V pin to switch a 12V LED strip. It works, but the MOSFET gets very hot. Why?

Not logic-level. Its R_DS(on) is specified at V_GS = 10V; at 3.3V it is in the linear region rather than fully switched, so it drops significant voltage while passing full current — and that product is heat. It works well enough to be misleading, which is what makes this such a common trap. Swap to a logic-level part such as an IRLZ44N, or add a gate driver. An LED strip is resistive so flyback is not the issue here.
Tier 4 · Faildiagnosis

When it does not switch

Module 4.1

A diagnostic sequence

Four measurements, in order
1Measure the control voltage at the base/gate itself, not at the microcontroller pin. If it is not what you expect, the problem is upstream.
2Measure collector-emitter (or drain-source) voltage while on. It should be small — under ~0.3V for a saturated BJT. A large drop means it is only partly on.
3Check the pinout against the datasheet for that exact package. TO-92 pin orders differ between part families, and a swapped pair is the single most common wiring error here.
4Confirm the grounds are common between control and load supplies.

Failure modes: transistors usually fail shorted, so the load stays permanently on — an alarming but informative symptom. If your motor runs the instant power is applied and ignores the control signal, suspect a destroyed transistor and look for the missing flyback diode that killed it.

Referencesearchable

Glossary