TL;DR:
Four hobby servos give you a base turn, a shoulder, an elbow and a wrist that holds a pen.
Power the servos from their own supply, set safe angle limits in code, and move slowly in small steps.
For a point in the arm's plane, the law of cosines gives the elbow angle, and a little trigonometry gives the shoulder.
A robot arm looks complicated, but each joint is just a motor you can set to an angle. The challenge is to choose the right angles so the tip lands where you want. This build starts with a pen on the end and three dots on paper.
What you will build
You will assemble a small arm with four servos: one to rotate the base, one for the shoulder, one for the elbow, and one for the wrist that holds the pen. The goal is to move the pen tip to three marked points on a sheet of paper, one after another, and lift between them.
Parts and tools
Four hobby servos and a kit or printed brackets that join them into an arm.
A microcontroller board that can drive servos.
A separate 5 to 6 V power supply for the servos, rated for the current of all four moving at once. Check your servo's data sheet for its limits.
A capacitor across the servo supply, jumper wires, a switch.
Paper, tape, a ruler and a light felt-tip pen.
Power for servos
The most common failure is power. A servo that pushes against a load can draw far more current than it does when idle, and four of them together can exceed what a board's USB port offers. The board then resets, the servos twitch, and the arm flops.
Give the servos their own supply. Connect that supply's ground to the board's ground, so the signal wires have a common reference, but do not feed servo power through the board.
Wiring and assembly
Center every servo first: Before attaching any arm piece, run a sketch that sends each servo to 90°. Fit the horns so the arm stands in a neutral position: upper link vertical, forearm horizontal.
Wire three lines per servo: Each servo has ground, power and signal. Power goes to the external supply, signal goes to a board pin, and ground goes to both.
Tape the paper down: Fix the paper at a measured place, and mark the base of the arm on it. Your numbers depend on that position.
The math for a two-link arm
Treat the shoulder and elbow as two links in a vertical plane, and the base as the turn that picks which plane. Say both links are 10 cm. Measure x outward from the shoulder and y upward. Given the target, the elbow angle comes from the law of cosines:
cos θ2 = (x² + y² − L1² − L2²) / (2 · L1 · L2)
θ1 = atan2(y, x) − atan2(L2 · sin θ2, L1 + L2 · cos θ2)Worked example: put the pen at (10, 0), level with the shoulder and 10 cm out.
cos θ2 = (100 + 0 − 100 − 100) / 200 = −0.5, soθ2 = 120°.θ1 = atan2(0, 10) − atan2(10 × 0.866, 10 + 10 × (−0.5)) = 0° − atan2(8.66, 5) = −60°.Check with forward kinematics: the elbow is at
(10 cos −60°, 10 sin −60°) = (5, −8.66). The forearm points at−60° + 120° = 60°, adding(5, 8.66). The tip is at(10, 0). ✓
A second point, (10, 10), gives cos θ2 = (200 − 200) / 200 = 0, so θ2 = 90° and θ1 = 45° − 45° = 0°. The upper link points straight out, the forearm straight up, and the tip lands at (10, 0) + (0, 10) = (10, 10). ✓
Servos expect numbers like 0 to 180, so add an offset. If a servo's 90° position is your zero, the shoulder command for the first point is 90 − 60 = 30. Which direction is positive depends on how you mounted the horn, so test one joint at a time.
The code: angle limits and sequenced moves
#include <Servo.h>
Servo base, shoulder, elbow, wrist;
int cur[4] = {90, 90, 90, 90};
int clampTo(int v, int lo, int hi) { return v < lo ? lo : (v > hi ? hi : v); }
void moveTo(int b, int s, int e, int w) {
int tgt[4] = { clampTo(b, 20, 160), clampTo(s, 30, 150),
clampTo(e, 30, 150), clampTo(w, 20, 160) };
bool moving = true;
while (moving) {
moving = false;
for (int i = 0; i < 4; i++) {
if (cur[i] < tgt[i]) { cur[i]++; moving = true; }
else if (cur[i] > tgt[i]) { cur[i]--; moving = true; }
}
base.write(cur[0]); shoulder.write(cur[1]);
elbow.write(cur[2]); wrist.write(cur[3]);
delay(15);
}
}
void setup() {
base.attach(3); shoulder.attach(5); elbow.attach(6); wrist.attach(9);
moveTo(90, 90, 90, 90);
}Moving one degree at a time every 15 ms turns each jump into a smooth glide. It also prevents the sudden current spike you get when a servo is told to go to a far angle at once. The clamps are your angle limits: choose them so no joint can drive the arm into the table or into itself.
Sequence the three points as lift, travel, lower, pause, lift again. A short sequence of moveTo calls is enough. Always raise the pen before traveling between dots.
Test, measure and fix
Pen lands a few millimeters off: measure the real link lengths with a ruler and use those in the formula, not the nominal ones.
Servo buzzes at the end of a move: it is pushing against a limit or fighting a load. Widen the limit or lighten the pen.
Whole arm resets: a power problem. Check the common ground and the supply rating.
Cheap servos have some slack, so expect about a millimeter or two of wobble. Mark your three dots, run the sequence five times, and measure the spread. That spread is your arm's repeatability.
Stay safe
Pinch points: Small arms can still pinch fingers between links, and a servo can move without warning at power-on. Keep hands clear while it moves, switch the servo supply off before adjusting, and use a supply designed for servos, never mains power.
Frequently asked questions
Can I use more than four servos?
Yes, but each one adds weight and current. Add a gripper only after the four-servo version is steady.
Why not just record the angles by hand?
You can. Move the arm by hand to each dot and write down the angles. The math is useful when you want points you have not recorded.
