3DOF Robotic Arm with Inverse Kinematics

Timeline: July 2021 Context: Personal project Alejo Restrepo

This was my first robotics project: a three-servo robot arm that follows the mouse cursor, built in 2021 from balsa wood, an Arduino UNO and a geometric inverse kinematics solver written in Python. Two of the servos position the two-link arm, and the third just keeps the end parallel to the ground.

Moving the mouse moves the arm. The Python script reads the cursor position, maps it to a target point in centimeters, solves the joint angles with plain trigonometry and streams them to the Arduino over serial. I made a video walking through how the whole thing works.

The project video: the solver simulated in GeoGebra, the reachable region and the software.

The geometry

An unconstrained two-link arm reaches everything inside a circle of radius L1 + L2, in my case 18.3 cm and 12.7 cm. With 180° servos in both joints the real picture is smaller: most of the lower half disappears, a blind circle of radius L1 - L2 sits around the base, and parts of the plane are only reachable with one of the two elbow configurations. I mapped the whole region out in GeoGebra before writing any code.

GeoGebra diagram of the arm's reachable region with unreachable areas marked in red
The reachable region, mapped in GeoGebra. Red marks what the arm cannot reach.

Solving a reachable point D is a circle intersection problem: one circle of radius L1 around the base, another of radius L2 around D. Where they intersect is where the elbow can be. The standard two-circle intersection equations give that point, the shoulder angle is then an arctangent, the elbow angle comes from the law of cosines, and a third angle keeps the end of the arm parallel to the ground, the same job the hand joint does on my later arms. The code repeats this with sign adjustments for each quadrant, and targets outside the region are never solved at all.

The GeoGebra simulation of the solver with the linkage inside the reachable region and the three output angles
The solver running in GeoGebra, with the three angles it outputs.

From the mouse to the servos

The Python script polls the cursor with pyautogui, maps screen pixels to roughly ±31 cm, solves the angles and packs them as three bytes over serial at 9600 baud. The Arduino receiver is 30 lines: read three bytes, write three servos. The value 255 is reserved as a sentinel for unreachable targets, in which case the arm holds its position. The servos are strong enough that the Arduino's 5 V pin alone does not always cut it, so the servos run off a 6 V pack of AA batteries that shares ground with the board.

Wiring diagram with the Arduino UNO, a breadboard and three servos
Wiring: Arduino UNO, breadboard and the three servos.
The GeoGebra simulation next to the Arduino receiver sketch
The two halves of the software: the GeoGebra model and the Arduino receiver sketch.

The first time the whole chain worked end to end, I recorded it.

Serial communication test: the arm driven live from the Python script.

The build

The arm itself is hand-cut balsa wood, painted red, with the servo horns screwed into pockets in the links. The base servo sits under a metal plate from a robot car kit, and everything mounts on a plywood board with the component layout drawn on in marker.

The metal base plate with the servo horn mounted between balsa blocks
The base plate with the servo horn mount.
The plywood base board with the component layout drawn in marker and a breadboard attached
The plywood base board with the layout marked out.
The assembled base and first link with servo cables routed out
The base and first link assembled, with the servo cables routed out.
One of the hand-cut balsa wood links
One of the balsa links.

It is rough, and that is the point: this is the project that started everything. The same geometric idea, done properly, became my Matura thesis arm three years later, and eventually the 6-axis arm I built at ETH.

The Python solver and the Arduino receiver are on GitHub: github.com/alerest285/3DOF-Robotic-Arm.

Both project videos are on YouTube: the project walkthrough and the serial communication test.