A valve controlled by a trickle
A transistor is a three-terminal part in which a small electrical signal at one terminal controls a much larger flow between the other two. The best everyday comparison is a tap with a very light handle: a gentle touch on the handle regulates a strong flow of water.
This is why transistors matter so much. A microcontroller pin can supply only a small current, typically enough for an LED or a signal line and not for a motor, a strip of LEDs or a relay coil. A transistor lets the pin act as the gentle touch, while the heavy current flows through a separate path from a separate supply.
Everything below applies to low-voltage hobby circuits. Check the ratings in the datasheet for any part you use.
The two common families
Makers mostly meet two kinds.
Bipolar junction transistors (BJTs). Three terminals called base, collector and emitter. A small current into the base allows a larger current to flow from collector to emitter. They are controlled by current.
MOSFETs. Three terminals called gate, drain and source. A voltage on the gate controls the flow from drain to source, and the gate draws almost no steady current. They are controlled by voltage.
Each comes in two polarities, such as NPN and PNP for bipolar types, and N-channel and P-channel for MOSFETs. The polarity decides whether it switches on the ground side or the supply side of the load. For beginners, switching the ground side with an NPN transistor or an N-channel MOSFET is the most common arrangement.
Using a transistor as a switch
In switching use, the transistor is meant to be either fully off or fully on, avoiding the in-between region.
- Off. No control signal, so almost no current flows through the load.
- On. A sufficient control signal turns the transistor fully on, and it behaves like a closed switch, with a small residual voltage drop across it.
A typical arrangement puts the load between the supply and the transistor, and the transistor between the load and ground. The control pin drives the base or gate.
With a bipolar transistor
A resistor goes between the pin and the base. Without it, the base-emitter junction behaves like a diode, and the pin could source far more current than it should. The resistor sets the base current. To switch properly, the base current has to be enough for the load current, with a margin, using the transistor’s current gain from its datasheet. Gain varies from part to part, so the usual approach is to be generous rather than precise.
With a MOSFET
The gate needs a suitable voltage. The key detail is that many MOSFETs need a gate voltage well above what a 3.3 V pin can supply to turn fully on. Parts described as logic-level are designed to turn on at lower gate voltages, and the datasheet shows the gate voltage at which the on-resistance is specified. A MOSFET that is only half on can get hot, because it then acts as a resistor carrying real current.
A resistor from gate to ground keeps the gate from floating when the pin is not driving it, which is the same idea as pull-down resistors, and a small series resistor at the gate is also commonly used to tame fast edges.
Loads that fight back: coils and motors
Relays, solenoids and motors are inductive. When current through them is switched off, they produce a voltage spike in the opposite direction, which can exceed the supply and damage a transistor.
The common protection is a flyback diode placed across the load, pointing so that it does not conduct in normal operation but gives the stored energy somewhere to go when the transistor turns off. Breakout boards and driver chips often include this, so check before adding another. For motors specifically, dedicated motor drivers combine switching, protection and direction control in one package, and are the sensible next step when the simple single transistor is not enough.
Using a transistor as an amplifier
If the transistor is left partway on, in its in-between region, the output varies smoothly with the input. A small change in base current causes a larger change in collector current, so a weak signal can be made stronger. This is analog amplification, and it is the basis of audio stages and sensor front ends.
Amplifier designs need more care than switching ones. The transistor must be biased: set to a steady operating point by resistors so that the signal can swing up and down around it without being cut off. Gain, distortion, temperature drift and stability all enter the picture.
For many hobby projects, a ready-made amplifier chip or an operational amplifier is easier and more predictable than building discrete stages. Still, understanding that the same device does both jobs, depending on how it is biased, is a useful idea. The conversion of weak sensor voltages into something a converter can read ties in with how analog digital signals are handled.
Quick selection guidance
When choosing a part for a switching job, check these items in its datasheet, rather than trusting a name or a guess:
- Maximum voltage the part can withstand across it
- Maximum continuous current, with margin
- For a MOSFET, the gate voltage at which it is fully on, compared with your pin’s logic level
- For a bipolar part, the current gain at the load current you need
- Power dissipation and whether it needs a heat sink
- Package, and whether it fits your breadboard or board
Reading datasheets takes practice, but the table of absolute maximum ratings and the on-state characteristics will answer most of these questions.
Common problems
- Load never switches fully on: MOSFET gate voltage too low, or too little base current.
- Transistor runs hot: it is only partly on, the current exceeds its rating, or it needs a heat sink.
- Load stays on at start-up: a floating control pin; add a resistor to hold it off.
- Chip resets when a motor starts: supply sag or spikes from the inductive load; separate supplies, a flyback diode and capacitors may help.
- Nothing works at all: terminals connected in the wrong order. Pinouts differ between packages, so check the datasheet.
Grounds and safety
When the load has its own supply, join the grounds of the two supplies so the control signal has a shared reference. Keep wiring and current ratings in mind, and avoid using a transistor to switch mains voltage on a hobby board. That belongs to purpose-made, certified equipment installed by a qualified person. For batteries and larger currents, follow manufacturer guidance and local rules.