Rubik's Cube
Solver Bot
A full-stack hardware + software system combining OpenCV computer vision, Kociemba's two-phase algorithm, and a custom mechanical translation engine to physically solve a Rubik's Cube using Arduino-driven servo motors.
~20
Moves to solve
54
Character state string
3
Servo mechanisms
1st Place
EMR Embedx β Embedded Systems Competition
Category
Embedded Systems & Robotics
Team Size
4 Members
My Role
Team Lead & Computer Vision Engineer
Competed against teams with a fully functional autonomous Rubik's Cube solving robot β demonstrated live scanning, solving, and mechanical execution on stage.
The Core Challenge
Bridging the gap between mathematical optimality and physical mechanical constraints.
Theoretical Solver
Kociemba Two-Phase Algorithm
Kociemba's algorithm produces an optimal solution in ~20 moves from any scrambled state. However, it operates in an abstract mathematical space β any face can be rotated from any direction, regardless of physical accessibility.
solution = "U2 R F' D B2 L U R2 D2"
// U=Up, R=Right, F=Front, D=Down β unrestricted
Physical Robot
3-servo constrained mechanism
The physical robot can only interact with the cube from one fixed orientation using three servo mechanisms. Every mathematical move must be translated into a valid sequence of flip, block, and rotate operations.
Flipper
Tilts cube 90Β°
Blocker
Holds position
Rotator
Spins bottom face
The Fundamental Mismatch
A solver output like R F' U tells the robot to rotate the Right face, then the Front face, then the Up face β but physically, the robot can only ever access the bottom face. To rotate the Right face, the cube must first be flipped to the correct orientation, the move executed, then potentially re-oriented for the next move.
Naively translating each move independently generates redundant flip-unflip sequences that cancel each other out β tripling execution time. The key innovation is a cost-optimized, stack-based reduction algorithm that eliminates these redundancies before they reach the hardware.
System Overview
Four-stage pipeline from physical cube to solved state β vision, cognition, translation, and execution.
Scan
OpenCV + Webcam
Webcam captures each of the 6 cube faces. OpenCV detects color regions using HSV masking. Each of 54 stickers is classified into one of 6 colors and encoded into a positional string.
Solve
Kociemba Algorithm
The 54-character cube state is passed to a Python implementation of Kociemba's Two-Phase Algorithm. Phase 1 reduces the cube to a subgroup; Phase 2 solves within that subgroup optimally in β€20 moves.
Translate
Custom Stack Algorithm
The KEY INNOVATION. Maps abstract moves (U, R, F, D, L, B) to physically valid servo operations. Uses cost-based optimization and stack-based cancellation to minimize redundant flip operations.
Execute
Arduino + Servos
Optimized commands are sent over USB serial to an Arduino Uno. The Arduino interprets each command and drives the three servo motors β flipper, blocker, and rotator β in precise timed sequences.
System Architecture
Three decoupled layers β each independently testable, each solving a distinct class of problem.
Computer Vision
OpenCV + Python
- Webcam captures each of the 6 faces sequentially
- HSV color space used for illumination-invariant detection
- Detection of each of the 9 stickers per face
- K-means clustering maps detected colors to 6 canonical cube colors
- Face ordering follows a fixed scanning protocol (UβRβFβDβLβB)
- Output: 54-character string
Kociemba Solver
Two-Phase Algorithm
- Phase 1: Reduces cube to subgroup G1 (edges oriented, corners partially solved)
- Phase 2: Solves within G1 subgroup using only half-turn moves
- Precomputed pruning tables enable fast look-ahead in search tree
- Guarantees solution in β€20 moves (God's Number proven 2010)
- Python `kociemba` library wraps the optimized C implementation
- Typical solve time: <100ms on modern hardware
Mechanical Translation
Custom Stack Algorithm
- Maps 18 possible cube moves (U/D/F/B/L/R Γ CW/CCW/180Β°) to servo sequences
- Maintains virtual orientation state β tracks current cube face at bottom
- Stack-based cancellation removes inverse operation pairs before emission
- Cost table assigns operation weight per face; selects minimum-cost path
- Lookahead optimization leaves cube in best position for next move
- Outputs compact binary command list sent over USB serial at 9600 baud
Algorithm Deep Dive
Why Kociemba alone is insufficient β and the custom translation layer that bridges the gap.
Why Kociemba Alone Is Insufficient
Kociemba's Two-Phase Algorithm solves any Rubik's Cube in at most 20 moves β this is mathematically proven (God's Number). It works in an abstract group space where any of the 6 faces can be rotated independently at any time.
The algorithm has no concept of physical orientation β it outputs a flat sequence like U R2 F B R B2 R U2... with no knowledge of how those moves will be physically executed.
Stack-Based Move Reduction
The translation algorithm maintains a virtual orientation state β tracking which face of the cube is currently at the bottom (accessible to the rotator servo). Instead of resetting to a canonical position between every move, it carries forward the current orientation and finds the cheapest path from the current state to the required state for the next move.
Without Reduction
With Stack Reduction
The stack tracks pending orientation changes and cancels inverse operations before they are emitted (e.g., a FLIP_FORWARD followed by a FLIP_BACKWARD that accomplishes nothing gets eliminated). This is analogous to peephole optimization in compiler design.
Cost-Based Move Optimization
Each face has a different physical cost to access from the current orientation. The algorithm uses a precomputed cost table to choose the minimum-cost transition path. When multiple reorientation paths have equal cost, it selects the one that leaves the cube in the best position for the next move (lookahead optimization).
| Face | Op Cost | Physical Sequence |
|---|---|---|
| D (Bottom) | Direct β no flip needed | |
| U (Top) | Flip Γ 2 + rotate | |
| F (Front) | Single flip + rotate | |
| B (Back) | Flip Γ 2 opposite | |
| L (Left) | Single flip + 90Β° rotation | |
| R (Right) | Single flip + 270Β° rotation |
Hardware Stack
Three servo mechanisms, one Arduino, and a clean serial protocol β minimal hardware, maximum precision.
Arduino Uno
Main Controller
Receives serial commands from Python host, drives PWM signals to each servo, and manages timing between operations.
Flipper Servo
Cube Orientation
Grips the cube from one side and physically tilts it 90Β° to change which face is accessible to the rotator.
Blocker Servo
Position Lock
Engages to hold the top portion of the cube stationary while the rotator spins only the bottom layer.
Rotator Servo
Face Rotation
Grips and rotates the bottom face of the cube β executes the actual cube moves after the flipper has positioned the correct face at the bottom.
Power Supply
5V Regulated
Servos draw significant current under load. A dedicated 5V rail prevents Arduino resets caused by voltage drops during simultaneous servo actuation.
Host Computer
Vision + Solver
Runs the computer vision pipeline and Kociemba solver. Connects to Arduino over USB and streams translated commands after solving.
Wiring Schematic

See It in Action
Full team walkthrough and live solve demonstration from the competition floor.
Video 01 / Team Presentation
Team Explanation β System Walkthrough
Video 02 / Working Demo
Live Demo β Autonomous Cube Solve
~20
Avg Moves
Kociemba optimal
9600
Serial Baud
USB-B protocol
30
Vision FPS
OpenCV capture
3
Servos
Flip / Block / Rotate
Build Gallery
Competition, hardware build, and live demos.

Team Group Photo

EMR Embedx 2026 β Award Ceremony

Final Assembly

EMR Embedx 2026 β Group Photo

Evalutation
My Contribution
Individual ownership within a collaborative team project.
Computer Vision Pipeline
- Designed and implemented cube state detection pipeline using OpenCV
- Mapped webcam input to structured 3Γ3 grid using coordinate-based ROI extraction
- Converted BGR frames to HSV color space for lighting-invariant color detection
- Applied morphological operations (opening/closing) to reduce noise and improve segmentation
- Developed color classification logic to map detected stickers into URFDLB representation
- Ensured consistent detection across varying lighting conditions through threshold tuning and filtering
- Generated accurate 54-character cube state string for solver input
Hardware & Firmware
- Designed and implemented servo control system using Arduino Uno for cube manipulation
- Controlled multiple servo motors (flipper, blocker, base rotation) using PWM signals
- Developed firmware to parse and execute command sequences received over serial communication
- Implemented synchronized motion logic to coordinate clamping, rotation, and flipping actions
- Integrated Python backend with Arduino via PySerial for real-time instruction streaming
- Optimized execution timing to ensure stable operation under mechanical constraints
- Debugged hardware issues including servo jitter, timing delays, and power stability
Technologies I worked with directly
View Source Code
Full source code including OpenCV pipeline, Kociemba integration, custom translation algorithm, Arduino firmware, and wiring schematics.