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

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.

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.

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

Applications

Key takeaways

Going further