AhmedAzouz
Published © LGPL

Arduino Marble Maze Labyrinth

Introducing a super easy automated control labyrinth marble maze.

BeginnerFull instructions provided1 hour59,868
Arduino Marble Maze Labyrinth

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×2
Breadboard (generic)
Breadboard (generic)
×1
Modulo Joystick
Modulo Joystick
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)
Sharp-Blade Knife

Story

Read more

Custom parts and enclosures

cardboard maze design files

Schematics

Main schematic

Code

contol maze with joystick

Arduino
#include <Servo.h>
Servo myServoX; // define servo motor for X-axis 
Servo myServoY; // define servo motor for Y-axis 
int ServoXPin = 8; // define  X-axis pin
int ServoYPin = 9; // define  Y-axis pin
int ServoXHomePos =90; // set home position for servos
int ServoYHomePos =90; 
int ServoXPos =103;
int ServoYPos =135; 
int XAxlePin = A0; // define  X-axis pin control for joystick A0
int YAxlePin = A1; // define  Y-axis pin control for joystick A1
int XAxleValue = 0; // set start up value for joystick
int YAxleValue = 0;
int Direction = 0;
int range = 12; // output range of X or Y movement
int center = range/2; // resting position value
int threshold = range/4; // resting threshold
void setup()
{
myServoX.attach(ServoXPin); // attaching servo X 
myServoY.attach(ServoYPin); // attaching servo Y
ServoXPos = ServoXHomePos;  // update ServoXPos with home position as startup
ServoYPos = ServoYHomePos;  // update ServoYPos with home position as startup
myServoX.write(ServoXPos);
myServoY.write(ServoYPos);
Serial.begin(9600);
}
void loop()
{
XAxleValue = readAxis(XAxlePin);
YAxleValue = readAxis(YAxlePin);

Serial.print(XAxleValue,DEC);
Serial.print(" - ");
Serial.println(YAxleValue,DEC);

// check the values of joystick and move the servos smothly with delay of 100 millisecond
if (XAxleValue>0) { ServoXPos++; myServoX.write(ServoXPos); delay(100*(7-XAxleValue)); }
if (XAxleValue<0) { ServoXPos--; myServoX.write(ServoXPos); delay(100*(7+XAxleValue)); }
if (YAxleValue>0) { ServoYPos++; myServoY.write(ServoYPos); delay(100*(7-YAxleValue)); }
if (YAxleValue<0) { ServoYPos--; myServoY.write(ServoYPos); delay(100*(7+YAxleValue)); }


if (ServoXPos>ServoXHomePos+20) { ServoXPos=ServoXHomePos+20; }
if (ServoXPos<ServoXHomePos-20) { ServoXPos= ServoXHomePos-20; }
if (ServoYPos>ServoYHomePos+20) { ServoYPos=ServoYHomePos+20; }
if (ServoYPos<ServoYHomePos-20) { ServoYPos= ServoYHomePos-20; }
delay(10);
}
int readAxis(int thisAxis) {
// read the analog input:
int reading = analogRead(thisAxis);
// map the reading from the analog input range to the output range:
reading = map(reading, 0, 1023, 0, range);
// if the output reading is outside from the
// rest position threshold, use it:
int distance = reading - center;
if (abs(distance) < threshold) {
distance = 0;
}
// return the distance for this axis:
return distance;
}

Credits

AhmedAzouz

AhmedAzouz

10 projects • 155 followers
High qualified software engineer, Creativity and Technology have always been a big part of my life.

Comments