Rubik's Cubes are fascinating, and the speed with which professionals (or speedcubers) solve them is even more impressive. As I write this article, the current record for solving a 3x3 Rubik's Cube is 3.134 seconds. My personal record being 14.91 seconds, it's safe to say my chances of becoming a record holder are very slim. At least without robotics …

This project is a robot capable of solving a Rubik's cube. The only human interactions are placing the cube, first on the base used for color detection and then in its solving position. This robot is divided into 2 parts: the logic part (executed by a RaspberryPi4) and the motor control part (executed by an Arduino Mega board).

Materials used:

Mechanics and structure

I first created a CAD model of my robot's structure. It is made of MDF panels (3mm thick) laser-cut. For portability purposes, the wooden structure is designed to be rigid while being assemblable without the use of screws. Other parts are 3D printed and assembled using screws.

Complete robot

Only 5 stepper motors are necessary to solve all 6 faces. In fact, the last rotation can be reproduced by a combination of the other 5. This reduces cost, but also the size of the system. Each motor is designated by a letter according to Singmaster notation: R, L, B, F and D.

The motor rotation is transmitted to the cube by fork-shaped tips inserted in the center of each face.

Tip1Tip2

During the color recognition phase, the cube is placed on a base, positioned on one of its corners. This way, by rotating the base 180°, we reduce the number of rotations and images needed to obtain the scrambled state. Only two shots are necessary. This base is rotated by an AX-12A servomotor.

Camera PoV

The stepper motors of the lateral faces are fixed on a piece that can slide horizontally. It is possible to add the 4 optional servomotors and connecting rods to automate the forward and backward movement of the tips into the cube.

A control box allows launching the different steps and displaying information on a screen.

Lateral motor Control box

Electronics

The stepper motors are controlled by a Ramps 1.4 Shield mounted on an Arduino Mega 2560 with A4988 drivers. The shield is powered by 12V. The A4988 drivers have a current limitation of 0.8A.

For the vision module, the camera is connected to the RaspberryPi board and the AX-12A motor to the shield.

Wiring

Software

The software consists of two programs: the vision algorithm and the solving algorithm.

The vision part is coded exclusively in Python. I use the OpenCV library which allows me to process the 2 captured images and retrieve the colors. On each of these images, the algorithm processes 27 (9 facets × 3 faces) zones. By superimposing the color masks on each zone, we can determine the zone's color by choosing the most represented one.
The scrambled state can be deduced and formatted as a string:

One letter per facet: each letter doesn't correspond to a color (White, Yellow, Red …) but to Down, Up, Right, Left … For example, if the letter is D, the facet is the same color as the center of the bottom face. A solved cube is therefore represented by the following string:

UUUUUUUUURRRRRRRRRFFFFFFFFFDDDDDDDDDLLLLLLLLLBBBBBBBBB

This format is necessary to use the cube solving algorithm. It's the Kociemba algorithm implemented by efrantar. This program provides a solution in a minimum of 20 moves, in Singmaster notation in less than 1 second.

The move list is transmitted via serial communication between the Raspberry and the Arduino, which then takes care of controlling the corresponding motors.

Result

The robot I designed perfectly met my expectations. Except for two human interventions (to move the cube and place it in the center of the manipulators), it manages to solve a Rubik's Cube autonomously, going through the stages of image recognition, solution calculation and its implementation.

The record time I was able to achieve is 2.009 seconds (average time 2.378 s). This time does not take into account the image recognition and solution calculation time. Considering that speedcubers have 15 seconds to observe the cube before solving it, the execution time can be comparable.

With my two seconds, although I could have beaten the world record, it wasn't in the same category. In comparison with other robots, my time doesn't rival the current record in the "robot" category, which is 0.305 s, achieved by Mitsubishi Electric in May 2024. This record time of three-tenths of a second includes not only the complete solving of the cube, but also its observation.