Skip to content

#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.

Components

  • 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

m1.low()
m2.low()
signaloff = 0
signalon = 0

def getDistance():
   trigger.low()
   utime.sleep_us(2)
   trigger.high()
   utime.sleep_us(5)
   trigger.low()
   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())
    print(measure)
    if measure>5:
        m1.high()
        m2.high()
        sleep(1) #if the distance is higher than 5, the wheels go straight
    else:
        m1.low()
        m2.low()
        sleep(0.5)
        m1.high()
        m2.low()
        sleep(0.5)
        measure=int(getDistance())
        if measure<5:
            m1.low()
        m2.low()
        sleep(0.5)
        m1.low()
        m2.high()
        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

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

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

void loop() {
  
  delay(50);
  int distance=sonar.ping_cm();
  Forward();

  if(distance<5){

    Stop();
    delay(1000);
    Turn_Right();
    delay(1000);
    int distance=sonar.ping_cm();

    if(distance<5){
      Stop();
      delay(1000);
      Turn_Left();
      delay(500);
      // 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
}

FAQ

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

Back In Stock Notification

Compare

Product SKURatingDescription Collection Availability Product Type Other Details
this is just a warning
Login
Shopping Cart
0 items
Same Day Shipping No Extra Costs
Easy Returns Guarantee Return with Ease
Secure Checkout Secure Payment