Rubik's Cube® Solver using an Arduino and MATLAB

Solve Rubik’s Cube® using image processing and Arduino-controlled servo motors
2,8K téléchargements
Mise à jour 1 sept. 2016

Afficher la licence

In this entry, we build a robot that solves a Rubik’s Cube® using MATLAB, a SparkFun RedBoard (Arduino Uno clone), two servo motors, and a webcam. The submission contains all of the code used to control the robot, a detailed article describing how the robot was built and programmed, and several videos of the final result. Download this submission if you’re interested in learning about our project. Or use it as a starting point for building and controlling your own Rubik’s Cube solving robot.
In addition to hardware components, this project requires MATLAB and Image Processing Toolbox. It also uses MATLAB Support Package for Arduino® Hardware, which can be downloaded for free here:
The initial setup of the project involved building the robot from readily available materials. In addition to the Arduino device, webcam, and servos, we used LEGO bricks, an acrylic sheet, and hard polystyrene foam. The robot was designed with two main parts. A holder holds the cube from below in an open-topped box and can rotate the cube in the horizontal plane. A gripper arm can be lowered over the cube from above to hold two layers still while the holder rotates one face from below. The gripper arm can also be pushed forward to flip the cube to a different side.
With the entire robot assembled and calibrated, solving the cube involves two steps:
1. Read the initial state of the scrambled cube.

MATLAB functions were written to control the servo motors on the Arduino so they could rotate the entire cube in the holder and flip it to a different side. These functions are used to rotate the cube so each of the 6 faces are facing up and capture an image of the face with a webcam. Using Image Processing Toolbox, the color of each facelet is determined. A custom MATLAB UI is used to validate the results and correct any errors.

2. Solve the cube.

The algorithm used for solving the cube is the Thistlethwaite 45 (T45) algorithm. It was used because a MATLAB implementation of the algorithm was already available on the MATLAB Central File Exchange as part of the submission here:

The output of the T45 algorithm determines which faces should be turned. This is then converted to a sequence of moves on the robot that could rotate the cube, flip it to a different side, and turn a single face. Once all the steps are complete, the cube is solved.

Citation pour cette source

MathWorks MATLAB Hardware Team (2024). Rubik's Cube® Solver using an Arduino and MATLAB (, MATLAB Central File Exchange. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2014a
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
En savoir plus sur Recognition, Object Detection, and Semantic Segmentation dans Help Center et MATLAB Answers

Inspiré par : Rubik's Cube Simulator and Solver


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Publié le Notes de version

Updated license

Added Trademark recognition (®) to first mention of Rubik's Cube® in each section, both in the File Exchange Title/Summary/Description and in the text of the html article which is part of the submission.