Electronics notes/General actuator notes, circuit protection
On driving loads from ICs
Or, 'from control signal to controlling power'
IC IO pins tend to handle 20mA, perhaps 40mA, and sometimes less. This is enough to drive a (resistor-protected) LED or two, but nothing bright, moving, or otherwise interesting.
When you drive something DC that needs more than a dozen mA, the simplest solution is probably to use this pin to control a (BJT/FET) transistor. That is, use it as a switch that takes current directly your power source and through your load.
One small but important detail to that is the current limiting transistor (often on the order of ~1kOhm) between IO pin and the transistor's base/gate. This avoids accidentally drawing part of the current from that IO pin after all, and ensures it pretty much all comes from your real power source.
Regular BJTs tend to be half an amp (maybe two or three in packages like TO220 and others more serious about heat dissipation). You can use a darlington/fetlington arrangement for somewhat higher currents (and higher-gain switching).
Even if you don't need that much power, consider that it's easier to replace a switching transistor than an controlling IC.
When you want to drive AC, you deal with more current, different voltages, a mix of AC and DC.
Conceptually, the simplest solution is often to add a relay.
In general, when your load is inductive (relays and solenoids and some other things), you can easily get flyback into your control circuit.
You'll want some sort of dissipation or isolation.
To protect your IC/transistor from flyback from inductive DC components (e.g. a solenoide), you can use a protection diode.
See also: