Skip to content

Actuator Selection and Driving

Actuator Selection and Driving

A wrong sensor only spoils your data; a wrong actuator burns parts, jams mechanisms, or creates personal risk. This section gives the selection and driving rules that survive delivery. By the end you will be able to:

  • Choose actuators by four questions: torque or position, holding required, noise tolerated
  • Handle the four mandatory items: power-domain split, inrush current, flyback protection, run-away stopping
  • Define power-on default state and the emergency-stop path — the first question in any safety-relevant project
  • Produce a selection table backed by measured stall current and temperature rise, not datasheet ratings

Before starting this section, make sure you:

  • Completed Section 2 of Chapter 25 (digital inputs and debounce)
  • Have a hobby servo, a geared DC motor with an H-bridge driver board, and a stepper driver (A4988 / TMC class)
  • Have a bench supply and a current meter (or power analyser); most conclusions here must be measured
Type Output Position control Holding Noise and heat Typical use
Servo Angle (internal position loop) Simple; accuracy limited by mechanical backlash Powered continuously when holding — heats up and buzzes Gear whine Valve levers, aiming, demo rigs
Geared DC motor Speed and direction Needs encoder or limit switch to close the loop No hold (free to turn) Brush noise Conveyors, stirring, wheels
Stepper motor Discrete steps High resolution but can lose steps Current flows while holding, noticeable heat Quiet with micro-stepping Precision stages, dispensing, printers
Solenoid class (relay / valve) On or off No position concept Latching relays need no hold current Coil whine possible Switching, gas and liquid paths

Four decision rules:

  1. If you need “held position with force”, a servo is worse than a solenoid lock or a self-locking mechanism — gearbox self-locking depends on lead angle and must not be assumed
  2. If you need precise position plus long holds, prefer stepper with closed-loop encoder, or go to a servo drive; pure open-loop stepper will lose steps whenever the mechanism binds
  3. If you need fast repetitive cycling, ask the vendor for mechanical lifetime and derating — gear trains fail silently
  4. In any customer-facing machine, every actuator needs “no command means stop” watchdog semantics

Mandatory item 1: split the power domain, keep one ground

Section titled “Mandatory item 1: split the power domain, keep one ground”

Sharing a rail between actuators and the controller is the number-one failure source:

  • Servo and motor start/stall currents are several times the steady value and collapse the 3.3 V or 5 V rail, resetting the controller or corrupting flash writes
  • Correct approach: separate supply for actuators, single common ground, short thick power runs, local energy storage capacitors; control signals come from the controller side, with opto-isolation where needed
  • When several servos move together currents add — either queue them in software (staggered) or increase storage and conductor size
  • Grounding order: star the power ground and signal ground together at one point; do not let motor return current run through a sensor’s reference ground
  • Relay coils must have a parallel flyback diode (or RC / TVS network); otherwise switch-off inductive kick destroys the driver and disturbs the MCU
  • H-bridges and stepper drivers usually have internal freewheel paths (body diodes or synchronous rectification), but the bus still needs local capacitance to absorb returned energy, or the rail pumps up and trips over-voltage protection
  • With solenoids and SAS-driven motors, look at solid-state relay zero-crossing behaviour together with back-EMF; inductive loads can draw large inrush at pick-up
  • A braking motor is a generator when it stops: shorting (brake) stops faster than coasting but dumps current into the driver

Mandatory item 3: power-on default state and emergency stop

Section titled “Mandatory item 3: power-on default state and emergency stop”

This is the heart of safety-relevant design and must be in writing:

  1. Power-on default: GPIOs are floating or weakly pulled at boot; with careless driver design the actuator twitches during start-up. Fix by strapping driver enable/inputs so that floating equals stop, and choose relays whose de-energised position is the safe position (specify normally-open vs normally-closed deliberately)
  2. Emergency stop must be hardware-level — cutting actuator power or shorting motor terminals directly — independent of MCU firmware and the communication link
  3. Watchdog adds a software layer: stop if no valid command arrives within a set time; commands must be idempotent (duplicate frames execute once, same principle as IR repeat filtering in Section 8)
  4. Interlocks: mutually exclusive actions (two valves never open together) need constraints in both software and hardware

On relay selection: contact ratings in the datasheet are usually for resistive loads. Switching motors, coils or lamps requires the vendor’s derating curve — never use the rated current directly.

Mandatory item 4: PWM resources and porting traps

Section titled “Mandatory item 4: PWM resources and porting traps”
  • Servos need roughly 50 Hz with sufficient pulse resolution (microsecond class). PWM peripheral channel counts, available frequencies and duty resolutions vary widely between chips: the original ESP32’s LEDC offers 16 channels while later models expose fewer, with different pin mapping, so on migration re-check both channel numbers and pins rather than reusing an old project
  • The frequency/bit-width combination determines pulse resolution; raising frequency costs resolution, and the servo starts buzzing or mis-positioning
  • Check for shared timer/clock sources between PWM and other peripherals (some parts share clocks with audio)
  • Holding a servo for long periods heats it and makes it buzz: if the mechanism allows, drop the output after reaching position, or use a self-locking mechanism
  • Legacy bipolar H-bridges (L298 class) drop roughly 1–2 V per leg — poor efficiency and heavy heat in low-voltage battery systems. MOSFET drivers (DRV8833 / TB6612 class) have low on-resistance and suit 3.3–7.4 V systems far better
  • For stepper drivers, current setting and thermal design dominate: peak current is set via reference voltage; too low loses steps, too high overheats. Micro-stepping lowers noise but costs torque, and quiet modes (StealthChop class) matter for customer-facing machines

Servo: LEDC angle control computed, not guessed

Section titled “Servo: LEDC angle control computed, not guessed”
const int SERVO_FREQ = 50; // 20 ms period
const int SERVO_RES_BITS = 16; // more bits = finer pulse
const uint8_t SERVO_PIN = 18;
const uint32_t PULSE_MIN_US = 1000; // 0°, calibrate by measurement
const uint32_t PULSE_MAX_US = 2000; // 180°, calibrate by measurement
void servoWriteAngle(float angleDeg) {
uint32_t us = PULSE_MIN_US + (PULSE_MAX_US - PULSE_MIN_US) * (uint32_t)angleDeg / 180U;
uint32_t duty = (us * ((1UL << SERVO_RES_BITS) - 1)) / 20000U; // period is 20000 µs
ledcWrite(0, duty);
}
void servoSetup() {
ledcAttach(SERVO_PIN, SERVO_FREQ, SERVO_RES_BITS); // new API; older cores use ledcSetup + ledcAttachPin
servoWriteAngle(90.0f);
}

Both end-point pulses must be calibrated on the real part (travel differs between servos), and the values recorded in comments and firmware notes. The API shape changed across arduino-esp32 versions (ledcAttach versus ledcSetup plus ledcAttachPin); adjust those two lines to the core you installed.

const uint8_t IN1 = 25, IN2 = 26, PWM_PIN = 27;
uint8_t duty = 0; // current duty
const uint8_t DUTY_STEP = 8; // increment every 10 ms to cut inrush
const unsigned long RAMP_MS = 10;
void motorForward() { digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); }
void motorReverse() { digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); }
void motorBrake() { digitalWrite(IN1, HIGH); digitalWrite(IN2, HIGH); } // both high: windings shorted, active stop
void motorCoast() { digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); } // both low: high-Z, coasts to a halt
// The truth table above fits DRV8833 / TB6612-class drivers; some boards have a separate
// standby pin or inverted inputs — measure it once before committing to a part
void rampUp() {
if (duty < 200) { duty = min(255, duty + DUTY_STEP); ledcWrite(1, duty); }
delay(RAMP_MS);
}
// Stall criterion (sketch): current above limit for a sustained period → stop and report
bool stallDetected(uint16_t currentMa, uint16_t limitMa, unsigned long holdMs) {
static unsigned long overSince = 0;
if (currentMa > limitMa) {
if (overSince == 0) overSince = millis();
return millis() - overSince > holdMs;
}
overSince = 0;
return false;
}
unsigned long lastCmdMs = 0;
const unsigned long CMD_TIMEOUT_MS = 2000;
void actuatorWatchdog() {
if (millis() - lastCmdMs > CMD_TIMEOUT_MS) {
motorBrake(); // or "release", per the hazard definition
servoRelease(); // depends on the mechanism
}
}
void onValidCommand(uint8_t cmd) { lastCmdMs = millis(); /* perform action */ }

Whether the timeout means brake or release must follow the mechanism’s dangerous direction: falling loads usually short the windings to hold position; horizontal conveyors usually release. Put this in the risk assessment table.

Check Expected result Verified
Measured start and stall current per actuator Peak band and duration recorded as the basis for supply design
Actuator state at power-on No motion; document the default level of each control pin
Emergency stop test Mechanism halts at the safe position; MCU reset does not defeat e-stop
Watchdog timeout Stops within 2 s without a command and reports the event
1000 continuous cycles No gear damage, no position drift, temperature rise acceptable
Servos simultaneous vs staggered Measured rail droop, deciding whether storage or queuing is needed
Stepper lost-step test under rated load Documented loss rate; improvement after adding limit or encoder
Relay contacts under real load, sampled life test No welding, no measurable contact-resistance rise
Motor brake versus coast Stop time and current impulse recorded for both

Issue 1: the controller keeps rebooting once actuators are connected

Section titled “Issue 1: the controller keeps rebooting once actuators are connected”

Cause: inrush drags the rail down, or driver noise couples into reset and flash supply.

Solutions:

  1. Separate actuator supply with common ground, plus local storage capacitance (hundreds of µF to start; size it to current and wire gauge)
  2. Ramp the software start to reduce instantaneous demand
  3. Re-check grounding and conductor size; do not run power return current through thin shared wiring

Issue 2: the servo buzzes or misses its position

Section titled “Issue 2: the servo buzzes or misses its position”

Possible causes: supply ripple; insufficient PWM resolution; load beyond torque (continuous stall); end-point calibration values that don’t match the real travel.

Solutions:

  1. Increase PWM bit-width or lower the frequency so pulse resolution beats 2 µs
  2. Re-calibrate end points against actual travel
  3. If it still buzzes after arrival, drop the output at position or move to a self-locking mechanism

Issue 3: the motor will not turn, or runs one way only

Section titled “Issue 3: the motor will not turn, or runs one way only”

Possible causes: enable/standby pin not asserted; direction inputs interpreted differently by the board; no common ground; PWM channel conflict.

Solutions:

  1. Verify the direction and enable truth table pin by pin (use the raw-level printout technique from Section 2)
  2. Swap IN1/IN2 to test whether one side of the wiring is at fault
  3. Move to another PWM channel to rule out conflicts

Issue 4: the stepper runs hot or loses precision

Section titled “Issue 4: the stepper runs hot or loses precision”

Cause: peak current set too high (heat) or too low (missed steps); micro-stepping versus torque trade-off set wrong; acceleration too aggressive.

Solutions:

  1. Re-set current using the vendor method (reference voltage against sense resistor) and record the value
  2. Reduce acceleration or raise current, then decide from measurement whether the fault is lost steps or stall
  3. Add position verification (limit switch or encoder) so lost steps become a detectable event
  • Do: make the selection table carry five fixed columns: voltage range, steady current, start/stall peak current, position-control method, fail-default state
  • Do: ship hardware e-stop plus software watchdog plus idempotent commands; missing any one means the safety design is not finished
  • Do: put power-domain splits into the wiring sheet and the mechanical layout (the ground-star point belongs on the drawing)
  • Do: give every inductive load its own flyback or snubber path; do not gamble on internal protection
  • Don’t: size relay contacts from the resistive rating when switching motors or coils
  • Don’t: run actuators and the controller off one thin supply run
  • Don’t: reuse PWM channel numbers and pins when migrating between chips

Key points of this section:

  1. Choose by torque / position / holding / noise: open-loop steppers lose steps when they bind; servos heat up when holding
  2. Power-domain split and grounding are problem number one; measured stall current is the design input, not the datasheet figure
  3. Four safety definitions must be explicit: power-on default state, emergency-stop path, watchdog behaviour, interlocks
  4. PWM resources differ per chip — re-check channels and pins on migration, and calibrate servo end points
  5. Derate relay contacts for the actual load, and always provide flyback paths for inductive loads

Next section: power rails and level shifting — logic thresholds, Wi-Fi current pulses, and how to end the “random reboot” and “cannot read high level” classes of problems.


Building a commercial IoT product?

We provide ESP32 ODM design-to-manufacturing services. From prototype to production — the team behind this tutorial can build it with you.

💡 Mention tutorial.imagrove.com in your Alibaba chat with us — get 10% off your custom project quote.

Talk to us →

First published attutorial.imagrove.com/sensor-module-selection/13-actuator-selection-and-driving/Please credit Imagrove and link back to this page when quoting or republishing.

Questions or issues with this tutorial?

Sign in with GitHub to leave a comment. If a step fails for you, tell us — we verify it and update the tutorial.