Learn

An NPN transistor switch, simulated

Beginner

Or see every lesson.

  • 261parts on the bench
  • 31boards running now
  • 1.00xreal time, on every board
An NPN transistor switchlive0.000 s 0.00x
Press Run, then click the slide switch
A slide switch drives the base of a 2N2222 through 1 k, and the transistor switches an LED. Press Run, then click the switch.

A transistor switch is how a small signal turns on something that needs more current than the signal can give: an LED from a pin, a relay, a motor, a buzzer. An NPN bipolar transistor has three legs. Current into the base, returning through the emitter, lets a much larger current flow from the collector to the emitter.

The circuit above is a 2N2222 with an LED and a 220 ohm resistor from 5 V to its collector, its emitter to ground, and its base fed from a slide switch through a 1 k resistor. Slide the switch to 5 V and the LED comes on. Slide it back and it goes off.

The base resistor matters. The base-emitter junction is a diode, and 5 V straight across it would push as much current as the supply can give. Through 1 k it takes about (5 - 0.7) / 1000, a little over 4 mA. The LED wants around 13 mA, and with a current gain well above ten that base current is more than enough, so the transistor is driven hard into saturation: fully on, with only a small voltage left from collector to emitter.

This is simulated, not animated. The transistor is an Ebers-Moll model with forward and reverse current gains and an Early voltage, solved by Newton-Raphson along with the rest of the circuit, so the numbers are the model’s own. Press Shift+O with the switch on and the DC operating point labels every net: about 0.7 V on the base, and a collector only a few tenths of a volt above ground. Click the transistor and the properties panel shows its base and collector currents.

Now break it on purpose. Change the base resistor to 100 k. The base current falls to about 43 microamps, the transistor can no longer pull the LED’s whole current, and the LED dims. The transistor has left saturation and is working as an amplifier, with the collector current set by the base current rather than by the LED and its resistor. That middle region is exactly what a switch is meant to stay out of, and seeing it once makes the rule about base resistors stick.

Swap the 2N2222 for a BC547 or a TIP120 Darlington in the properties panel and compare how much base current each one needs.

Questions

What base resistor should I use for a transistor switch?

Work out the collector current, divide by a forced gain of about ten for a solid switch, and size the resistor for that base current from your drive voltage less about 0.7 V. For 13 mA from a 5 V pin, about 1 k is comfortable.

Does Mokxi simulate transistors or just show them?

It simulates them. A bipolar transistor is an Ebers-Moll model solved with the rest of the circuit, so its currents and voltages, saturation included, come from the model rather than from a fixed drop somebody typed in.

Build this for real

Open the editor, change a value and watch the number move with it. Nothing to install, and no account needed.