The problem a transistor solves
Output pins on a microcontroller or logic chip are meant to carry signals, not power. Each pin can typically supply only a small current, often tens of milliamps at most, and exceeding the limit can damage the chip. Many useful loads need far more: motors, relays, buzzers, lamps and LED strips. A transistor bridges the gap. A small current or voltage at its control terminal lets a much larger current flow through the other two terminals.
Work at low voltage when learning, such as a battery or small regulated supply. A transistor switch is not a safe way to experiment with mains voltage, and mains-powered devices should be handled only by someone qualified. Wear eye protection, since a part that is overloaded can overheat.
The basic idea
Think of the transistor as an electrically operated switch with three terminals. The load current flows between two of them. The third is the control. Apply the right signal to the control and the switch closes, and remove it and the switch opens.
Two main families appear in hobby work.
Bipolar junction transistors (BJTs). The control terminal is the base. A small current into the base allows a larger current from collector to emitter. The ratio of the two is called gain, and it varies from part to part, so a good design does not depend on a precise value. The usual practice is to supply enough base current to drive the transistor firmly on, called saturation.
MOSFETs. The control terminal is the gate, and it is controlled by voltage, not current, so it draws almost no steady current. What matters is that the gate voltage is high enough to turn the device fully on. Some MOSFETs need much more than the 3.3 or 5 volts a microcontroller supplies, while “logic-level” types are designed to work at those levels. Check the datasheet.
A typical low-side switch
The most common arrangement places the transistor between the load and ground, so it is called a low-side switch.
- One side of the load connects to the positive supply.
- The other side of the load connects to the transistor’s collector (or drain).
- The emitter (or source) connects to ground.
- The control signal from the microcontroller goes to the base through a resistor, or to the gate.
When the signal goes high, the transistor conducts, current flows through the load to ground, and the load turns on. When the signal goes low, the transistor stops conducting and the load turns off.
The base resistor
With a BJT, the base must not be connected directly to a signal pin. The base-emitter junction behaves like a diode, and without a resistor the current would be limited only by the pin, which could damage it. A resistor in series sets the base current.
A hypothetical example with checked arithmetic: suppose the load needs 100 mA, and the transistor is assumed to have a gain of at least 100 in saturation. A conservative rule is to supply a base current of roughly a tenth of the load current, so 10 mA. If the pin outputs 5 volts and the base-emitter drop is about 0.7 volts, the resistor sees 4.3 volts. 4.3 / 0.01 = 430 ohms, so a nearby standard value such as 470 ohms gives about 9 mA. Real parts differ, so use the datasheet and test.
For a MOSFET, a small series resistor at the gate is often used to limit surge current, and a larger resistor from gate to ground keeps the gate from floating when the controlling pin is not driving it. That ties into the topic of floating inputs, since an undriven gate can pick up noise and turn the load on at random.
Inductive loads and the flyback diode
Motors, relays and solenoids are coils. When current through a coil is switched off, the coil can generate a brief voltage spike many times larger than the supply. That spike can destroy the transistor. A diode placed across the coil, with its cathode toward the positive supply, gives the current a safe path. The diode is part of what the passive components article describes. For small motors and servos, there are other considerations such as stall current and noise, which are covered separately.
Matching the transistor to the load
Check these ratings before choosing a part:
- Maximum collector (or drain) current, which should be comfortably above the load current.
- Maximum voltage, which should exceed the supply voltage with margin.
- Power dissipation. A transistor that is only partly on gets hot. A MOSFET that is fully on has low resistance, and its heat depends on the current squared times that resistance.
- Gate threshold, for MOSFETs. Make sure it is fully on at your logic voltage.
If the load draws substantial current, a heat sink or a different part may be needed. If the part gets hot, switch off and reassess.
Common mistakes
No shared ground. If the load supply and the controller have separate supplies, their grounds should be joined, or the transistor sees no reference.
Missing base resistor. This can damage the signal pin or the transistor.
Wrong pin order. Transistor packages vary. Look up the pinout rather than assuming.
MOSFET not fully on. A part that is only partly on gets hot and delivers less power to the load.
Forgetting the diode on a coil. The circuit may work for a while and then fail.
Power drawn from a small regulator. Heavy loads should not be run from a board’s built-in regulator. Use a suitable separate supply, as discussed in the notes on choosing a project power supply.
When to use something else
A relay or a ready-made driver module may suit certain jobs, such as isolating a controller from a load. Relays that switch mains voltage are not a beginner project, and a qualified professional should do that wiring. For ordinary low-voltage loads, though, a single transistor, a resistor and a diode are often all you need.