Skip to content

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

Cart

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.

  1. Cut a large cardboard square as the base of your maze.
  2. Draw or glue cardboard strips to create maze walls.
  3. Leave a starting point and an ending goal.
  4. 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.

  1. Connect the first servo (X-axis) to digital pin 9.
  2. Connect the second servo (Y-axis) to digital pin 10.
  3. 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.

  1. Connect the joystick VCC to 5V and GND to GND.
  2. Connect the joystick X-axis output to analog pin A0.
  3. 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.

  1. Open Arduino IDE and create a new sketch.
  2. Copy the complete labyrinth control sketch below.
  3. The sketch reads joystick values and maps them to servo angles.
  4. Upload to your Arduino.
cpp
#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.

  1. Place a marble at the starting point.
  2. Use the joystick to tilt the maze and guide the marble to the goal.
  3. 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.