NPN transistor with a glowing collector wire arcing to a small motor

The Transistor as a Switch: NPN Basics for Makers

An NPN transistor works as a switch by letting a small current into its base terminal control a much larger current flowing from collector to emitter, so a microcontroller pin that can only supply 20mA can switch a load that needs hundreds. Wire the load between the positive supply and the collector, tie the emitter to ground, and feed the base through a resistor from a digital pin. Pin HIGH pushes a few milliamps into the base, the transistor turns fully on (saturates), and current flows through the load as if a switch closed. Pin LOW, and the load turns off. That one trick, small current commanding big current, is the foundation of every driver circuit you will ever build.

Why a pin cannot drive the load directly

An Arduino Uno R3 pin is designed for signals, not power. It can source or sink about 20mA comfortably, 40mA at the edge of damage. A bright LED strip segment wants 100mA. A small DC motor wants 200mA to 1A. A relay coil wants 70mA. Connect any of these straight to a pin and the pin voltage sags, the chip heats, and sooner or later that pin (or the whole port) dies. The transistor stands between: the pin supplies the whisper, the transistor handles the shout.

Meet the NPN

A bipolar junction transistor (BJT) has three legs: base, collector, emitter. In the NPN flavour, the everyday rules are simple. Current flows collector to emitter only when current also flows base to emitter. The base needs about 0.7V above the emitter to conduct at all; below that, the transistor is off. And the collector current is a multiplied copy of the base current, up to a limit: the gain, written hFE or β, is typically 100 to 300 for small transistors like the BC547 or 2N2222.

For switching, you do not use the gain region delicately. You overdrive the base so the transistor saturates, meaning it conducts as hard as it can and the collector-emitter voltage falls to about 0.2V. Saturated means cool: little voltage across it times the load current equals little heat in the transistor.

The standard low-side switch

The circuit to memorise: load from +supply to collector; emitter to ground; base resistor from the control pin to base. It is called low-side switching because the transistor sits on the ground side of the load. The load's positive supply can be higher than the microcontroller's 5V (a 12V fan, say) as long as the grounds are connected, because the base only cares about its 0.7V relationship with the emitter, which is at ground.

If the load is inductive, a motor or a relay coil, add a flyback diode across it (cathode to positive). Inductors object violently to being switched off, and the diode gives the objection somewhere safe to go. That story gets its own article.

Worked example: base resistor for a 100mA load

Say a BC547 switches a 100mA load from a 5V pin. Design for saturation with a base current of about a tenth of the collector current, so 10mA of base drive:

  • Voltage available to push base current: 5V pin minus 0.7V base drop = 4.3V
  • Base resistor: 4.3V ÷ 10mA = 430Ω, so use 470Ω from a resistor variety pack

Assemble on a 400-point breadboard: load positive rail to the load, load to collector, emitter row jumpered to GND, 470Ω from pin 8 to base, all with Dupont jumper wires. digitalWrite(8, HIGH) and the load runs; LOW and it stops. You can even PWM the pin and the transistor chops the load current for speed or brightness control. Check the BC547's limit though: 100mA is its ceiling. For 500mA reach for a BD139 or a MOSFET.

Where this bites you

Mistake one: no base resistor. The base-emitter junction is a diode; connect it straight to a 5V pin and it clamps at 0.7V while the pin tries to force unlimited current through it. Result: a hot transistor, a stressed pin, sometimes both dead. Always a base resistor, 220Ω to 1kΩ for hobby loads.

Mistake two: high-side wiring with an NPN. Put the load between emitter and ground (load on the bottom, transistor on top) and the emitter rises to nearly the load voltage when conducting. The base then needs 0.7V above that, which a 5V pin cannot supply for a 12V load, so the transistor half-conducts, drops volts across itself, and cooks. NPN goes on the ground side. High-side switching wants a PNP or P-channel MOSFET.

Mistake three: swapping collector and emitter. The transistor sort of works in reverse, with terrible gain, which produces the most confusing half-working circuits imaginable. Check the pinout for your exact part; BC547 and 2N2222 pinouts differ even though the packages look identical.

FAQ

How do I know if my transistor is saturated?

Measure collector-to-emitter voltage while the load is on. Around 0.2V or less means saturated and healthy. A volt or more means the base drive is too weak; the transistor is dropping real power as heat. Lower the base resistor value.

NPN vs PNP: which do I buy?

For switching grounded loads from a positive-logic pin, NPN is the default and covers most maker jobs. PNP switches the positive side and turns on when its base is pulled low. Start with a handful of NPNs; add PNPs when a circuit forces high-side switching on you.

Can a transistor switch 230V mains?

Not a small BJT, and you should not try direct mains switching on a breadboard at all. Mains loads are switched through relays or opto-isolated solid-state modules, where your transistor drives the relay coil and the mains side stays physically separated from your low-voltage circuit.

When a project needs a motor, pump, or LED array switched safely, Compoden's AI build assistant Soldr can put the right driver stage into your wiring plan automatically.

Back to blog