Skip to main content

Maze Solver

The aim of the project is the modification of a Parallax BoeBot to solve a random maze. With an Arduino Uno and three HC-SR04 ultrasonic sensors the robot should navigate through mazes and should be optimized for the second round with the help of a maze solving algorithm.


Maze Solver Presentation


The code is available on


Defines, pins, variables and library objects were created globally. Initialisation was done in "setup", the routine was done in "loop". In the main routine, functions from the following described parts were called, as well as robustness was added to the system, by double checking the detected junction.


The algorithm is used by any round greater than the first. Junctions, detected in the first round, are saved as a letter to a string. The algorithm includes the LSRB transfer table (adapted from a research paper). All dead ends detected in the first round, will be replaced by a letter from the table. In the 2 nd , the robot detects junctions and compares it to the letters of the shortened path. Junctions that lead to a dead end can be skipped.


3 LEDs shows what junction was detected.


To avoid bumping, the robot reacts by moving away when a wall closer than 3cm is detected, and PID Controller is implemented by using the PID vl.h library. Setpoints are calculated by using the two distances measured left and right. The controller values are mapped to the PWM servo signals. The code is not adjusted to a fixed maze, due to controllers and measured distances, the robot can act in mazes where walls are away from around 4cm to 35cm and it doesn't need 90 degree corners.

Letter Evaluation

By detecting walls, the adequate letter to a junction is saved to a string.


The Servo.h library is used.


By pressing the button, a new round is started with the help of an interrupt.


The measured distances (of the last time where left AND right wall was detected) are used to adjust servo values. If the distance on the side which the robot wants to turn is smaller, the turn is more likely a pivot turn, a higher distance will cause a smoother turn.


NewPing.h library was used to get distances. Walls are analysed for bumping, junctions, controllers and end of the maze.