Skip to content

Coordinate a three-servo gripper sequence

Command home, grab, release, and pick-and-place motion while checking each servo's angle and the shared power boundary.

Motor Max: I want you to verify the power boundary and every commanded angle before trusting the gripper under load., your practice guide

Motor Max: I want you to verify the power boundary and every commanded angle before trusting the gripper under load.
Predict the reading, then compare it with the measurement.

Wokwi ESP32

Third party Tool

Tier 1 · Web · No account

Version tested: Compiled and booted by the Wokwi gate (ESP32 Arduino core 3.3.11); captured in the Wokwi web editor on 2026-09-09. Date: 2026-09-09.

Open the ESP32 editor, paste diagram.json, then paste sketch.ino.

Open Wokwi to paste in the files (new tab)

Get the files

Use both prepared files. This is a paste-in setup; saving a project requires a Wokwi account.

diagram.json

1,440 bytes · Circuit connections

Download

sketch.ino

2,429 bytes · ESP32 program

Download

  1. Use the launch button above to open the ESP32 editor in Wokwi.
  2. Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
  3. Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.

Steps

Screens captured against Wokwi ESP32 Compiled and booted by the Wokwi gate (ESP32 Arduino core 3.3.11); captured in the Wokwi web editor on 2026-09-09 on 2026-09-09; the tool may have moved on — the text steps are the contract.

  1. 1 Step 1

    Do
    In Wokwi's project editor, paste diagram.json and sketch.ino into a new Wokwi ESP32 project, then inspect the three signal paths and common ground before starting.
    You will see
    Base servo PWM connects to ESP32 GPIO18 (diagram.json line 52). Arm servo PWM connects to ESP32 GPIO19 (diagram.json line 53). Gripper servo PWM connects to ESP32 GPIO21 (diagram.json line 54). All three servo V+ pins connect to the separate servo 5 V supply (diagram.json line 55). All three servo grounds and ESP32 ground join the common ground (diagram.json lines 58–61).
    Why it matters
    The three PWM lines independently command base, arm, and gripper in later movement steps. Their common ground gives all three servos and the ESP32 a shared signal reference.
    Step 1: Three servo signal paths and the shared 5 V and ground rails are visible. The ring marks the three servos and their common power boundary.
    Step 1 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  2. 2 Step 2

    Do
    In Wokwi's sketch editor, inspect moveToPosition and identify how the duration becomes 20 ms interpolation steps.
    You will see
    Move toward a target position: void moveToPosition(Position target, int duration) { (sketch.ino line 52). Split duration into 20 ms steps: int steps = max(1, duration / 20); (sketch.ino line 54). Iterate through the steps: for (int i = 0; i <= steps; i++) { (sketch.ino line 55). Compute interpolation progress: float p = (float)i / steps; (sketch.ino line 56). Update the base servo: baseServo.write(curB + (target.base - curB) * p); (sketch.ino line 57). Update the arm servo: armServo.write(curA + (target.arm - curA) * p); (sketch.ino line 58). Update the gripper servo: gripperServo.write(curG + (target.gripper - curG) * p); (sketch.ino line 59). Wait 20 ms between updates: delay(20); (sketch.ino line 60).
    Why it matters
    The duration becomes at least one 20 ms interval. Interpolation advances all three servo angles together, so later position output corresponds to a stepped move rather than an instantaneous jump.
    Step 2: The interpolation loop writes all three target angles in 20 ms steps. The ring marks moveToPosition.
    Step 2 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  3. 3 Step 3

    Do
    In the Simulation toolbar, start the run and read the Serial Monitor command menu.
    You will see
    Input: supplied three-servo sketch. Observed: "Position base=90 arm=90 gripper=90". Observed: "Commands: h=home, g=grab, r=release, s=sequence". Expected: the servos begin at their home angles.
    Why it matters
    All three reported angles begin at 90 degrees. The live menu exposes four commands. The starting state is a reference for later motions. The serial values are simulated servo commands.
    Step 3: Position base=90 arm=90 gripper=90 Commands: h=home, g=grab, r=release, s=sequence The ring marks the home position and command menu.
    Step 3 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  4. 4 Step 4

    Do
    In the Serial Monitor input field, send g and wait for the grab sequence.
    You will see
    Input: send g. Observed: "Sequence: grab". Observed: "Position base=90 arm=45 gripper=45". Observed later: "Position base=90 arm=90 gripper=45".
    Why it matters
    The arm lowers to 45 degrees. The gripper closes at 45 degrees. The arm returns to 90 degrees. The final closed position matches the real capture.
    Step 4: Sequence: grab Position base=90 arm=45 gripper=90 Position base=90 arm=45 gripper=45 Position base=90 arm=90 gripper=45 The ring marks the ordered grab positions.
    Step 4 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  5. 5 Step 5

    Do
    In the Serial Monitor input field, send r and wait for the release sequence.
    You will see
    Input: send r after grab. Observed: "Sequence: release". Observed: "Position base=90 arm=45 gripper=90". Observed later: "Position base=90 arm=90 gripper=90".
    Why it matters
    The arm lowers before release. The gripper opens to 90 degrees. The arm then returns home. The output ends with all three axes at 90 degrees.
    Step 5: Sequence: release Position base=90 arm=45 gripper=45 Position base=90 arm=45 gripper=90 Position base=90 arm=90 gripper=90 The ring marks the ordered release positions.
    Step 5 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  6. 6 Step 6

    Do
    In the Serial Monitor input field, send s and watch the pick-and-place sequence.
    You will see
    Input: send s. Observed: "Sequence: pick-and-place". Observed: "Position base=45 arm=45 gripper=45". Observed: "Position base=135 arm=45 gripper=45", then home.
    Why it matters
    The base reaches 45 degrees for pickup. It reaches 135 degrees for placement. The gripper closes during transfer. The last serial position returns all axes to 90 degrees.
    Step 6: Sequence: pick-and-place Position base=45 arm=45 gripper=90 Position base=45 arm=45 gripper=45 Position base=135 arm=45 gripper=45 Position base=135 arm=45 gripper=90 Position base=90 arm=90 gripper=90 The ring marks the pickup, placement, and return positions.
    Step 6 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)
  7. 7 Step 7

    Do
    In the Serial Monitor input field, send h and read the final position.
    You will see
    Input: send h after pick-and-place. Observed: "Position base=90 arm=90 gripper=90". Observed: a second identical home line followed the sequence result. Expected: the explicit home command ends at 90, 90, 90.
    Why it matters
    The command reports the intended home angles. The repeated position distinguishes explicit home from sequence completion. All axes are at their starting values. This is serial position evidence from the simulator.
    Step 7: Position base=90 arm=90 gripper=90 The ring marks the final explicit home position.
    Step 7 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab)

Chapter checks

These questions refer to the chapter’s examples. Use the return links to review their answers.

  1. A standard hobby servo receives a 1.5ms pulse at 50 Hz. What position will the servo move to?

    Return to the chapter’s knowledge check
  2. Why does the smooth motion interpolation function use an ease-in-out curve rather than moving at constant speed?

    Return to the chapter’s knowledge check
  3. A high-torque servo has a stall current of 2.5A. If you are building a 3-servo robotic arm, what minimum power supply current rating do you need?

    Return to the chapter’s knowledge check

Caution

The Wokwi 5 V symbol represents the legacy lab's separate regulated servo supply. On hardware, never power three servos from the ESP32 rail; size the external supply for stall current, join grounds, centre each servo before attaching linkages, and enforce mechanical travel limits.

Return to Servo Motors: Calibration and Applications · Browse Labs