Skip to content
International Shipping
Wish Lists Cart
0 items

#24 Maze Navigating Robot Project With PicoBricks

01 Nov 2023
#24 Maze Navigating Robot Project With PicoBricks
How about build your own autonomous maze solving robot? In this project, we will witness a car using LDR sensor, motor driver and servo motors to solve the maze by itself. You can find python codes and wiring diagram for beginners in our article.

Coding education is as old as the history of programming languages. Today, different products are used to popularize coding education and make it exciting and fun. The first of these is educational robots. Preparing and programming robots improves children’s engineering and coding skills. Robotics competitions are organized by institutions and organizations to popularize coding education and encourage teachers and students. One of these competitions is the Maze Solver Robot competitions. These robots learn how to solve the maze by wandering around in the maze and returning to the starting point. Then, when they start the labyrinth again, they try to reach their destination in the shortest way possible. Robots use infrared or ultrasonic distance sensors while learning the maze.

Smart robot vacuums used in homes and workplaces also work with logic close to the algorithms of maze-solver robots. Thanks to their algorithms that constantly check and map the obstacles, they try to complete their tasks without crashing into things. Most of the smart vacuums are equipped with LIDAR and infrared sensors that are designed for  high-precision laser measurements and obstacle detection.

In this project, we will make a simple robot that you can use to navigate your own maze.

Maze Robot Details and Algorithm

In this project, we will use the 2WD robot car kit that comes with the set. We will use the HC-SR04 ultrasonic distance sensor so that the robot can detect the walls in front of it and decide its movements. In the maze, the robot will scan the space in front of the car and move forward if it is empty. If there is a wall (obstacle) within 5 cm’s, the car will turn right and measure the distance again. If the new distance on the right is greater than 5 cm, it will continue on its way. If it is less, it will turn left and move forward. By turning right and left, we will guide the vehicle to make progress and exit the maze.


  • 1X PicoBricks
  • 1X HC-SR04 Ultrasonic Sensor
  • 2X DC Motor
  • Jumper Cables
  • Easy Connection Cables

Wiring Diagram

You can code and run Picobricks’ modules without wiring. If you are going to use the modules by separating them from the board, you should make the module connections with grove cables.

Construction Stages of the Project

You can build the robot car by following the steps for the 2WD robot car assembly in the voice-controlled car project.

We will not use the HC05 bluetooth module in this project.

In order to mount the HC-SR04 ultrasonic distance sensor on the robot, you can download the required parts from the link here and print it on the 3D printer and mount it on the vehicle.

After assembling the robot, you can use cardboard boxes to build the maze. You can make walls out of cardboard, or you can use 3D printed walls to connect the walls with hot glue to build the maze.


Microblocks Run Tab

MicroBlocks Codes of Maze Solving Robot

You can access the Microblocks codes of the project by dragging the image to the Microblocks Run tab or click the button.


MicroPython Codes of the PicoBricks


from machine import Pin
from utime import sleep
import utime

# Define libraries
trigger = Pin(15, Pin.OUT)
echo = Pin(14, Pin.IN)
# Define sensor pins
m1 = Pin(21, Pin.OUT)
m2 = Pin(22, Pin.OUT)
# Define dc motor pins

signaloff = 0
signalon = 0

def getDistance():
   while echo.value() == 0:
       signaloff = utime.ticks_us()
   while echo.value() == 1:
       signalon = utime.ticks_us()
   timepassed = signalon - signaloff
   distance = (timepassed * 0.0343) / 2
   return distance

# Calculate distance
measure = 0

while True:
    measure = int(getDistance())
    if measure > 5:
        sleep(1)  # If the distance is higher than 5, the wheels go straight
        measure = int(getDistance())
        if measure < 5:
            sleep(0.5)  # If the distance is less than 5, wait, move in any direction; if the distance is less than 5, move in the opposite direction

Arduino C Codes 

#include <NewPing.h>
#define TRIGGER_PIN  15
#define ECHO_PIN     14
#define MAX_DISTANCE 400
// Define sensor pins

void setup() {
  pinMode(21, OUTPUT);
  pinMode(22, OUTPUT); // Define dc motor pins

void loop() {
  int distance = sonar.ping_cm();
  if(distance < 5){
    int distance = sonar.ping_cm();
    if(distance < 5){
      // If the distance is less than 5, wait, turn right; if the distance is less than 5 again, move in the opposite direction

void Forward(){
  digitalWrite(21, HIGH);
  digitalWrite(22, HIGH); // If the distance is higher than 5, go straight

void Turn_Left(){
  digitalWrite(21, LOW);
  digitalWrite(22, HIGH); // Turn left

void Turn_Right(){
  digitalWrite(21, HIGH);
  digitalWrite(22, LOW);  // Turn right

void Stop(){
  digitalWrite(21, LOW);
  digitalWrite(22, LOW); // Wait


What is the algorithm of the robot in the maze runner?

The algorithm of the robot in the maze runner typically involves a pathfinding technique like the A* (A-star) algorithm. This algorithm efficiently finds the shortest path through the maze by combining aspects of the best-first search and Dijkstra's algorithm, balancing between exploration and the goal's distance.

What are the advantages of maze solving robot?

The advantages of a maze solving robot include enhanced problem-solving skills, efficient navigation in complex environments, the ability to learn and adapt from experiences, potential for search and rescue operations, and the development of advanced algorithms applicable in various fields like robotics, AI, and automation.

What is the a* maze solving algorithm?

The A* maze-solving algorithm is a pathfinding and graph traversal technique used for efficiently finding the shortest path through a maze. It combines features of Dijkstra's algorithm and a heuristic-based search, like Greedy Best-First-Search, to optimize pathfinding by considering both the cost to reach a node and an estimate of the distance to the goal.

Prev Post
Next Post

Thanks for subscribing!

This email has been registered!

Shop the look
Choose Options

Edit Option

Have Questions?

Back In Stock Notification


Product SKUDescription Collection Availability Product Type Other Details

Terms & Conditions

What is Lorem Ipsum? Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
this is just a warning
Shopping Cart
0 items