The output pin of a microcontroller or logic IC can supply only enough current to light an LED or two. Loads like motors, relays, solenoids, and big lamps need tens of mA up to several amps, and connecting them straight to the pin destroys it. This article covers the arrangement of a driver circuit that switches a big load with a small signal, choosing between transistors and MOSFETs, the flyback diode that coil loads absolutely need, and tips on separating power and sharing ground.
Current a pin can supply, and loads
| Load | Current needed (approx.) |
|---|---|
| One LED | 5–20 mA |
| Small 5 V relay coil | About 40–100 mA |
| Small DC motor | 100–500 mA (more at start and stall) |
| Solenoid | 200 mA or more |
| Buzzer (active) | About 10–30 mA |
The current one microcontroller pin can supply is usually around 20 mA or less. Check the exact value in the chip's datasheet (How to Read a Datasheet). A big load must get its current straight from the supply through a driver (transistor, MOSFET, or dedicated IC).
Choosing the driving device
| Device | Characteristics | Use |
|---|---|---|
| NPN transistor (such as 2N3904) | Simple and cheap. Up to about 200 mA | Small relays, small motors, groups of LEDs (Transistor Switch Circuits) |
| Darlington array (such as ULN2003) | 7 channels, about 500 mA per channel, built-in flyback diodes | Relays, stepper motors, several loads at once |
| Logic-level N-channel MOSFET | Small voltage drop when on and large current | High-current motors, lamps |
| H-bridge IC (L298N, TB6612, DRV8833, and so on) | Motor direction reversal and speed control | Forward and reverse motor rotation |
Driving a relay with a transistor
Say a 5 V relay's coil current is 70 mA and the microcontroller output is 3.3 V.
- Collector current Ic = 70 mA, base current Ib ≈ Ic ÷ 10 = 7 mA
R_B = (3.3 V − 0.7 V) ÷ 7 mA ≈ 370 Ω→ use 330 Ω.- Check that the microcontroller pin can supply 7 mA. If it cannot, use a ULN2003 or a MOSFET.
Tips for using a MOSFET
- Use a logic-level MOSFET. Pick one that turns on fully at a 3.3 V gate voltage (the IRLZ44N, or small-signal ones like the 2N7000 and AO3400). A regular MOSFET (such as the IRF540) needs a gate voltage near 10 V and does not turn on properly at 3.3 V.
- Put 100–220 Ω in series between the gate and the pin, and a 10 kΩ pull-down between the gate and GND. That keeps the load from turning on even if the pin floats while the microcontroller boots.
- Connect the load between the MOSFET drain and +V, and the source to GND (low side).
The flyback (freewheeling) diode
When the current through a coil load (relay, motor, solenoid) is cut, the coil releases energy and creates a momentary high reverse voltage (tens to hundreds of volts). That voltage can destroy the transistor or reset the microcontroller.
- If you attach a diode in reverse, in parallel with the coil, this current circulates through the diode and dies away safely.
- The diode's cathode (band) goes to the +V side and its anode to the transistor (collector or drain) side.
- For small relays use a 1N4148 or 1N4007, and for big motors a diode with a higher rating (How to Use Diodes and Zener Diodes).
- Driver ICs like the ULN2003 include this diode (connect the COM pin to the load supply).
Choosing a relay
- Coil voltage: 5 V, 12 V, 24 V. Match it to the circuit's supply.
- Contact rating: markings like 10 A 250 V AC are the limits the contacts can withstand. But switching mains such as 220 V AC directly carries a high risk of shock and fire, so beginners should not do it. It is safer to use the coil at low voltage and the contacts only for low-voltage loads (such as a 12 V lamp).
- Relay modules: modules that are isolated from the control circuit with an optocoupler and include a driver and a diode are convenient. Many turn on when the signal is Low, so check the instructions.
Tips for driving motors
- Separate power: motors create supply noise and large currents. If possible, use a separate supply from the microcontroller, and share ground (Power Rails, Grounding, and Decoupling Capacitor Placement).
- Stall current: the current when the motor is stopped (cannot turn) is 3 to 10 times the normal. Choose the driver's rating based on this value.
- Put a 100 nF ceramic across the motor terminals to reduce brush noise. Put a 470–1000 µF electrolytic at the large power entry.
- Speed control: change the on-off ratio with PWM. To reverse direction you need an H-bridge IC.
- Wiring: keep motor wires thick and short, and away from signal lines.
Build and check tips
- First check the driver's input and output with no load.
- Turn it on for the first time with a current-limited supply (Choosing a Bench Power Supply).
- Touch the driver or transistor to check that it is not getting hot.
- If the microcontroller resets each time the load turns on, suspect power separation, capacitors, or the diode.
Summary
Have a big load driven by a transistor, MOSFET, or driver IC taking current directly from the supply, not by a microcontroller pin, and always attach a flyback diode to coil loads. Use a separate supply for motors and share ground, and do not work directly with AC mains. Continue with the basic principle in Transistor Switch Circuits.