Use the diode equation and bias an NPN transistor as a saturated switch for a load driven from a microcontroller pin.
Why it matters
Diodes and transistors are the building blocks of every power supply, amplifier and digital chip. The most common job you will give a discrete transistor is the simplest: letting a 3.3 V microcontroller pin switch a load (an LED string, a relay coil, a small motor) that needs more current than the pin can supply. Getting the bias right is the difference between a cool, reliable switch and a hot, half-on part.
Diodes
A diode conducts easily in one direction (anode to cathode) and blocks the other. The Shockley diode equation describes the forward current:
I = I_s * (exp(V / (n * V_T)) - 1)
V_T = k T / q = 25.85 mV at 300 K
I_s is a tiny saturation current (around 1e-14 A for a small silicon diode) and n is between 1 and 2. Because the current is exponential, a silicon diode's voltage stays near 0.6 to 0.7 V over a wide range of currents. With n = 1, every extra 60 mV multiplies the current by about 10: I_s = 1e-14 A gives 0.12 mA at 0.60 V and 1.2 mA at 0.66 V.
Useful diode types:
- Rectifier diodes turn AC into pulsing DC in power supplies.
- LEDs drop more voltage (about 1.8 to 2.2 V for red, about 3 V for blue and white) and need a series resistor to set current.
- Zener diodes are used in reverse at a defined breakdown voltage as simple references.
- Schottky diodes have a lower forward drop (about 0.3 V) and switch fast.
- Flyback diodes go across relay coils and motors to absorb the voltage spike when the current is switched off. Leaving one out is a classic way to destroy a transistor.
The bipolar transistor (NPN)
A small base current controls a much larger collector current. In the active region, I_C = beta * I_B, with beta (also called h_FE) somewhere from 50 to 300 and varying widely between parts. That is what amplifiers use.
For a switch we want the opposite: drive the transistor hard into saturation, where it acts like a closed contact with only V_CE(sat) (about 0.1 to 0.3 V) across it. Designers use a forced beta of about 10, meaning they supply ten times less than the load current as base current, far more than the minimum I_C / beta, so the switch stays saturated for any part from the bin.
Worked example: an LED switched from a 3.3 V pin
A 5 V supply drives an LED (2.0 V drop) through a 150 Ω resistor and an NPN transistor (V_CE(sat) = 0.2 V). The base is driven from a 3.3 V GPIO pin through R_B, and V_BE is about 0.7 V.
I_C = (5.0 - 2.0 - 0.2) / 150 = 18.7 mA
I_B (forced beta 10) = 18.7 mA / 10 = 1.87 mA
R_B = (3.3 - 0.7) / 1.87 mA = 1,393 Ω -> use 1.2 kΩ (next standard value down)
P_transistor = 0.2 V * 18.7 mA = 3.7 mW
Choosing the next value down gives a little more base current, which keeps the transistor saturated. Check that the pin can supply about 2.2 mA (most can; the datasheet gives the limit).
MOSFETs
For larger currents, a logic-level N-channel MOSFET is often the better low-side switch. Its gate draws almost no steady current, and when fully on it behaves like a small resistance R_DS(on), so it dissipates P = I^2 * R_DS(on). Check that the datasheet specifies R_DS(on) at your gate voltage (for example 2.5 V or 4.5 V), because "threshold voltage" is only where it barely starts to conduct.
Simulate it
Build the LED switch in Falstad (https://www.falstad.com/circuit/) or LTspice: sweep the base resistor and watch V_CE rise when the transistor leaves saturation. Simulators make it safe to see what too little base drive or a missing flyback diode does. Every hands-on task in this course uses paper, Python or a free simulator (Falstad, LTspice or ngspice). Never build or probe circuits connected to mains (wall outlets, appliances, panels) or utility equipment.
Common mistakes
- Designing a switch with the typical beta instead of a forced beta, so some parts never saturate.
- No base resistor, which overloads both the pin and the base-emitter junction.
- No flyback diode on inductive loads.
- Picking a MOSFET by its threshold voltage rather than
R_DS(on)at the actual gate drive. - Forgetting power: at 1 A, a
V_CE(sat)of 0.3 V means 0.3 W to get rid of.
Recap
- Diode current is exponential in voltage; silicon sits near 0.6 to 0.7 V.
- As a switch, saturate the BJT with forced beta about 10:
R_B = (V_drive - V_BE) / (I_C / 10). - Use flyback diodes on coils; consider logic-level MOSFETs for higher currents.
Try it
Open the Do tab to code the diode equation and the transistor-switch design calculation.