Robotics · in-house development

ArmControl:
Robot arm with custom control

I turned a kit into a fully controllable robot arm, with custom firmware, inverse kinematics, 3D simulation and a web interface for defining points and paths.

Arduino Mega 2560 RAMPS 1.4 3 axes + rail Python back end Inverse kinematics Custom C++ firmware
Interactive

Control the arm in your browser

The demo uses the same inverse kinematics as the real software: you set a target point, and the program works out how the joints need to be positioned.

TCP -
Joints -
⚠ out of reach
Drag = rotate · mouse wheel = zoom

Target position (Cartesian)

Jog

Tool & demo

Ready.
What is inside

From kit to real control system

The software that came with the kit was only a simple remote control. So I rewrote both the firmware and the PC software from scratch.

Inverse kinematics

You enter X, Y and Z in millimetres, and the software calculates the joint angles. The gripper stays level throughout.

3D simulation

A live 3D view always shows the arm's current pose. I programmed it myself, without third-party libraries.

Points & paths

Positions can be saved and revisited. Waypoints, pauses and tool actions combine into complete sequences, which can also run in a loop.

Safety

Moves end before the mechanical stops, and unreachable targets are rejected. STOP halts, the emergency stop switches the motors off.

Light barrier

On the rotary axis, a light barrier replaces the mechanical limit switch.

Reverse engineering

I first decoded the original firmware's protocol by disassembling its machine code. Today the arm runs completely custom firmware.

Calibration assistant

Ten guided steps check limit switches and directions and calibrate the arm.

Synchronised axes

All axes start and stop together; none runs ahead.

Wi-Fi bridge

If you like, an ESP32 replaces the USB cable with a Wi-Fi link.

Technology

Technology used

Everything runs locally on your own computer, with no cloud and no heavy add-on packages.

Hardware: Arduino Mega 2560 + RAMPS 1.4, 3× stepper motor + linear lead screw, optional ESP32 as a Wi-Fi bridge
Firmware: C++ / Arduino, AccelStepper, own G-code parser
Back end: Python, pyserial, HTTP + server-sent events
Front end: HTML / CSS / JavaScript, canvas 3D
Mathematics: Inverse & forward kinematics for the parallelogram linkage, synchronised axes
Electronics

All connections at a glance

An Arduino Mega 2560 with a RAMPS 1.4 shield drives three stepper motors for the joints and one for the rail. On the rotary axis, a light barrier sits instead of a limit switch, so the axis can safely spin through.

Complete wiring of the robot arm
The wiring, with motors, limit switches, light barrier, Bluetooth and power supply.
FunctionConnection (RAMPS)Pin
Main arm (X, joint 1)Y driver slotSTEP/DIR/EN
Forearm (Y, joint 2)X driver slotSTEP/DIR/EN
Rotary axis (Z)Z driver slotSTEP/DIR/EN
Linear rail (E)E0 driverSTEP/DIR/EN
Limit switch, forearmX-minD3
Limit switch, main armY-minD14
Light barrier, rotary axisZ-min (S/−/+)D18
Gripper / suction cup / fanFET outputsD9 / D10 / D8
ESP32 Wi-Fi bridge (optional)AUX-4 (Serial2)D16 TX2 / D17 RX2
Power supplyPower supply unit12 V DC
Mathematics

How the arm positions its joints

You specify a point in space, and the arm sets its joints by itself so that it reaches it. This method is called inverse kinematics. For an arm with two joints on a turntable, it can be solved exactly.

Base plate / rail Height h₀ a b Shoulder Elbow Target (TCP) Reach r Height z

How it is calculated

First the turntable rotates until the target lies in the plane of the arm:

Base = atan2( X , Y )

Reach r and height z give the distance d. The law of cosines gives the arm angles:

d = √( r² + z² )
Elbow = acos( (a² + b² − d²) / (2ab) )
Shoulder = atan2( z , r ) + acos( (a² + d² − b²) / (2ad) )

If d is greater than a + b or less than |a − b|, the target is unreachable. The software then does not move.

The forward kinematics calculates the real position back from the joint angles. That way the 3D view always shows where the arm is.

Manual

Technical manual

Six steps from installation to your first program.

1 · Start the software

Install Python 3, run pip install pyserial once and then start Start_Windows.bat. The interface opens in the browser at localhost:8000.

2 · Flash the firmware

In the Arduino IDE, install the library AccelStepper. Then open RobotArmFW.ino, select the board “Mega 2560” and upload the firmware.

3 · Connect & check

Select the port (USB or “ESP32-Brücke”) and connect. Use M119 to test the limit switches; the light barrier then reports “interrupted = 1”. Only after that, make small jog steps.

4 · Homing

With G28 each axis moves to its limit switch and sets the zero point there. You can abort with STOP (button or !) or with the emergency stop (space bar).

5 · Calibrate

The assistant guides through calibration in ten steps. Then the limits before the stops are taught.

6 · Safety

Moves end before the calibrated limits, and unreachable targets are rejected. STOP halts, and the motors stay energised. The emergency stop switches them off.

Command reference (G-code)

CommandFunction
G0 / G1 X Y Z E F [S0]Axis move, all axes in sync; S0 moves them independently
G4 S<s>Pause / dwell time
G28 [X Y Z]Homing (can be aborted)
G90 / G91Absolute / relative mode
G92 X Y Z Eset current position
M17 / M18motors on / off
M42 P<pin> S<0..255>switch output (gripper/suction cup/fan)
!STOP: aborts any movement; the motors stay energised
M112Emergency stop: halts immediately and switches the motors off
M114report position
M119report limit switch states

The complete guide is included in the download as FIRMWARE_ANLEITUNG.md and LIESMICH.md files.

Gallery

The arm in different poses

The images show poses from the 3D simulation.

A look at the code

How the program calculates the joint angles

This excerpt shows how a target point becomes joint angles: trigonometry for the two arm joints plus a rotation of the base.

server.py: inverse kinematics (abridged)
def cart_to_joints(self, x, y, z, e):
    # world coordinates [mm] -> joint angles of the parallelogram arm
    a, b = g["lower_arm"], g["upper_arm"]
    dx   = x - e                                  # arm base sits on the rail
    base = math.degrees(math.atan2(dx, y))        # base rotation
    r = math.hypot(dx, y) - g["tool_offset_h"]                  # reach
    h = z + g["tool_offset_v"] - g["base_height"]      # height above shoulder
    d = math.hypot(r, h)
    if d > a + b:
        raise ValueError("point too far away")
    th1 = math.atan2(h, r) + math.acos((a*a + d*d - b*b) / (2*a*d))  # main arm
    th2 = math.atan2(h - a*math.sin(th1), r - a*math.cos(th1))   # forearm, absolute
    # … check angle limits and scissor angle, convert to joint units
    return joints, angles
Orientation

The axes at a glance

As coordinates, the letters X, Y and Z mean something different than in G-code. Click a row to highlight that axis in the picture.

LetterAs a coordinate As a joint (G-code)
Xleft / right in mmMain arm angle (joint 1)
Yforward / back in mmForearm angle (joint 2)
ZHeight in mm Base rotation
E-Rail in mm
A common mistake

A G1 Z50 does not move 50 mm upwards; it rotates the base. For height, use the Cartesian jog or the coordinate input.

Inverse kinematics

Why a straight path takes a lot of calculation

If all joints turn evenly, the tip moves in an arc. For a true straight line, the path is split into small steps and the inverse kinematics is calculated for each and every one of them. In the demo you can compare both approaches.

X
Y
Z
X
Y
Z
Distance -
Steps -
Path reachable -
Largest joint jump -
Arc error without IK -

Top view · X / Y

Side view · reach / height

Joint angles along the path

Linear move with IK: true straight line Joint interpolation: arc unreachable
Source code on request

Download project

Firmware, control software and guides come in one package. The software runs on any PC with Python.

⭳ Request ArmControl.zip
Contents: server.py · static/index.html · firmware/RobotArmFW.ino · guides · documentation
Download on request: sign in, and I will unlock the download for you.

Contact

Write to me if you have questions about how it is built, would like to know why I solved something a certain way, or want to use the controller for an arm of your own.

Arithmetic check Arithmetic task, shown as an image

Your details are processed in order to answer your enquiry. More in the privacy notice.

No Google captcha, no cookies, no disclosure to third parties. Alternatively by e-mail to info@timobritz.de.