Skip to content
Mustafa Tarhan

Rubik's Cube Solving Machine

Scan, solve and physically turn a scrambled 3×3×3 cube at the push of a button.

Embedded systems · course project2023 – 2024Complete
Top view of the cube-solving machine: a Rubik's cube in the centre gripped by four stepper motors mounted on linear rails, arranged in a cross on a wooden board.
The finished machine, March 2024. Four stepper motors on linear rails grip and turn the cube.
Role
Course project at HTW Berlin: mechanics, camera controls, solver, motor control and the Buildroot image, each module buildable and testable on its own.
Motors
4 steppers
OS
Buildroot Linux
Stack
C++, OpenCV, Raspberry Pi 4, Buildroot, GPIO, A4988 stepper drivers, Make, GitLab CI

The machine

Press a button and the machine solves a scrambled cube by itself. The software is three modules, each with its own Makefile and tests: camera controls, the algorithm and hardware controls. A main program ties them together on a Raspberry Pi 4 running a Linux image built with Buildroot.

Architecture

  1. Camera controls
    • Capture each face
    • Dominant colour per sticker
    • Match colours to centre pieces
  2. Algorithm
    • Cube model6 faces, face turns
    • Staged solvercross → F2L → last layer
  3. Hardware controls
    • Move translation
    • Stepper controlGPIO → A4988, 90° = 50 steps
The three modules of the repository.

Reading colours and finding moves

Colours. For each sticker the pixels are clustered by colour distance and the biggest cluster wins, which copes with uneven light across a sticker. Each sticker is then matched to the nearest centre colour, because the six centre pieces define the six faces.

Moves. Instead of one huge search, the solver follows the layer-by-layer method people use: white cross, first two layers, yellow cross, alignment, then the last layer's edges and corners. Each stage runs a depth-limited search over a short list of moves and move sequences that can't break what the earlier stages solved, so every search stays small.

Hardware

Four stepper motors sit on linear rails around the cube. They slide in to grip a face and turn it in 90° steps. The mechanics went through two builds and two chassis prototypes, all photographed in the repository.

Side view of the machine: the cube held between two stepper motor shafts above a black base plate.
Side view of the second build. The cube is held between the motor shafts above the base plate.