Actuator Interfacing
Actuators turn electrical signals into action: LEDs, relays, solenoids, DC motors, servos and steppers. Learn transistor and MOSFET drivers, flyback protection, H-bridges, servo PWM and how to size drive circuits safely.
An MCU pin can supply only a few milliamps at 3.3 V, but actuators need amps at 12, 24 or 48 V. Between them sit driver circuits — transistors, MOSFETs, H-bridges and dedicated driver ICs — that amplify the signal and protect the MCU from the load.
Inductive actuators (relays, solenoids, motors) add a twist: when switched off they generate large voltage spikes that must be clamped.
An analogy
The MCU is a conductor with a baton, and the driver is the orchestra: the conductor's small gestures (logic signals) command the orchestra's powerful output (current into the load).
Low-side switching
The simplest driver puts an NPN transistor or N-channel MOSFET between the load and ground; the load connects to the positive supply. A logic-level MOSFET (fully on at V_GS = 2.5–4.5 V) is preferred for currents above ~100 mA because its drop is only I·R_DS(on). Add a gate pull-down so the load stays off while the MCU boots.
Flyback diodes
Interrupting current in an inductor makes it generate V = L·di/dt — hundreds of volts that destroy the transistor. A diode across the coil (reverse-biased normally) gives the current a path to decay. For fast relay/solenoid release, use a diode + Zener or a TVS so the current decays more quickly.
DC motors and H-bridges
A single transistor runs a motor one way with PWM speed control. Reversing needs an H-bridge (four switches) — typically an integrated driver (DRV8871, L298-style, or MOSFET bridge with gate driver) with current limiting, thermal shutdown and brake/coast modes.
Servos and steppers
Hobby servos contain a motor, gearbox, potentiometer and controller; you command angle with a 1–2 ms pulse every 20 ms. Stepper motors need dedicated drivers (A4988, TMC2209) that regulate phase current and do microstepping from STEP/DIR signals.
Protection and EMC
Add fuses or electronic current limits, reverse-polarity protection, and TVS diodes on long cables. Keep high-current loops small and separate power and signal grounds (star point). Optically isolated or digital-isolator drivers protect MCUs from high-voltage loads. Snubbers and slew-rate control reduce EMI from fast switching.
Formulas
- Coil current:
I = V / R_coil - BJT base resistor:
R_B = (V_GPIO − V_BE) / (k · I_C/β), k ≈ 3–5 overdrive - Inductive energy:
E = ½ L I² - Servo angle:
t = 1 ms + (θ/180°) × 1 ms (50 Hz frame)
Worked example: Relay driver with an NPN transistor
Given: Relay: 12 V, 400 Ω coil; NPN β ≥ 50, V_BE = 0.7 V; GPIO = 3.3 V, 5× overdrive
Find: Coil current and base resistor.
- I_C = 12/400 = 30 mA
- I_B = 5 × 30/50 = 3 mA
- R_B = (3.3 − 0.7)/3 mA = 867 Ω → 820 Ω
- Add a 1N4148 flyback diode across the coil
Answer: 30 mA coil, 820 Ω base resistor + flyback diode
Worked example: Servo compare value
Given: Timer 1 MHz, 20 ms frame; Target 90°
Find: Pulse width and CCR.
- t = 1 ms + (90/180) × 1 ms = 1.5 ms
- CCR = 1500 ticks
Answer: 1.5 ms → CCR = 1500
Driving a hobby servo with a timer PWM channel
// Timer clock 1 MHz (1 µs per tick), period 20 ms -> ARR = 19999
void servo_init(void) {
TIM3->PSC = 72 - 1; // 72 MHz / 72 = 1 MHz
TIM3->ARR = 20000 - 1; // 20 ms frame (50 Hz)
TIM3->CCMR1 |= (6u << 4); // PWM mode 1 on channel 1
TIM3->CCER |= TIM_CCER_CC1E;
TIM3->CR1 |= TIM_CR1_CEN;
}
void servo_set_angle(float deg) {
if (deg < 0) deg = 0;
if (deg > 180) deg = 180;
TIM3->CCR1 = (uint16_t)(1000 + deg * 1000.0f / 180.0f); // 1000..2000 µs
}The timer generates the pulse in hardware; the CPU only updates the compare register when the angle changes.
Common mistakes
- Wrong: Omitting the flyback diode on a relay or solenoid. — Right: Always clamp inductive loads; the turn-off spike destroys transistors and resets MCUs.
- Wrong: Powering motors from the MCU's regulator. — Right: Use a separate supply for motors, with a common ground and bulk decoupling.
Applications
- Home automation: Relays and SSRs switch lights, pumps and heaters from MCU outputs.
- Robotics: H-bridges drive wheels; servos and steppers position arms and grippers.
- Automotive: Smart high-side switches with diagnostics drive lamps, heaters and solenoid valves.
Key takeaways
- MCU pins signal; drivers (BJT, MOSFET, H-bridge, ICs) deliver power.
- Always clamp inductive loads (diode, Zener, TVS).
- Servos: 1–2 ms pulses per 20 ms; steppers: STEP/DIR drivers.
- Separate power supplies and protect against faults and EMI.
Going further
- Smart high-side switches: Automotive 'PROFET'-type switches integrate the MOSFET, charge pump, current sense, overtemperature and open-load diagnostics, reporting faults to the MCU.
- Peak-and-hold drivers: Solenoids and injectors are pulled in with high current, then held at a lower current by PWM or a current regulator, cutting heat and power.
- Back-EMF and regenerative braking: Braking a DC motor through the H-bridge returns energy to the supply; without a place to go (battery or brake resistor), the bus voltage rises dangerously.