Servo robot arm
What you’ll build
A small robot arm with a rotating base, a shoulder, an elbow and a gripper, each driven by a servo. First you control each joint with a knob; then the arm learns to replay a sequence by itself.
Parts
| Part | Qty | Notes |
|---|---|---|
| Servos (SG90 for a light arm, MG90S/MG996R for stronger joints) | 4 | Metal gears last longer |
| Arm kit or 3D-printed / cardboard links | 1 | |
| Potentiometers (10 kΩ) | 4 | One per joint |
| 5–6 V supply, 2 A or more | 1 | Servos must not run from the Arduino’s 5V pin |
| Arduino UNO, breadboard, wires | 1 |
Wiring
| Joint | Servo signal | Knob |
|---|---|---|
| Base | 9 | A0 |
| Shoulder | 10 | A1 |
| Elbow | 11 | A2 |
| Gripper | 6 | A3 |
All servo red wires go to the external 5–6 V supply; all grounds (supply, servos, Arduino) are joined.
Build tips
- The shoulder carries the most load: use your strongest servo there.
- Keep the arm light, especially near the end: every gram at the tip loads the shoulder.
- Set each servo to 90° before attaching its horn, so the arm’s middle position matches the code.
- Limit each joint’s range in code so it can’t crash into itself.
Knob control for four joints
#include <Servo.h>
Servo joint[4];const int SERVO_PIN[4] = {9, 10, 11, 6};const int KNOB[4] = {A0, A1, A2, A3};const int MIN_ANGLE[4] = {0, 20, 20, 30}; // safe ranges: tune for your armconst int MAX_ANGLE[4] = {180, 160, 160, 110};
void setup() { for (int i = 0; i < 4; i++) joint[i].attach(SERVO_PIN[i]);}
void loop() { for (int i = 0; i < 4; i++) { int a = map(analogRead(KNOB[i]), 0, 1023, MIN_ANGLE[i], MAX_ANGLE[i]); joint[i].write(a); } delay(15);}Record and replay (idea)
Store the four angles in an array every time a button is pressed (up to, say, 20 poses). On a second button, play them back in order, moving each joint smoothly from pose to pose.
Try it in the virtual Arduino
Press Start simulator, replace diagram.json, paste the sketch and press ▶. Each knob moves one joint. If Wokwi says a library is missing, click its Install button and press ▶ again.
{ "version": 1, "author": "RoboLearn", "editor": "wokwi", "parts": [ { "type": "wokwi-arduino-uno", "id": "uno", "top": 0, "left": 0, "attrs": {} }, { "type": "wokwi-servo", "id": "base", "top": -110, "left": 160, "attrs": {} }, { "type": "wokwi-servo", "id": "shoulder", "top": -110, "left": 300, "attrs": {} }, { "type": "wokwi-potentiometer", "id": "pot1", "top": -100, "left": -40, "attrs": {} }, { "type": "wokwi-potentiometer", "id": "pot2", "top": -100, "left": 50, "attrs": {} } ], "connections": [ [ "base:GND", "uno:GND.1", "black", [] ], [ "base:V+", "uno:5V", "red", [] ], [ "base:PWM", "uno:9", "orange", [] ], [ "shoulder:GND", "uno:GND.1", "black", [] ], [ "shoulder:V+", "uno:5V", "red", [] ], [ "shoulder:PWM", "uno:10", "orange", [] ], [ "pot1:GND", "uno:GND.2", "black", [] ], [ "pot1:VCC", "uno:5V", "red", [] ], [ "pot1:SIG", "uno:A0", "green", [] ], [ "pot2:GND", "uno:GND.2", "black", [] ], [ "pot2:VCC", "uno:5V", "red", [] ], [ "pot2:SIG", "uno:A1", "green", [] ] ], "dependencies": {}}#include <Servo.h>
Servo base, shoulder;
void setup() { base.attach(9); shoulder.attach(10);}
void loop() { base.write(map(analogRead(A0), 0, 1023, 0, 180)); shoulder.write(map(analogRead(A1), 0, 1023, 20, 160)); // limited range delay(15);}Runs on Wokwi, free, no account needed.
Safe rangesEasy
Change the shoulder range to 45–135° and check that the knob can’t push it further.
shoulder.write(map(analogRead(A1), 0, 1023, 45, 135));
WaveMedium
Replace the knob code with an automatic “wave”: the base swings 60°→120°→60° while the shoulder stays at 90°.
Show an answer
void loop() { shoulder.write(90); for (int a = 60; a <= 120; a++) { base.write(a); delay(10); } for (int a = 120; a >= 60; a--) { base.write(a); delay(10); }}Record and replayHard
Add a button: each press saves the current two knob angles (up to 10 poses). After 10 presses, replay all poses in a loop.
Use two arrays, int baseA[10], shoulderA[10]; and a counter. Detect presses with the edge-detection pattern from the button lessons.
Quick check
Finished this lesson?