Six-axis robotic arm with servo driver
Build it step by step
0 of 7 doneSet the buck converter
6.0 V on a meter first.
Wire the PCA9685
I2C and common ground.
Test one servo
Unloaded, gentle move.
Find safe limits
Edit the limit tables.
Assemble the arm
Centre every servo first.
Move joints together
Check the smooth motion.
Save and play poses
Repeat a sequence.
How do you build a six-axis robotic arm with servo driver?
A metal 6-DOF arm runs on a PCA9685 servo driver, with smooth moves between saved poses and a serial command interface. You need ESP32 DevKit V1, Robotic arm 6-DOF metal kit, PCA9685 16-channel servo driver, SMPS 12 V 5 A (metal case) and XL4015 5 A buck converter module. It takes 7 steps and about 360 minutes.
- Level
- Advanced
- Time
- About 360 min
- Parts
- 5
Parts list
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| 12 V supply output | XL4015 input | Power in |
| XL4015 output | PCA9685 V+ terminal | Servo power, set to 6.0 V with a meter first |
| PCA9685 VCC | ESP32 3V3 | Logic power |
| PCA9685 GND | ESP32 GND and supply minus | Common ground |
| PCA9685 SDA and SCL | ESP32 GPIO21 and GPIO22 | I2C |
| Servos 1 to 6 | PCA9685 channels 0 to 5 | Yellow signal on top |
| ESP32 USB | Computer | Power and serial commands |
Code
Six servos pulling hard at once can draw more than a small supply gives, which is why the power for the servos comes through its own buck converter and never from the ESP32 board. Before connecting any servo, set the converter output to 6.0 V with a meter and check the common ground. Move one joint at a time at first, because a servo pushed against its stop stalls and draws a lot; the limits in the sketch exist to prevent that, so adjust them to your arm. The sketch moves with an ease-in and ease-out so the arm does not jerk, and saves up to twelve poses you can replay. Keep fingers away from the joints when it moves, and never reach in while the supply is on. The 12 V supply comes as a sealed unit: do not open it, and have the mains connection made with a proper cable and plug, by a qualified electrician if you are unsure. Start each session with the home command in a clear space. Arduino IDE with the ESP32 boards package 2.0.x, board "ESP32 Dev Module".
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// 6-axis arm on a PCA9685 with smooth moves and saved poses. No library needed.
// Serial commands (115200, newline): j 2 90 (joint, angle), save, play, clear, home.
// Board: ESP32 Dev Module.
#include <Wire.h>
const uint8_t PCA = 0x40;
const int JOINTS = 6;
const int MAXPOSE = 12;
float cur[JOINTS] = {90, 90, 90, 90, 90, 90};
float lo[JOINTS] = {10, 20, 20, 10, 10, 60}; // safe limits in degrees: tighten them for your arm before powering the servos
float hi[JOINTS] = {170, 160, 160, 170, 170, 120};
float poses[MAXPOSE][JOINTS];
int nPoses = 0;
void pcaWrite(uint8_t r, uint8_t v) { Wire.beginTransmission(PCA); Wire.write(r); Wire.write(v); Wire.endTransmission(); }
void pcaInit() {
pcaWrite(0x00, 0x10); // sleep so the prescale can be set
pcaWrite(0xFE, 121); // about 50 Hz
pcaWrite(0x00, 0x20); // wake with auto-increment
delay(5);
}
void setServo(int ch, float deg) {
deg = constrain(deg, lo[ch], hi[ch]);
int us = 500 + (int)(deg * 2000.0 / 180.0); // 0.5 to 2.5 ms: check against your servos
int ticks = us * 4096L / 20000;
uint8_t base = 6 + 4 * ch;
Wire.beginTransmission(PCA); Wire.write(base);
Wire.write(0); Wire.write(0); Wire.write(ticks & 0xFF); Wire.write(ticks >> 8);
Wire.endTransmission();
}
void moveTo(float target[], int ms) {
float start[JOINTS]; for (int j = 0; j < JOINTS; j++) start[j] = cur[j];
int steps = max(1, ms / 20);
for (int s = 1; s <= steps; s++) {
float f = (float)s / steps; f = f * f * (3 - 2 * f); // ease in and out
for (int j = 0; j < JOINTS; j++) { cur[j] = start[j] + (target[j] - start[j]) * f; setServo(j, cur[j]); }
delay(20);
}
}
void setup() {
Serial.begin(115200);
Wire.begin(21, 22); Wire.setClock(400000);
pcaInit();
for (int j = 0; j < JOINTS; j++) setServo(j, cur[j]);
Serial.println("Ready. Commands: j N DEG, save, play, clear, home");
}
void loop() {
if (!Serial.available()) return;
String line = Serial.readStringUntil('\n'); line.trim();
if (line.startsWith("j ")) {
int a = line.indexOf(' ', 2); int j = line.substring(2, a).toInt(); float d = line.substring(a + 1).toFloat();
if (j >= 0 && j < JOINTS) { float t[JOINTS]; for (int k = 0; k < JOINTS; k++) t[k] = cur[k]; t[j] = d; moveTo(t, 600); }
} else if (line == "save" && nPoses < MAXPOSE) { for (int j = 0; j < JOINTS; j++) poses[nPoses][j] = cur[j]; nPoses++; Serial.println(nPoses); }
else if (line == "play") { for (int p = 0; p < nPoses; p++) { moveTo(poses[p], 1500); delay(300); } }
else if (line == "clear") nPoses = 0;
else if (line == "home") { float h[JOINTS] = {90, 90, 90, 90, 90, 90}; moveTo(h, 2000); }
}What the serial monitor should show
Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual ESP32 Dev Module with its sensors at their default values. Your numbers will follow your real readings, but the format should match.
Ready. Commands: j N DEG, save, play, clear, home
Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Servo power | 6.0 V under no load |
| Single joint | Moves smoothly to the angle |
| Save two poses and play | Arm moves between them |
| Limits | Joint never hits its stop |
If it does not work
Servos twitch
Check the common ground and the supply current.
ESP32 resets
Power the servos only from the buck converter.
Buzzing at rest
Reduce the load or the limit angle.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the six-axis robotic arm with servo driver?
ESP32 DevKit V1, Robotic arm 6-DOF metal kit, PCA9685 16-channel servo driver, SMPS 12 V 5 A (metal case) and XL4015 5 A buck converter module.
How long does the six-axis robotic arm with servo driver take to build?
About 360 minutes for a advanced maker, in 7 steps.
How do I know the six-axis robotic arm with servo driver works?
Servo power: 6.0 V under no load. Single joint: Moves smoothly to the angle. Save two poses and play: Arm moves between them.
Servos twitch: what should I check?
Check the common ground and the supply current.
ESP32 resets: what should I check?
Power the servos only from the buck converter.
Buzzing at rest: what should I check?
Reduce the load or the limit angle.
