Knob-controlled robot arm
A two-joint arm made of two SG90 servos. Turn a knob and its joint follows. Faber checked that the gripper reaches a target cup before anything was built.
By the Faber team · Featured build · 2026-11-17
The prompt
“Make a small robot arm I can move with two knobs.”
How it was built
- Describe it. "Make a small robot arm I can move with two knobs." Faber planned a planar arm: a 12 cm upper arm on the shoulder servo and a 10 cm forearm on the elbow servo.
- Wire it. Servo signals go to D9 and D10, the two pins Timer1 drives in hardware. Each knob's middle pin goes to an analog input (A0, A1).
- Upload the sketch. It reads both knobs about 50 times a second and turns each reading into a 50 Hz servo pulse of 544 to 2400 µs, the same signal the Servo library makes, without needing the library.
- Test it in the simulator. Turning a knob moves its servo to the matching angle within 1.5 degrees in half a second. Setting the knobs from inverse kinematics puts the gripper inside a cup placed at (15, 4) cm.
- Build the real one. Glue or screw the servo horns to the links, mount the shoulder servo on a heavy base, and power the servos from a separate 5 to 6 V pack.
Wiring
| From | To | Note |
|---|---|---|
| Uno D9 | Shoulder servo signal | Timer1 hardware PWM (OC1A) |
| Uno D10 | Elbow servo signal | Timer1 hardware PWM (OC1B) |
| 5 V supply, GND | Both servos' power | share GND with the Uno |
| Knob 1 wiper | Uno A0 | ends on 5V and GND |
| Knob 2 wiper | Uno A1 | ends on 5V and GND |
The code
The core of robot-arm.ino, as it ran in the simulator:
const uint16_t MIN_US = 544, MAX_US = 2400;
void setPulse(volatile uint16_t &ocr, int angle) {
uint16_t us = map(constrain(angle, 0, 180), 0, 180, MIN_US, MAX_US);
ocr = us * 2; // Timer1 ticks at 2 MHz: 2 ticks per microsecond
}
void setup() {
pinMode(9, OUTPUT); pinMode(10, OUTPUT);
// Fast PWM, TOP = ICR1, non-inverting on OC1A/OC1B, prescaler 8: 50 Hz
TCCR1A = _BV(COM1A1) | _BV(COM1B1) | _BV(WGM11);
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11);
ICR1 = 39999;
setPulse(OCR1A, 90); setPulse(OCR1B, 90);
Serial.begin(115200); Serial.println("arm ready");
}
void loop() {
setPulse(OCR1A, map(analogRead(A0), 0, 1023, 0, 180)); // shoulder
setPulse(OCR1B, map(analogRead(A1), 0, 1023, 0, 180)); // elbow
delay(20);
}
What the simulator tested
- The shoulder servo follows its knob: at 75 % it passes 130 degrees within 1 s.
- Knobs set by inverse kinematics put the gripper in the cup.
- Pulses measured to the CPU cycle: 50 Hz, 1461 µs for 89 degrees.
What it doesn't prove
- Link weight and gravity are not simulated: a real SG90 droops a few degrees under load.
- Two servos on the Uno's 5 V pin can brown out the board when both move; use a separate supply.
- Most SG90s don't reach the full 0 to 180 degrees.
Describe it in one sentence. Faber picks the parts, wires them, writes and tests the code, and designs a case.