Learn & build · Electronics · Chapter 4

Diodes and transistors

Resistors, capacitors and coils only ever react to what you do to them. This chapter's parts make decisions. A diode lets current flow one way and not the other. A transistor lets a tiny signal, like a 3.3 V pin on a microcontroller, switch a big current, like a motor's, or copy a small wiggle as a big one. Every chip in every computer is billions of transistors doing exactly the switching you'll do below.

In plain words: a diode is a one-way valve (a check valve) for current: forwards it opens once you push past about 0.7 V, backwards it stays shut. A MOSFET transistor is a tap with a handle: the gate is the handle, and turning it takes almost no effort, while the water through the tap can be a flood. Open the tap fully and it's a switch; hold it part way and the flow follows your hand: an amplifier.

1. A one-way valve

Push current through a diode with the battery, then flip the battery around.

The curve on the right is the diode's whole personality: almost nothing flows until about 0.6 V, then a little more voltage brings a lot more current. That's why the voltage across a conducting silicon diode is nearly always 0.6–0.8 V, whatever the current, and why chapter 1's LED (a diode that glows) needed a resistor. Backwards, it blocks.

The math, step by step

The same Shockley equation as chapter 1's LED, \(I = I_s(e^{V/(nV_T)} - 1)\), with a silicon diode's much larger \(I_s\) (about \(10^{-14}\) A) and \(n \approx 1\). Solve it for the voltage:

\[ V = n V_T \ln\!\left(\frac{I}{I_s} + 1\right) \]

A logarithm grows very slowly: 1 mA gives about 0.60 V, 10 mA 0.66 V, 100 mA 0.72 V. Each ten times more current adds only \(nV_T \ln 10 \approx 60\) mV. That's why "a silicon diode drops 0.6–0.7 V" is such a good rule over a thousand-fold range of currents.

With \(n = 1\) and \(V_T = 26\) mV, how much more voltage does a diode need for 10× the current? (mV)

\(26 \times \ln 10 = 26 \times 2.303 \approx 60\) mV.

🎯 Challenge: push exactly 10 mA forwards through the diode (within 0.3 mA).

2. Turning AC into DC

The wall socket gives alternating current: a sine wave that goes positive, then negative, 60 times a second. Electronics want steady DC. One diode keeps only the positive halves (a rectifier). Then a capacitor from chapter 2 fills up on each bump and keeps the load going between them.

The leftover wobble is called ripple. A bigger capacitor, or a lighter load, makes it smaller. Your phone charger does this (with four diodes, a "bridge", to use both halves of the wave), then a switching regulator cleans up the rest.

The math: sizing the smoothing capacitor

Between peaks the capacitor alone feeds the load current \(I\) for about one period \(1/f\) (half-wave) and sags by \(\Delta V = Q/C = I/(f C)\):

\[ V_{\text{ripple}} \approx \frac{I}{f\, C} \quad (\text{half-wave}), \qquad \frac{I}{2 f C} \quad (\text{bridge}) \]

100 mA from 60 Hz with 1000 µF: \(0.1 / (60 \times 0.001) = 1.67\) V of ripple, half that with a bridge. That's why mains supplies use big electrolytic capacitors, and why a bridge rectifier is the default.

The formula assumes the ripple is small next to the output, so the load's current hardly changes. With a 12 V peak into 100 Ω (about 110 mA), this page's solver gives 0.37 V of ripple with 4700 µF (formula: 0.39 V) and 1.57 V with 1000 µF (1.83 V). With 220 µF it gives 5.2 V where the formula says 8.3 V: the output sags so far that the load draws less current.

A bridge rectifier at 60 Hz, 1000 µF, 100 mA load. Ripple, in volts?

\(0.1 / (2 \times 60 \times 0.001) \approx 0.83\) V. The bridge refills the capacitor twice per cycle.

🎯 Challenge: get the ripple below 10% with the 1 kΩ load.

3. A MOSFET switches a motor

A microcontroller pin can only give a few milliamps at 3.3 V; a motor wants an amp at 12 V. A MOSFET joins them. It has three legs: the gate (the handle), the drain (the load's current comes in here) and the source (it leaves here, to ground). The pin drives the gate, and the motor's current goes from drain to source. This is an N-channel MOSFET, turned on by raising its gate above its source; a P-channel one is its mirror image, turned on by pulling the gate below the source, and chapter 12 pairs one of each. Turn the pin on and off, then try PWM: switching it on and off fast, where the fraction of time it's on sets the speed.

The motor is a coil (chapter 3), so every time the MOSFET switches off, the coil's current needs somewhere to go. With the flyback diode it loops back through the motor. Untick it and watch the drain voltage spike: the MOSFET's own breakdown ("avalanche") absorbs the energy, rated at around 40 V here, and enough of those hits kill it.

The math: PWM and heat in the switch

Switching on for a fraction \(D\) (the duty cycle) of each period gives the motor an average voltage \(D \cdot V\): 25% of 12 V acts like 3 V. Because the motor's coil smooths the current (chapter 3), it sees a steady average, not the pulses.

When fully on, a MOSFET acts like a small resistance \(R_{DS(on)}\), and it heats by \(P = I^2 R_{DS(on)}\). 2 A through 0.05 Ω is 0.2 W: barely warm. The danger is the half-on state, next section.

A fully-on MOSFET with \(R_{DS(on)} = 0.05\) Ω carries 2 A. How much heat?

\(I^2 R = 4 \times 0.05 = 0.2\) W.

🎯 Challenge: run the motor at about half speed (40–60% of full current) with PWM.

4. Why your 3.3 V chip needs a "logic-level" MOSFET

The gate has a threshold: below it the MOSFET is off, a little above it it's only half on, and it needs a few volts more to switch fully on. A half-on MOSFET is a resistor carrying the full current, and it gets hot (power = voltage across it × current). Pick a MOSFET and a gate voltage.

🎯 Challenge: from an ESP32's 3.3 V pin, switch the full 1 A load with the MOSFET wasting under 0.1 W.

That's the whole trick of a transistor switch: fully off or fully on, never in between, and nothing gets hot.

A MOSFET is half on: 6 V across it and 1 A through it. Fully on, 0.05 V across it at the same 1 A. How do the heats compare?

\(6 \times 1 = 6\) W, enough to burn a small package without a heatsink, against \(0.05 \times 1 = 0.05\) W. Fully on or fully off, never in between.

5. Half on, on purpose: a transistor that amplifies

Section 4 said never to leave a transistor half on. Yet a hi-fi amplifier (chapter 16) and a linear regulator (chapter 10) keep theirs half on all the time, on purpose. What could the in-between be good for?

Meet the other transistor family, the bipolar junction transistor (BJT), like the 2N3904 in every starter kit. Its legs are the base (the handle), the collector (the load's current comes in) and the emitter (it leaves, to ground). Base to emitter is a diode, with section 1's curve: below about 0.6 V nothing happens. Above it, a small current into the base lets a current about β ("beta", 200 for this one) times bigger flow from collector to emitter. Here an input voltage feeds the base through 47 kΩ, and the load is 1 kΩ from 9 V. Slide the input slowly from 0 and watch the output (the collector's voltage).

Predict before you add the wiggle. Set the input to 1.6 V. The wiggle moves the input 0.1 V up and down. How far up and down will the output move? (volts)

About 0.41 V, four times the input's wiggle, and upside down: input up, output down. Pick the ±0.1 V wiggle and see. That's amplification: the same shape, bigger, paid for by the 9 V supply, not by the input.

The curve has three parts, and you've now been in all of them:

A MOSFET has the same middle region (section 4's half-on), set by its gate voltage instead of a base current. Switching circuits (logic, PWM, motors) live at the two ends, where nothing gets hot; amplifiers, linear regulators and oscillators live in the middle and pay for it in heat. A PNP transistor is the BJT's mirror image, turned on by pulling its base below its emitter.

A transistor is a valve worked by a small signal. Fully on or fully off, it's a switch that stays cool; in between, it's an amplifier that copies a small wiggle as a big one, and it gets warm.

🎯 Challenge: with the ±0.8 V wiggle, find an input where the output swings its full 3 V or more both ways, without either tip being flattened (clipped).

Why is the gain about 4?
  1. In the middle region the base sits near 0.65 V and barely moves (section 1: ten times the current adds only 60 mV).
  2. So the 47 kΩ resistor has \(V_{in} - 0.65\) across it, and the base current is \(I_B \approx (V_{in} - 0.65)/47\,\text{k}\Omega\). Raising the input by 0.1 V adds about 2.1 µA.
  3. The collector current is β times that: \(200 \times 2.1\) µA = 0.43 mA more.
  4. That extra current drops 0.43 V more across the 1 kΩ load (Ohm's law), so the collector, at 9 V minus that drop, falls by 0.43 V.
  5. In one line: gain \(\approx -\beta \, R_{load} / R_{base} = -200 \times 1/47 \approx -4.3\). The solver gets −4.1, because the base voltage does creep up a little.
Where it breaks: every transistor has a different β

The gain above has β in it, and β is a poor number to build on: the 2N3904 datasheet allows anything from 100 to 300 (at 10 mA), and it drifts with temperature. Solving this same circuit at 1.6 V in with three β's:

Two transistors from the same bag give amplifiers that differ threefold, and the high-β one sits so close to saturation that a big wiggle clips. Real designs fix this with feedback, trading some gain for a result set by resistors instead of by β: chapter 7 does exactly that with op-amps.

Next: real parts: reading color codes and datasheets, and choosing values and ratings that survive the real world.

Previous: Coils, resonance and antennas · All chapters: Learn & build · Try things in the circuit lab.

Last updated