Inverse Kinematics on Arduino: 6-DoF Robotic Arm
3D coordinate-based motion control and servo actuation using C++ on Arduino Uno
Project Overview
This project implements inverse kinematics (IK) for a six-degree-of-freedom robotic arm controlled by an Arduino Uno. The system computes the joint angles needed to position the gripper in 3D space and tilt it to a defined global Z-axis angle.
Development Goals
The main goals were to learn practical robotics kinematics, build a modular embedded software architecture, and implement 3D coordinate-based servo control within the Arduino’s limited resources.
Hardware Setup
- 6 × MG996R servo motors
- PCA9685 16-channel PWM driver (Adafruit library)
- Arduino Uno microcontroller
- External 5 V power supply for servos
- Aluminum 6 DoF arm frame (custom assembly)
The PCA9685 module communicates via I²C and provides independent PWM signals for each servo. An external 5 V supply powers the motors safely, while the Arduino handles only logic control.
Software Architecture
The firmware is fully modular and divided into three main components:
- ik_solver.cpp / .h — Computes joint angles from (X, Y, Z, tilt, rotate)
- servo_driver.cpp / .h — Handles servo movement and angle limits via PCA9685
- interface.cpp / .h — Parses serial commands like
GOTO X=150 Y=0 Z=120 TILT=90
Each module is independent, making the system easy to extend (e.g., adding sensor feedback or trajectory planning later).
Inverse Kinematics Implementation
The IK solver uses geometric relationships between link lengths and angles to find a valid set of joint positions for a given target. The model includes real-world offsets and measured angle corrections for physical servo mounting differences.
// Example from ik_solver.cpp
Angles solveIK(float x, float y, float z, float wristTilt, float wristRotate) {
Angles a;
a.theta0 = atan2(y, x); // base rotation
// project wrist length and solve shoulder/elbow geometry
// includes measured link lengths: L1–L5
...
return a;
}
The system currently supports up to four active degrees of freedom (Base, Shoulder, Elbow, Wrist Tilt) and calculates the gripper orientation relative to the global Z-axis.
Servo Control & Serial Interface
Each servo is smoothly interpolated between angles to avoid jerky movements. Commands are sent over USB as simple text lines:
GOTO X=150 Y=0 Z=120 TILT=90 ROTATE=90
GRIP OPEN
GRIP CLOSE
The firmware validates coordinate reachability and servo limits before movement to ensure safe operation.
Mechanical Model
Link lengths and offsets used in the calculation:
- L1 = 85 mm — Base height
- L2 = 23 mm — Horizontal offset to shoulder tilt axis
- L3 = 105 mm — Upper arm
- L4 = 150 mm — Forearm
- L5 = 180 mm — Wrist + gripper length
All coordinates are interpreted in a right-handed 3D coordinate system with the base as the origin.
Results & Lessons Learned
- Reliable 3D positioning of the gripper using geometric IK
- Safe servo motion with angle limits and smooth interpolation
- Modular C++ design for debuggable and extensible code
This project was a practical exercise in applying mathematics and embedded software to a real mechanical system. It highlighted the value of step-wise development — starting from 2D IK, then expanding to 3D and adding wrist control — to manage complexity and ensure reliability.
Source Code & Documentation
All source files and a detailed technical report are available on GitHub.