amoliksinghcontact
← all projects

Rubik's Cube Solver

Archived

A Java solver driving a stepper-motor machine that turns a real cube

May 2017

  • Java
  • C++
  • Arduino
  • Stepper motors
Solver
Java
Hardware
C++ on Arduino
Solve + turn
~1 minute
Built
May 2017

What it is

A machine that solves a physical Rubik's cube. You enter the scrambled state by clicking squares in a Java GUI; the solver works out a move sequence; Java then sends that sequence over serial to an Arduino running C++, which drives stepper motors that actually turn the cube. Working out the solution and physically turning the cube take about a minute between them.

The distinction matters. A cube solver that prints a move list is an afternoon's work once you know the method. Making the moves happen in the physical world is a different project, and it is where all the interesting failure modes live.

Entering the cube

The GUI draws the cube as two pictures: one showing three faces, the other showing the opposite three. Clicking a square cycles its colour, so you transcribe the scramble by eye.

It also refuses invalid input, which is less obvious than it sounds and more necessary. Most colour arrangements you can click into a net are not reachable on a real cube — wrong colour counts, impossible corner twists, swapped edge pairs. Without that check the solver would happily chase a state that cannot exist, and you would only find out when the motors started turning.

Why two languages

Because the split follows the hardware, not a preference. Java has the GUI and the solving logic, where it is pleasant to write and easy to debug. C++ runs on the Arduino, because that is what drives stepper motors. The serial link between them is the seam.

It is a more honest answer than most “why did you use two languages” stories: each language is sitting on the side of the boundary where it belongs.

The method

The solver follows the beginner's method rather than anything exotic: cross, then corners, then edges, then the yellow cross, then permuting corners, then orienting them. A human layer-by-layer routine, mechanised.

That produces far more moves than a two-phase solver would, and it does not matter much here. When a motor is doing the turning, a longer sequence costs seconds. What you gain is a solve you can verify by eye at every stage, which is worth a great deal when the thing you are debugging has moving parts.