Skip to main content

Raspberry Pi Robot Solves Rubik's Cube

Andrea Favero's Rubik's Cube-solving robot
(Image credit: Andrea Favero)

That Rubik’s Cube you bought in 1981 and never solved may have met its match in this cube-solving robot, created by Andrea Favero and brought to our attention by Hackaday (opens in new tab). The ‘bot, powered by a Raspberry Pi 4 (opens in new tab), uses a camera, some Python code, two servo motors and a stepper to solve a typical jumbled 3 x 3 cube in less than a minute.

Surely an invention destined for our list of the best Raspberry Pi projects (opens in new tab), Favero has shared his entire method on Instructables (opens in new tab), and helpfully used only off-the-shelf components and 3D prints (plus some plywood) rather than custom PCBs, making it easier for anyone to build their own version. 

The camera used is the standard Raspberry Pi Camera (opens in new tab) v1.3 (the 5MP module) that plugs into the board’s CSI (camera) port with a ribbon cable - you’ll need a slightly longer one than usual, with Favero saying 50CM is perfect. 3D printed parts hold the camera and motors on top of a plywood case which houses the Pi, and there's an on/off button and dual LCD displays, which show the time taken and helpful messages such as ‘cube done’, while a smiley face on the inside of the arm that houses the camera is a nice touch. Power is handled by a couple of DC to DC buck transformers, turning a 20V feed into something more suitable for the Pi and motors.

The clever computer vision stuff for the Pi all comes thanks to the Python libraries CV2 (opens in new tab) (OpenCV) and Numpy (opens in new tab). The image analysis of the camera feed determines the colors and where they sit in an unfolded cube model. Parameters like the camera’s auto white balance and exposure gain are fixed to ensure that the colors it returns are consistent, and the information about the colored blocks is passed to a Rubik’s Cube solving algorithm (opens in new tab) from Hegbert Kociemba. This returns a sequence of moves, and the motors take care of spinning the cube on its various axes, holding the bottom segment so that changes can be made.

The build guide provided by Favero is so detailed, the hardest part about building yourself a Rubik’s Cube robot may be sourcing the Pi board itself, as the worldwide chip shortage, and an increase in demand (opens in new tab), continues to bite. 

Ian Evenden
Ian Evenden

Ian Evenden is a UK-based news writer for Tom’s Hardware US. He’ll write about anything, but stories about Raspberry Pi and DIY robots seem to find their way to him.