กลับไปหน้ารวมไฟล์
spinnercube-rubiks-cube-solver-robot-18-seconds-4a4f7b-en.md

Scope of work

This project uses Arduino, Python, and OpenCV to solve the Rubik's cube. The main goal was to obtain a cheap robot which could solve the Rubik's cube in less than one minute.

However, I need to mention that my additional idea was to design a T-shirt with some ideas to talk about with other people—so this project requires understanding some fundamental maths and training yourself in Python and OpenCV.

Rubik's cube T-shirt - final design

Technical Motivation

I was checking some Rubik's cube solver robots and I got captivated by the ingenuity of the LEGO robot named SpinnerCube.

Project Overview

The "SpinnerCube" is an advanced mechatronic system that combines computer vision, high-speed mathematical algorithms, and precision motion control to solve a Rubik's Cube in under 18 seconds. This project is a cross-disciplinary engineering feat, utilizing Python with OpenCV for real-time image processing and an Arduino UNO for low-level control of Bipolar Stepper Motors. By following the Kociemba algorithm, the robot calculates an optimal path to the solved state (typically 20-27 moves) and executes the sequence with micro-second accuracy, demonstrating the synergy between desktop-level computing and embedded hardware.

Technical Deep-Dive & Control Logic

  • Computer Vision Pipeline (OpenCV): The computer vision system must handle various lighting conditions and color shades. Using a webcam, the Python script executes HSV (Hue, Saturation, Value) filtering to identify the nine stickers on each face. The stickers are then mapped to a string representation of the cube's state (e.g., URFDLB notation). This "vision-to-algebra" conversion is the most computationally intensive part of the solving workflow.
  • Kociemba's Two-Phase Algorithm: Once the cube state is known, the Python backend runs the Kociemba algorithm. This search algorithm splits the problem into two phases: first, reducing the cube to a subgroup where it can be solved with restricted moves, and second, finding the final solution. This mathematical strategy ensures a near-optimal solution path, minimizing the mechanical wear on the stepper motors.
  • Serial Communication Protocol: The solution (a series of moves like R2 U' L) is transmitted from Python to the Arduino via Serial UART. The Arduino parses these ASCII commands into a coordinated sequence of pulses for the A4988 Stepper Drivers.
  • Stepper Motor Optimization: To reach the 18-second mark, the Arduino firmware must implement acceleration and deceleration ramping. Instantaneous starts would cause the stepper motors to slip due to the cube's inertia. By using a trapezoidal velocity profile, the robot maintains maximum torque while reaching high angular velocities during $180^\circ$ turns.

Engineering & Hardware Insights

  • A4988 Driver Tuning: The A4988 drivers are tuned using a multimeter to set the Current Limit (Vref). This ensures the bipolar steppers have enough torque to overcome the internal friction of the cube without overheating the drivers or the motor coils.
  • Flexible Shaft Couplers: The use of flexible couplers between the motor shafts and the cube-holding arms is critical. They compensate for minor misalignments, preventing mechanical binding and ensuring a smooth, repeatable rotation.
  • Power Management: Solving a cube requires high peak currents from all three motors simultaneously. The project utilizes large decoupling capacitors (10µF+) on the power rails to prevent voltage sags from resetting the Arduino during high-speed transitions.
  • Open-Source Philosophy: The project's GUI and firmware are designed with modularity in mind, allowing other developers to upgrade the vision model or adapt the code for different mechanical architectures (e.g., transitioning from 3 to 6 motors).

Operation

This robot uses 3 stepper motors to perform all the moves of the cube's faces URFLDB. The stages are:

  • To capture sticker's color face by face, according to a sequence
  • To process each face, using Python and establish the scrambled initial position of the cube
  • To solve the cube by the Kociemba algorithm
  • To send the solution from Python to Arduino through the serial port
  • From Arduino, to perform all the moves as soon as accurate and as repeatable as possible!!!
SpinnerCube-30 seconds

Best Time reached

In order to obtain a good time record, one easy trick to perform with these robots based on stepper motors is an inverse sequence. However, it is easy to identify if the solution is real because Kociemba normally solves the cube with 20 to 27 moves, and other methods like Fridrich, CFOP, normally solve in more moves. By the way, I am not interested in a Record as my main goal; I am interested in learning, but looking for physical limits, without tricks, is a good exercise to go with patience in the calibration process - Fine Tuning.

Consequently, depending on the robot model, there is a physical limit; in this case, the stepper motors have adequate torque to move the faces and a maximum speed and acceleration associated. However, the delays between moves and the spins for U(up), D(down), B(back) moves are constraints.

I have seen working Spinner Cube robots based on Servos, and the speed to solve is better. In the near future, I will share with all of you my project with this model based on servos.

In this case, playing with calibration settings, I got 18 seconds as my minimal time.

In this video you can see how after iterations, I got 18 seconds (different scrambled positions-same calibration parameters):

18 seconds to solve (Different scrambled positions-equal calibration parameters)

Developer

I can share with you my complete software development; this is open source.

An application was developed with Arduino and Python to integrate the program, solve the cube, and control the robot. This helps us to test and make more efficient the input of the cube state and to take pictures.

This APP uses programming strategies from other open-source developers and was tuned for weeks in order to teach the system to watch and extract sticker's color.

GUI-Arduino/Python Software

What for?

The answer to this question will be given to the readers in the near future; now this answer could be to develop a product for a niche of people who like Rubik's cube. Let's see what happens.

ข้อมูล Frontmatter ดั้งเดิม

apps: []
author: "hbolanos2001"
category: "Gadgets, Games & Toys"
components:
  - "3x Capacitor 10 µF"
  - "1x Wire Stripper & Cutter, 32-20 AWG / 0.05-0.5mm² Solid & Stranded Wires"
  - "1x Mastech MS8217 Autorange Digital Multimeter"
  - "1x Arduino UNO"
  - "3x Stepper Motor, Bipolar"
  - "1x Jumper wires (generic)"
  - "3x Stepper motor driver board A4988"
  - "3x shatf coupler flexible"
description: "Using the legacy of brilliant mathematicians, this robot solve the cube in 18 seconds or less."
difficulty: "Intermediate"
documentationLinks: []
downloadableFiles: []
encryptedPayload: "U2FsdGVkX1/bVG6kCt+Rg3h7YowoxxOb4sW6G+ysZ/n2lPF4r34er+6BuYKhQVO76MkzylkG41i0PSntXxXI1W5PysxXy/xxRNWR5ri+qGPpC3eHS9kfzEr0TM3+AJXeAHBdN+aDqOSPBWeEwb0qaubVwscwqtgks5SAZ2A3B5LujcPzmgT5EDWy3vUaCl7otxcsnBZTL/W4GU69SU+3wySEhbHWoGpOX4EFZT2m7Yg="
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/spinnercube-rubiks-cube-solver-robot-18-seconds-4a4f7b_cover.jpg"
lang: "en"
likes: 8
passwordHash: "5da8116acae2584321f4673f66aa0e06824f3521a1bdd881f902e84a2e1464c9"
price: 699
seoDescription: "Build SpinnerCube, a Rubik's cube solver robot that solves the cube in under 18 seconds using Arduino and advanced mathematical algorithms."
tags:
  - "stepper motors"
  - "rubik´s cube"
  - "robots"
title: "SpinnerCube - Rubik's cube solver robot -18 seconds"
tools: []
videoLinks:
  - "https://www.youtube.com/embed/7Tx0p5Vo24s"
  - "https://www.youtube.com/embed/dd1Z84myVOU"
views: 13153