Once your arm has more than a couple of joints, setting each angle by hand stops making sense. You want to say “put the gripper here” and let the arm work out the angles. That’s inverse kinematics — and the basic case is simpler than its reputation suggests.

This builds on degrees of freedom; read that first if “DOF” is new to you.

Forward vs inverse kinematics

  • Forward kinematics (FK): given the joint angles, where is the gripper? Easy — just follow the chain of links.
  • Inverse kinematics (IK): given a target position for the gripper, what joint angles get it there? Harder, because multiple solutions (or none) can exist.

IK is the useful one for control: it’s how vision-guided Raspberry Pi arms turn “the object is at this point” into motion.

Most DIY IK reduces to a 2-link planar arm (shoulder + elbow) reaching a point (x, y). With link lengths L1 and L2, the law of cosines gives both joint angles directly. The elbow angle:

cos(θ2) = (x² + y² − L1² − L2²) / (2·L1·L2)

and the shoulder angle combines the direction to the target with a correction for the elbow. Here it is as runnable code.

Arduino / C++

#include <math.h>
const float L1 = 10.0, L2 = 10.0;   // link lengths (cm)

// Returns true if reachable; fills shoulder & elbow in degrees.
bool ik2(float x, float y, float &shoulder, float &elbow) {
  float d2 = x*x + y*y;
  float c2 = (d2 - L1*L1 - L2*L2) / (2*L1*L2);
  if (c2 < -1 || c2 > 1) return false;          // out of reach
  float t2 = acos(c2);                          // elbow (radians)
  float t1 = atan2(y, x) - atan2(L2*sin(t2), L1 + L2*cos(t2));
  shoulder = t1 * 180.0 / PI;
  elbow    = t2 * 180.0 / PI;
  return true;
}

Feed the results into the servo control from the Arduino arm guide.

Python (for a Raspberry Pi arm)

import math

L1, L2 = 10.0, 10.0   # cm

def ik2(x, y):
    d2 = x*x + y*y
    c2 = (d2 - L1**2 - L2**2) / (2*L1*L2)
    if not -1 <= c2 <= 1:
        return None                  # unreachable
    t2 = math.acos(c2)               # elbow
    t1 = math.atan2(y, x) - math.atan2(L2*math.sin(t2), L1 + L2*math.cos(t2))
    return math.degrees(t1), math.degrees(t2)

print(ik2(12, 5))   # -> (shoulder_deg, elbow_deg)

Elbow-up vs elbow-down

A 2-link arm can usually reach a point two ways — elbow bent up or down. Negating θ2 gives the other solution. Pick whichever keeps the arm away from obstacles and within its joint limits.

Going to 3D and more joints

  • Add the base rotation to aim the whole plane at the target, and you have a 3-DOF arm reaching any point in a cylinder around the base.
  • Full 6-DOF orientation is much harder analytically — most people use a library or a numerical (iterative) IK solver rather than closed-form maths.
  • Always clamp results to your servo limits and check reachability before commanding a move.

When to use it

You don’t need IK for a cardboard or basic 4-DOF arm. Reach for it when you want:

  • Vision-guided pick and place
  • Straight-line or path moves
  • A natural “go to this point” interface

Start with the 2-link code above on your existing arm — it’s the clearest way to see the maths turn into motion.

Frequently asked questions

What is inverse kinematics for a robotic arm?

Inverse kinematics (IK) is the maths that turns a target position for the gripper into the joint angles needed to reach it. Forward kinematics goes the other way — from joint angles to gripper position. IK is what lets you say 'go to this point' instead of setting every joint by hand.

Do I need inverse kinematics for my robotic arm?

Not for simple builds. With 2–4 DOF you can control joints directly or with potentiometers. IK becomes valuable when you want the arm to reach a specific point in space automatically — for example vision-guided pick and place, or smooth straight-line moves.

Is inverse kinematics hard to program?

For a 2-link planar arm it's a few lines of trigonometry (the law of cosines). It gets harder with more joints and full 3D orientation, where you use libraries or numerical solvers. Most DIY arms only need the simple 2- or 3-link case, which you can code yourself.