Every way to drive a load from a pin
Straight from the pin, through a BJT or a MOSFET, through a relay, or through a driver chip. The load's current, its supply and whether it is a coil decide which.
Start with two numbers: how much current the load needs and what voltage it runs on. Then ask whether it is a coil (a motor, a relay, a solenoid), because a coil kicks back when it switches off.
- A few milliamps at the board's own voltage (an indicator LED, a module's input) → drive it straight from the pin, with a series resistor where the part needs one. Stay well under the pin's limit: 8 mA per pin on the Uno R4 Minima.
- More current, or a higher supply, switched on and off → a low-side switch. A small NPN BJT is fine to a few tens of milliamps, as long as its base current fits the pin; for anything bigger use a logic-level N-channel MOSFET, one whose datasheet promises it fully on at your pin's voltage (3.3 V or 5 V).
- A load on a separate circuit, or one that must be isolated → a relay, driven through a transistor with a flyback diode across the coil, or a solid-state relay whose output type (AC or DC) matches the load.
- A motor that must reverse, brake or change speed → a motor driver IC (an H-bridge), on its own supply with a shared ground. Servos, steppers and addressable LED strips each take their own signal format, but still get their power from a separate supply, never from the pin.
- Not enough pins → a 74HC595 shift register gives eight outputs from three pins, within its own per-pin and total limits.
Every coil gets a flyback diode, every separate supply shares a ground with the board, and every limit you design to is the working figure, never the absolute maximum.
Straight from the pin
Section
GPIO is not a power supply
Per-pin and total current limits, and why a coil on a pin can reset or damage the board.
Section
LEDs and current limiting
The one load a pin drives directly every day, sized with R = (V_s - V_f)/I and rounded up to E12.
Example
A transistor switch
Section
The transistor as a switch
An NPN low-side switch, with the base current a tenth of the load current and the base resistor rounded down.
Section
MOSFETs
A logic-level N-channel MOSFET with a gate resistor and a gate pull-down; the threshold is not "fully on".
Term
saturation
A relay
Section
Relays and solid-state relays
A coil driven through a transistor, its contact ratings, and when a solid-state relay fits better.
Section
Inductors and kickback
Why a coil's current can't stop instantly, and the spike that follows.
A driver for motors and strips
Section
Driving motors safely
A separate motor supply, the bulk capacitor, the H-bridge's four useful states and shoot-through.
Section
DC motors and drivers
A driver IC such as the DRV8833, read from its truth table, with speed set by PWM.
Section
Servos
The pin sends only a pulse every 20 ms; the servo's power comes from its own supply.
Section
Stepper motors
A ULN2003A or a STEP/DIR driver between the pin and the coils.
Section
Addressable LEDs
One data wire from the pin, a separate 5 V supply for the strip, and a level shifter from a 3.3 V board.
Term
H-bridge
More outputs than pins
Section
Shift registers for more pins
Eight outputs from three pins with a 74HC595, within its per-pin and total current limits.