Arduino Marble Labyrinth
Make your own tilt-controlled marble labyrinth using Arduino, servo motors, and cardboard.
- Arduino
- Intermediate
- 90 minutes
- 5 steps
Shop this project
CartYou'll need
Arduino Uno Rev 3Board Only$32.24
Small Servo$6.99
400 Hole Solderless Breadboard$4.79
Male-Male Jumper Wires (Set of 65-assorted sized and colors)$6.99
Prices from vilros.com. Tax and shipping at checkout.
Before you start, you'll need
- Arduino Uno
- 2 servo motors
- Joystick module or accelerometer
- Breadboard
- Jumper wires
- Cardboard
- Marble
- Glue and tape
Build the cardboard labyrinth
About 30 minutes
Create a tilting maze platform.
- Cut a large cardboard square as the base of your maze.
- Draw or glue cardboard strips to create maze walls.
- Leave a starting point and an ending goal.
- Attach the base to two servo motor arms so it can tilt in X and Y directions.
You should see
The cardboard maze is built and mounted on the servos.
Wire the servo motors
About 15 minutes
Connect servos for X and Y tilt control.
- Connect the first servo (X-axis) to digital pin 9.
- Connect the second servo (Y-axis) to digital pin 10.
- Connect both servo power wires to 5V and ground wires to GND.
You should see
Both servos are powered and connected to the Arduino.
Connect the joystick
About 10 minutes
Wire the joystick to control the maze tilt.
- Connect the joystick VCC to 5V and GND to GND.
- Connect the joystick X-axis output to analog pin A0.
- Connect the joystick Y-axis output to analog pin A1.
You should see
The joystick is wired and can be read by the Arduino.
Write the control sketch
About 25 minutes
Map joystick input to servo positions.
- Open Arduino IDE and create a new sketch.
- Copy the complete labyrinth control sketch below.
- The sketch reads joystick values and maps them to servo angles.
- Upload to your Arduino.
#include <Servo.h>
Servo servoX;
Servo servoY;
const int joystickXPin = A0;
const int joystickYPin = A1;
int centerX = 512;
int centerY = 512;
int deadZone = 50;
void setup() {
servoX.attach(9);
servoY.attach(10);
servoX.write(90);
servoY.write(90);
Serial.begin(9600);
}
void loop() {
int joyX = analogRead(joystickXPin);
int joyY = analogRead(joystickYPin);
int servoXAngle = 90;
int servoYAngle = 90;
if (abs(joyX - centerX) > deadZone) {
servoXAngle = map(joyX, 0, 1023, 60, 120);
}
if (abs(joyY - centerY) > deadZone) {
servoYAngle = map(joyY, 0, 1023, 60, 120);
}
servoX.write(servoXAngle);
servoY.write(servoYAngle);
delay(15);
}Adjust deadZone and map() ranges to control sensitivity. Center position is 90° for both servos.
You should see
Moving the joystick tilts the maze platform smoothly.
Play the marble labyrinth
About 10 minutes
Test the game and adjust sensitivity.
- Place a marble at the starting point.
- Use the joystick to tilt the maze and guide the marble to the goal.
- Adjust the map() ranges in your sketch to fine-tune the tilt responsiveness.
You should see
You can successfully guide the marble through the maze.
It didn't work
Servos move too quickly or jerkily.
Add small delays between servo writes, or use servo.writeMicroseconds() for finer control.
What to do next
Stuck? Contact Vilros Support with your board model and what you see on screen.