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.
Predict the reading, then compare it with the measurement.
Wokwi ESP32
Third party ToolOpen 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.
sketch.ino
- Use the launch button above to open the ESP32 editor in Wokwi.
- Select the editor’s diagram.json tab and replace all its text with the supplied diagram.json.
- Select the sketch.ino tab, replace all its text with the supplied sketch.ino, then click Start Simulation.
Steps
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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · Wokwi ESP32; numbered callout added to a real capture. Enlarge screenshot (new tab) 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 · 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.
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 checkWhy does the smooth motion interpolation function use an ease-in-out curve rather than moving at constant speed?
Return to the chapter’s knowledge checkA 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
Return to Servo Motors: Calibration and Applications · Browse Labs