SlideShare a Scribd company logo
4
Most read
5
Most read
9
Most read
INTRODUCTION
A maze is a complicated system of paths from entrance to exit. Maze
solving problem involves determining the path of a mobile robot from its
initial position to its destination while
travelling through environment consisting of obstacles. In addition, the robot
must follow the best possible path among various possible paths present in the
maze.
Maze solving - a seemingly minor challenge for the analytical minds of
humans – has generated enough curiosity and challenges for A.I. experts to
make their machines (robots) solve any given maze.
Applications of such autonomous vehicles range from simple tasks like
robots employed in industries to carry goods through factories, offices,
buildings and other workplaces to dangerous or difficult to reach areas like
bomb sniffing, finding humans in wreckages etc.
Some maze solving methods are designed to be used inside the maze
with no prior knowledge of the maze whereas others are designed to be used
by a computer program that can see whole maze at once. We used the former
one. Our mazes are simply – connected i.e., without any closed loops.
Autonomous maze solving robot that we have built first goes from start to
end searching in the maze using wall follower algorithm (left hand rule) and
then processes out the shortest possible path by eliminating dead ends and
takes that path next time . It does all of that without any human assistance.
OBJECTIVE :
1. Design and build the robot using ultrasonic sensors.
2. Understand and implement wall-follower algorithm.
3. Construct Arduino based program to solve the maze.
COMPONENTS REQUIRED
•Arduino UNO board
•Motor driver
•2 DC motors
•Bread board
•3 ultrasonic sensors
•2 9V battery
•Chassis
•2 tires and ball caster
WALL FOLLOWING ALGORITHM
The wall follower, one of the best known rules for traversing mazes, is
also known as either left-hand rule or the right-hand rule. Whenever the robot
reaches a junction, it will sense for the opening walls and select its direction
giving the priority to the selected wall. Here, the selected wall is left! The
priority in left hand wall is in the following order: left, straight and right and if
all the sides are closed, then U-turn.
The robot uses three ultrasonic sensors attached to it, to determine the
distance of the walls in three directions: Front, Left and Right. If the distance
of the wall from the bot is less than the set threshold value in a particular
direction, then the robot assigns it as closed and similarly if it is greater than
the set threshold value, then it assigns it as open. It also uses the left and right
wall distances to align itself parallel to the wall, while moving forward.
START
Reached the end
Left Wall
True
Front Wall
Yes
Right Wall
Yes
Yes
Right turn No
Straight No
U-Turn
FLOW CHART
Left turn No
Now update the array index
and store it in the array!
Call Reduce function to
shorten the path storing
array for any U-Turns, etc.
Now, set the index of the array,
storing the shortened path to the
initial value and continue
traversing the maze from
beginning.
Now, at each node, before
making a turn, verify it with the
final array and adhere to it get to
the end in a shorter way!
END.
False
As the bot traverses the maze, its path is stored in an array and is
simultaneously reduced by calling the function ‘reduce’,
if it can be shortened. For example, if we consider the
following part of the maze: at the node where it moved
forward over right, this turn along with its two previous
turns (U-turn and a left turn respectively) can be
shortened to ‘R’! That is, ‘LUF = R’ and now the array
is dynamically modified and the modified path is updated
into it. After reaching the end, the bot again starts from
the beginning and this time, at each node it checks with
the shortened array and follows it to go to the end in a
much shorter path!
In this way, while traversing the maze the bot remembers as well as
shortens and adheres it to reach the end in a much shorter path!
As it is said, the wall follower algorithm is amateur programmers’
favorite! This method works perfectly well for those mazes whose start and
end is wall connected or in other words for those mazes which are simply
connected, but gets stuck in loops. There are many algorithms which have
successfully overcome this problem of getting stuck in loops, but most of them
have one condition, that the maze be known priorly. Examples of some of the
algorithms are: Flood Fill Algorithm which is extensively used in
‘Micromouse Competitions’, the Pledge algorithm, the Tremaux’s algorithm,
etc.
CODE
#define fthold 12 // Threshold value in front direction
#define rthold 20 // Threshold value in right direction
#define lthold 20 // Threshold vlaue in left direction
const int t = 1050; // Time alotted for taking 90 degrees for 9V!
int tfr =2750; // Initial Time for which it moves forward when it chooses
forward over right.
int timefr; // Dynamically set time..for which it moves forward,when it
chooses forward over right.
int tlbef=440; // Time for which it moves forward before taking left turn.
int tlaf = 1150; // Time for which it moves forward after taking left turn.
int nf =0; // Number of times it chooses straight over right.
int nlr=0; // Number of times it takes left turn.
bool found=false; // If its true, it indicates that the bot has reached the
end!
int dir[100]; // Array for storing the path of the bot.
int i=-1; // For the indices of the dir array.
int j=0; // Implies the number of intersections bot passed through.
// Front US sensor.
const int trigPinf = 2;
const int echoPinf = 6;
// Right US sensor.
const int trigPinr = 8;
const int echoPinr = 5;
// Left US sensor.
const int trigPinl = 3;
const int echoPinl = 9;
//Booleans for recognising the walls. True if resp sensor distance is less than
the resp threshold vlaue.
bool fsensor; // For the front US sensor.
bool rsensor; // For the right US sensor.
bool lsensor; // For the left US sensor.
// Sorts and returns the median value of a five element array.
float middleval(float arr[])
{
for(int p=0;p<4;p++)
{
for(int q=0;q<4;q++)
{
The below code contains code both for Maze
Solving and Shortest path Simplification.
if(arr[q]>arr[q+1])
{
int temp = arr[q];
arr[q] = arr[q+1];
arr[q+1] = temp;
}
}
}
return arr[2]; // Median value.
}
// Moves the bot in the forward direction
void gofront()
{
// Moves forward adjusting its path
float ldist1 = leftdist();
float lconst = ldist1;
while(ldist1<=5) // Should turn a little to its right
{
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
delay(t/65);
ldist1 = leftdist();
if(abs(lconst - ldist1)>=0.8||(ldist1>=3.6)){break;}
}
float rdist1 = rightdist();
float rconst = rdist1;
while(rdist1<=5.4) // Should turn a little to its left
{
digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
delay(t/65);
rdist1 = rightdist();
if(abs(rconst - rdist1)>=0.9){break;}
}
if(leftdist()>=7.2) // Will move little to its left if its too far from
the left wall
{
digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
delay(t/30);
}
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
}
// Returns the dist of wall in front of it
float frontdist()
{
float gapf;float ticktockf;
digitalWrite(trigPinf,LOW);
delayMicroseconds(2);
digitalWrite(trigPinf,HIGH);
delayMicroseconds(10);
digitalWrite(trigPinf,LOW);
ticktockf = pulseIn(echoPinf,HIGH); // in one cm there are 29 microseconds.
gapf = ticktockf*0.0344/2;
return gapf;
}
// Returns the distance the wall to its right side
float rightdist()
{
float gapr;float ticktockr;
digitalWrite(trigPinr,LOW);
delayMicroseconds(2);
digitalWrite(trigPinr,HIGH);
delayMicroseconds(10);
digitalWrite(trigPinr,LOW);
ticktockr = pulseIn(echoPinr,HIGH);
gapr = ticktockr*0.0344/2;
return gapr;
}
// Returns the distance of the wall to its left side
float leftdist()
{
float gapl;float ticktockl;
digitalWrite(trigPinl,LOW);
delayMicroseconds(2);
digitalWrite(trigPinl,HIGH);
delayMicroseconds(10);
digitalWrite(trigPinl,LOW);
ticktockl = pulseIn(echoPinl,HIGH);
gapl = ticktockl*0.0334/2;
return gapl;
}
// Reduces the path if it can be shortened and dynamically modifies the path
storing array.
void reduce(int dir[], int &pt)
{
int i=pt;
if(i>=2)
{
//RUL = U..
if((dir[i-1]==3)&&(dir[i-2]==2)&&(dir[i]==1))
{
dir[i-2]=3;
pt = pt -2;
}
//LUL = F..
else if((dir[i-1]==3)&&(dir[i-2]==1)&&(dir[i]==1))
{
dir[i-2]=0;
pt = pt -2;
}
//LUR = U..
else if((dir[i-1]==3)&&(dir[i-2]==1)&&(dir[i]==2))
{
dir[i-2]=3;
pt = pt -2;
}
//FUF = U..
else if((dir[i-1]==3)&&(dir[i-2]==0)&&(dir[i]==0))
{
dir[i-2]=3;
pt = pt -2;
}
//FUL = R..
else if((dir[i-1]==3)&&(dir[i-2]==0)&&(dir[i]==1))
{
dir[i-2]=2;
pt = pt -2;
}
//LUF = R..
else if((dir[i-1]==3)&&(dir[i-2]==1)&&(dir[i]==0))
{
dir[i-2]=2;
pt = pt -2;
}
return;
}
}
// Stops the bot
void stopit()
{
digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
}
// When it has to move forward according to the shortest path.(At some
intersection)
void frontturn()
{
for(int n=1;n<=8;n++)
{gofront();delay((timefr)/8);}
digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
delay(1000);
}
// When it has to take a right turn according to the shortest path.
void rightturn()
{ stopit();delay(1000);
float prevfdist = frontdist();
//while( abs(frontdist()-prevfdist)<=(prevfdist/2)-1)
for(int n=1;n<=5;n++)
{gofront();delay(260);}
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
delay(t);
// gofront();delay(2400);
float prevfrdist = frontdist();
while( abs(frontdist()-prevfrdist)<=18)
/* for(int n=1;n<=10;n++)*/
{gofront();delay(300);}
digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
delay(1000);
}
void setup() // put your setup code here, to run once:
{
// US pins setup..
pinMode (trigPinf,OUTPUT);
pinMode (echoPinf,INPUT);
pinMode (trigPinr,OUTPUT);
pinMode (echoPinr,INPUT);
pinMode (trigPinl,OUTPUT);
pinMode (echoPinl,INPUT);
pinMode( 4,INPUT); // FOR THE IR SENSOR...
// Motor pins.
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
Serial.begin(9600); //staartingg serial communication...9600 bits per second.
// dir[0] = 0; // initial direction..?
}
void loop() // put your main code here, to run repeatedly
{
if(nlr==7)
{
found=true; // Reached the end.
for(int i=0;i<=2;i++){Serial.print(dir[i]);}
i=-1;j=0; nlr=0; // Back to start again..
// Stops the bot for 30 seconds after reaching the end.
digitalWrite(10,LOW);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,LOW);
delay(30000);
}
float fdist; float rdist; float ldist; // front, right, and left
distances.
float fduration;float rduration;float lduration; // front, right, and left
travel time in echoPin.
float fdur[5]; float rdur[5]; float ldur[5]; // Arrays which store the
values of five durations... We will take only the median value(afer sorting)
with error bearing capacity of 40%.
float ldista[5];
// For the front US sensor..
for(int i=0;i<=4;i++)
{
digitalWrite(trigPinf,LOW); // Clearing the trigPin.
delayMicroseconds(5);
digitalWrite(trigPinf,HIGH); // Setting the trigPin HIGH for 10
microseconds..sends some 8cycle sonics.
delayMicroseconds(10);
digitalWrite(trigPinf,LOW);
fdur[i] = pulseIn(echoPinf,HIGH); // Returns the time for which the wave
travelled.
}
fduration = middleval(fdur);
fdist = fduration*0.0344/2; // Distance of the wall in the forward
direction
/*Serial.print("frontdistance: ");
Serial.println(fdist);*/
// for the right US sensor...
for(int i=0;i<=4;i++)
{
digitalWrite(trigPinr,LOW);
delayMicroseconds(5);
digitalWrite(trigPinr,HIGH);
delayMicroseconds(10);
digitalWrite(trigPinr,LOW);
rdur[i] = pulseIn(echoPinr,HIGH);
}
rduration = middleval(rdur);
rdist = rduration*0.0344/2; // Distance of the wall to its right.
/* Serial.print("rightdistance: ");
Serial.println(rdist);*/
// for the left US sensor....
for(int i=0;i<=4;i++)
{
digitalWrite(trigPinl,LOW);
delayMicroseconds(5);
digitalWrite(trigPinl,HIGH);
delayMicroseconds(10);
digitalWrite(trigPinl,LOW);
ldur[i] = pulseIn(echoPinl,HIGH);
}
lduration = middleval(ldur);
ldist = lduration*0.0344/2; // Distance of the wall to its left side
/* Serial.print("leftdistance: ");
Serial.println(ldist);*/
if((fdist>=125)||(rdist>=150)||(ldist>=400)) {return;} // Cancelling out any
error values...goes back to void loop().
fsensor = false;rsensor = false;lsensor = false; // Setting up the
booleans.
if(rdist<=rthold) rsensor = true;
if(ldist<=lthold) lsensor = true;
if(fdist<=fthold) fsensor = true;
// Left
Wall Following Algorithm!
// If left is closed-
if((lsensor==true))
{ // for a U-turn..
if((rsensor==true)&&(fsensor==true))
{ j=j+1;
i=i+1;
dir[i] = 3;
reduce(dir,i);
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
delay(2*t);
}
// If Front is open..
else if(fsensor==false)
{
if((rsensor==false)&&(frontdist()>=40)) // If both front and right are
open..
{
i = i+1;
j=j+1;
if((found==true)&(dir[i]!=0)) // After reaching the end ... checks the s
{
rightturn();return;
}
else
{
if(found==false){
dir[i] = 0; // moving forward over right...
reduce(dir,i);
}
/*Serial.print("for the jth turn ..");Serial.print(" =");Serial.print(j);
Serial.print(" the i value is ");Serial.print(i);Serial.print("and the dir
is ..");Serial.println(dir[i]);*/
timefr = tfr + 65*nf;
nf=nf+1;
stopit();delay(1000);
for(int g=1;g<=10;g++){gofront();delay(timefr/10);}
stopit();delay(1000);
}
}
else {gofront();delay(300);} // Else moving forward .. only front is open.
}
//for a right turn..
else
{
i = i+1;
j=j+1;
dir[i] = 2;
reduce(dir,i);
float prevfdist = frontdist();
while( abs(frontdist()-prevfdist)<=(prevfdist/2)-2)
{gofront();delay(300);if(frontdist()<=4.5){break;}}
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
digitalWrite(12,LOW);
digitalWrite(13,HIGH);
delay(t);
float prevfrdist = frontdist();
while( abs(frontdist()-
prevfrdist)<=15.2){gofront();delay(300);if(frontdist()<=4.5){break;}}
}
}
else
{
//for a left turn..
i=i+1;
j=j+1;
if((found==true)&&(dir[i]!=1)){
if((dir[i]==2)&&(rightdist>=10)){rightturn();return;}
else if((dir[i]== 0)&&(fsensor==false))
{frontturn();return;}
}
else{
dir[i]=1; // Left turn..
nlr=nlr+1;
reduce(dir,i); //calling reduce function to shorten the path
dynamically..if path is not yet completed
{gofront(); delay(tlbef);}
digitalWrite(10,LOW); // takes a left turn..
digitalWrite(11,LOW);
digitalWrite(12,HIGH);
digitalWrite(13,LOW);
delay(2*t);
for(int n=1;n<=8;n++) { gofront();delay(tlaf/8);}
stopit();delay(1000);
}
}
delay(320);
}

More Related Content

What's hot (20)

PPTX
Obstacle Avoidance Robot Summer training Presentation
Wasi Abbas
 
PPT
Robotics and machine vision system
Gowsick Subramaniam
 
PPTX
Line follower robot
Priya Hada
 
PPT
Maze solver robot presentation
Naveed Ahmed
 
PPTX
Line Following Robot using Arduino UNO
Viswanadh Ivaturi
 
PPTX
Autonomous maze solving robot (1/2)
Musfiqur Rahman
 
PPTX
Reverse car-parking
Salehin Rahman Khan
 
PPTX
Line Following Robot
Self-employed
 
PPTX
OBSTACLE AVOIDING CAR
Shubham Thakur
 
PPTX
Automatic Railway Gate Control System with Arduino
Misbah Ahmad Chowdhury Fahim
 
PPTX
Line follower robot
Rohit Dadoriya
 
PPTX
Manish1 washing machine control
manish rishi
 
PPTX
Programmable Logic Controller | Ladder Logic diagrams| Block diagram | I/O Mo...
Waqas Afzal
 
PPT
Smart Traffic Light Controller
Himanshi_Sharma
 
PDF
Automatic railway gate control
Mohamed Magdy
 
PPT
Robotics: Introduction to Kinematics
Damian T. Gordon
 
PDF
Sensors and microcontroller interfacing
mohamed albanna
 
PDF
Architecture of 8051 Microcontroller.pdf
HezalLopes1
 
PPTX
Traffic light controller
Rkrishna Mishra
 
Obstacle Avoidance Robot Summer training Presentation
Wasi Abbas
 
Robotics and machine vision system
Gowsick Subramaniam
 
Line follower robot
Priya Hada
 
Maze solver robot presentation
Naveed Ahmed
 
Line Following Robot using Arduino UNO
Viswanadh Ivaturi
 
Autonomous maze solving robot (1/2)
Musfiqur Rahman
 
Reverse car-parking
Salehin Rahman Khan
 
Line Following Robot
Self-employed
 
OBSTACLE AVOIDING CAR
Shubham Thakur
 
Automatic Railway Gate Control System with Arduino
Misbah Ahmad Chowdhury Fahim
 
Line follower robot
Rohit Dadoriya
 
Manish1 washing machine control
manish rishi
 
Programmable Logic Controller | Ladder Logic diagrams| Block diagram | I/O Mo...
Waqas Afzal
 
Smart Traffic Light Controller
Himanshi_Sharma
 
Automatic railway gate control
Mohamed Magdy
 
Robotics: Introduction to Kinematics
Damian T. Gordon
 
Sensors and microcontroller interfacing
mohamed albanna
 
Architecture of 8051 Microcontroller.pdf
HezalLopes1
 
Traffic light controller
Rkrishna Mishra
 

Similar to Maze Solver Robot using Arduino (20)

PDF
Line maze solver
Sushil Dahal
 
PPTX
MAZE RUNNER and the best of u to do the needful
VikasA19
 
PPT
Final ppt ens492
Ali Ülkü
 
PPT
Final ppt ens492
Ali Ülkü
 
PDF
How to Build a Maze Solving Robot Using Arduino
CircuitDigest
 
PDF
How to Build a Maze Solving Robot Using Arduino
CircuitDigest
 
PDF
IRJET - Analysis of A-Star Bot
IRJET Journal
 
PPTX
Maze Solver Robot Poster
Naveed Ahmed
 
PPTX
Line maze solver robot
saiharsha41
 
PPT
2015_1009_Line following - Braitenberg, robot examples.ppt
r_sadoun
 
PDF
Grid Based Autonomous Navigator
Sayeed Mohammed
 
DOCX
Path Following Robot
Chamila Wijayarathna
 
PPTX
Maze follower robot
VikasKumar1792
 
PDF
Autonomous navigation robot
IRJET Journal
 
PDF
Goal The goal is to build a Maze-runner special edition of your .pdf
aucmistry
 
DOCX
Final Lab, Arduino Robot Challenge
James Smith
 
PDF
IRJET- Shortest Path Follower Robot
IRJET Journal
 
PPTX
HandyBug Robot
Reyna M
 
PDF
Wall follower autonomous robot development applying fuzzy incremental controller
rajabco
 
PDF
Wall follower autonomous robot development applying fuzzy incremental controller
Yousef Moh. Abueejela
 
Line maze solver
Sushil Dahal
 
MAZE RUNNER and the best of u to do the needful
VikasA19
 
Final ppt ens492
Ali Ülkü
 
Final ppt ens492
Ali Ülkü
 
How to Build a Maze Solving Robot Using Arduino
CircuitDigest
 
How to Build a Maze Solving Robot Using Arduino
CircuitDigest
 
IRJET - Analysis of A-Star Bot
IRJET Journal
 
Maze Solver Robot Poster
Naveed Ahmed
 
Line maze solver robot
saiharsha41
 
2015_1009_Line following - Braitenberg, robot examples.ppt
r_sadoun
 
Grid Based Autonomous Navigator
Sayeed Mohammed
 
Path Following Robot
Chamila Wijayarathna
 
Maze follower robot
VikasKumar1792
 
Autonomous navigation robot
IRJET Journal
 
Goal The goal is to build a Maze-runner special edition of your .pdf
aucmistry
 
Final Lab, Arduino Robot Challenge
James Smith
 
IRJET- Shortest Path Follower Robot
IRJET Journal
 
HandyBug Robot
Reyna M
 
Wall follower autonomous robot development applying fuzzy incremental controller
rajabco
 
Wall follower autonomous robot development applying fuzzy incremental controller
Yousef Moh. Abueejela
 
Ad

Recently uploaded (20)

PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
July Patch Tuesday
Ivanti
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Ad

Maze Solver Robot using Arduino

  • 1. INTRODUCTION A maze is a complicated system of paths from entrance to exit. Maze solving problem involves determining the path of a mobile robot from its initial position to its destination while travelling through environment consisting of obstacles. In addition, the robot must follow the best possible path among various possible paths present in the maze. Maze solving - a seemingly minor challenge for the analytical minds of humans – has generated enough curiosity and challenges for A.I. experts to make their machines (robots) solve any given maze. Applications of such autonomous vehicles range from simple tasks like robots employed in industries to carry goods through factories, offices, buildings and other workplaces to dangerous or difficult to reach areas like bomb sniffing, finding humans in wreckages etc. Some maze solving methods are designed to be used inside the maze with no prior knowledge of the maze whereas others are designed to be used by a computer program that can see whole maze at once. We used the former one. Our mazes are simply – connected i.e., without any closed loops. Autonomous maze solving robot that we have built first goes from start to end searching in the maze using wall follower algorithm (left hand rule) and then processes out the shortest possible path by eliminating dead ends and takes that path next time . It does all of that without any human assistance. OBJECTIVE : 1. Design and build the robot using ultrasonic sensors. 2. Understand and implement wall-follower algorithm. 3. Construct Arduino based program to solve the maze. COMPONENTS REQUIRED •Arduino UNO board •Motor driver •2 DC motors •Bread board •3 ultrasonic sensors •2 9V battery •Chassis •2 tires and ball caster
  • 2. WALL FOLLOWING ALGORITHM The wall follower, one of the best known rules for traversing mazes, is also known as either left-hand rule or the right-hand rule. Whenever the robot reaches a junction, it will sense for the opening walls and select its direction giving the priority to the selected wall. Here, the selected wall is left! The priority in left hand wall is in the following order: left, straight and right and if all the sides are closed, then U-turn. The robot uses three ultrasonic sensors attached to it, to determine the distance of the walls in three directions: Front, Left and Right. If the distance of the wall from the bot is less than the set threshold value in a particular direction, then the robot assigns it as closed and similarly if it is greater than the set threshold value, then it assigns it as open. It also uses the left and right wall distances to align itself parallel to the wall, while moving forward. START Reached the end Left Wall True Front Wall Yes Right Wall Yes Yes Right turn No Straight No U-Turn FLOW CHART Left turn No Now update the array index and store it in the array! Call Reduce function to shorten the path storing array for any U-Turns, etc. Now, set the index of the array, storing the shortened path to the initial value and continue traversing the maze from beginning. Now, at each node, before making a turn, verify it with the final array and adhere to it get to the end in a shorter way! END. False
  • 3. As the bot traverses the maze, its path is stored in an array and is simultaneously reduced by calling the function ‘reduce’, if it can be shortened. For example, if we consider the following part of the maze: at the node where it moved forward over right, this turn along with its two previous turns (U-turn and a left turn respectively) can be shortened to ‘R’! That is, ‘LUF = R’ and now the array is dynamically modified and the modified path is updated into it. After reaching the end, the bot again starts from the beginning and this time, at each node it checks with the shortened array and follows it to go to the end in a much shorter path! In this way, while traversing the maze the bot remembers as well as shortens and adheres it to reach the end in a much shorter path! As it is said, the wall follower algorithm is amateur programmers’ favorite! This method works perfectly well for those mazes whose start and end is wall connected or in other words for those mazes which are simply connected, but gets stuck in loops. There are many algorithms which have successfully overcome this problem of getting stuck in loops, but most of them have one condition, that the maze be known priorly. Examples of some of the algorithms are: Flood Fill Algorithm which is extensively used in ‘Micromouse Competitions’, the Pledge algorithm, the Tremaux’s algorithm, etc.
  • 4. CODE #define fthold 12 // Threshold value in front direction #define rthold 20 // Threshold value in right direction #define lthold 20 // Threshold vlaue in left direction const int t = 1050; // Time alotted for taking 90 degrees for 9V! int tfr =2750; // Initial Time for which it moves forward when it chooses forward over right. int timefr; // Dynamically set time..for which it moves forward,when it chooses forward over right. int tlbef=440; // Time for which it moves forward before taking left turn. int tlaf = 1150; // Time for which it moves forward after taking left turn. int nf =0; // Number of times it chooses straight over right. int nlr=0; // Number of times it takes left turn. bool found=false; // If its true, it indicates that the bot has reached the end! int dir[100]; // Array for storing the path of the bot. int i=-1; // For the indices of the dir array. int j=0; // Implies the number of intersections bot passed through. // Front US sensor. const int trigPinf = 2; const int echoPinf = 6; // Right US sensor. const int trigPinr = 8; const int echoPinr = 5; // Left US sensor. const int trigPinl = 3; const int echoPinl = 9; //Booleans for recognising the walls. True if resp sensor distance is less than the resp threshold vlaue. bool fsensor; // For the front US sensor. bool rsensor; // For the right US sensor. bool lsensor; // For the left US sensor. // Sorts and returns the median value of a five element array. float middleval(float arr[]) { for(int p=0;p<4;p++) { for(int q=0;q<4;q++) { The below code contains code both for Maze Solving and Shortest path Simplification.
  • 5. if(arr[q]>arr[q+1]) { int temp = arr[q]; arr[q] = arr[q+1]; arr[q+1] = temp; } } } return arr[2]; // Median value. } // Moves the bot in the forward direction void gofront() { // Moves forward adjusting its path float ldist1 = leftdist(); float lconst = ldist1; while(ldist1<=5) // Should turn a little to its right { digitalWrite(10,HIGH); digitalWrite(11,LOW); digitalWrite(12,LOW); digitalWrite(13,LOW); delay(t/65); ldist1 = leftdist(); if(abs(lconst - ldist1)>=0.8||(ldist1>=3.6)){break;} } float rdist1 = rightdist(); float rconst = rdist1; while(rdist1<=5.4) // Should turn a little to its left { digitalWrite(10,LOW); digitalWrite(11,LOW); digitalWrite(12,HIGH); digitalWrite(13,LOW); delay(t/65); rdist1 = rightdist(); if(abs(rconst - rdist1)>=0.9){break;} } if(leftdist()>=7.2) // Will move little to its left if its too far from the left wall { digitalWrite(10,LOW); digitalWrite(11,LOW); digitalWrite(12,HIGH); digitalWrite(13,LOW);
  • 6. delay(t/30); } digitalWrite(10,HIGH); digitalWrite(11,LOW); digitalWrite(12,HIGH); digitalWrite(13,LOW); } // Returns the dist of wall in front of it float frontdist() { float gapf;float ticktockf; digitalWrite(trigPinf,LOW); delayMicroseconds(2); digitalWrite(trigPinf,HIGH); delayMicroseconds(10); digitalWrite(trigPinf,LOW); ticktockf = pulseIn(echoPinf,HIGH); // in one cm there are 29 microseconds. gapf = ticktockf*0.0344/2; return gapf; } // Returns the distance the wall to its right side float rightdist() { float gapr;float ticktockr; digitalWrite(trigPinr,LOW); delayMicroseconds(2); digitalWrite(trigPinr,HIGH); delayMicroseconds(10); digitalWrite(trigPinr,LOW); ticktockr = pulseIn(echoPinr,HIGH); gapr = ticktockr*0.0344/2; return gapr; } // Returns the distance of the wall to its left side float leftdist() { float gapl;float ticktockl; digitalWrite(trigPinl,LOW); delayMicroseconds(2); digitalWrite(trigPinl,HIGH); delayMicroseconds(10); digitalWrite(trigPinl,LOW); ticktockl = pulseIn(echoPinl,HIGH);
  • 7. gapl = ticktockl*0.0334/2; return gapl; } // Reduces the path if it can be shortened and dynamically modifies the path storing array. void reduce(int dir[], int &pt) { int i=pt; if(i>=2) { //RUL = U.. if((dir[i-1]==3)&&(dir[i-2]==2)&&(dir[i]==1)) { dir[i-2]=3; pt = pt -2; } //LUL = F.. else if((dir[i-1]==3)&&(dir[i-2]==1)&&(dir[i]==1)) { dir[i-2]=0; pt = pt -2; } //LUR = U.. else if((dir[i-1]==3)&&(dir[i-2]==1)&&(dir[i]==2)) { dir[i-2]=3; pt = pt -2; } //FUF = U.. else if((dir[i-1]==3)&&(dir[i-2]==0)&&(dir[i]==0)) { dir[i-2]=3; pt = pt -2; } //FUL = R.. else if((dir[i-1]==3)&&(dir[i-2]==0)&&(dir[i]==1)) { dir[i-2]=2; pt = pt -2; } //LUF = R.. else if((dir[i-1]==3)&&(dir[i-2]==1)&&(dir[i]==0)) { dir[i-2]=2; pt = pt -2; } return; } } // Stops the bot void stopit() {
  • 8. digitalWrite(10,LOW); digitalWrite(11,LOW); digitalWrite(12,LOW); digitalWrite(13,LOW); } // When it has to move forward according to the shortest path.(At some intersection) void frontturn() { for(int n=1;n<=8;n++) {gofront();delay((timefr)/8);} digitalWrite(10,LOW); digitalWrite(11,LOW); digitalWrite(12,LOW); digitalWrite(13,LOW); delay(1000); } // When it has to take a right turn according to the shortest path. void rightturn() { stopit();delay(1000); float prevfdist = frontdist(); //while( abs(frontdist()-prevfdist)<=(prevfdist/2)-1) for(int n=1;n<=5;n++) {gofront();delay(260);} digitalWrite(10,HIGH); digitalWrite(11,LOW); digitalWrite(12,LOW); digitalWrite(13,HIGH); delay(t); // gofront();delay(2400); float prevfrdist = frontdist(); while( abs(frontdist()-prevfrdist)<=18) /* for(int n=1;n<=10;n++)*/ {gofront();delay(300);} digitalWrite(10,LOW); digitalWrite(11,LOW); digitalWrite(12,LOW); digitalWrite(13,LOW); delay(1000); } void setup() // put your setup code here, to run once: {
  • 9. // US pins setup.. pinMode (trigPinf,OUTPUT); pinMode (echoPinf,INPUT); pinMode (trigPinr,OUTPUT); pinMode (echoPinr,INPUT); pinMode (trigPinl,OUTPUT); pinMode (echoPinl,INPUT); pinMode( 4,INPUT); // FOR THE IR SENSOR... // Motor pins. pinMode(10,OUTPUT); pinMode(11,OUTPUT); pinMode(12,OUTPUT); pinMode(13,OUTPUT); Serial.begin(9600); //staartingg serial communication...9600 bits per second. // dir[0] = 0; // initial direction..? } void loop() // put your main code here, to run repeatedly { if(nlr==7) { found=true; // Reached the end. for(int i=0;i<=2;i++){Serial.print(dir[i]);} i=-1;j=0; nlr=0; // Back to start again.. // Stops the bot for 30 seconds after reaching the end. digitalWrite(10,LOW); digitalWrite(11,LOW); digitalWrite(12,LOW); digitalWrite(13,LOW); delay(30000); } float fdist; float rdist; float ldist; // front, right, and left distances. float fduration;float rduration;float lduration; // front, right, and left travel time in echoPin. float fdur[5]; float rdur[5]; float ldur[5]; // Arrays which store the values of five durations... We will take only the median value(afer sorting) with error bearing capacity of 40%. float ldista[5]; // For the front US sensor.. for(int i=0;i<=4;i++) { digitalWrite(trigPinf,LOW); // Clearing the trigPin. delayMicroseconds(5); digitalWrite(trigPinf,HIGH); // Setting the trigPin HIGH for 10 microseconds..sends some 8cycle sonics.
  • 10. delayMicroseconds(10); digitalWrite(trigPinf,LOW); fdur[i] = pulseIn(echoPinf,HIGH); // Returns the time for which the wave travelled. } fduration = middleval(fdur); fdist = fduration*0.0344/2; // Distance of the wall in the forward direction /*Serial.print("frontdistance: "); Serial.println(fdist);*/ // for the right US sensor... for(int i=0;i<=4;i++) { digitalWrite(trigPinr,LOW); delayMicroseconds(5); digitalWrite(trigPinr,HIGH); delayMicroseconds(10); digitalWrite(trigPinr,LOW); rdur[i] = pulseIn(echoPinr,HIGH); } rduration = middleval(rdur); rdist = rduration*0.0344/2; // Distance of the wall to its right. /* Serial.print("rightdistance: "); Serial.println(rdist);*/ // for the left US sensor.... for(int i=0;i<=4;i++) { digitalWrite(trigPinl,LOW); delayMicroseconds(5); digitalWrite(trigPinl,HIGH); delayMicroseconds(10); digitalWrite(trigPinl,LOW); ldur[i] = pulseIn(echoPinl,HIGH); } lduration = middleval(ldur); ldist = lduration*0.0344/2; // Distance of the wall to its left side /* Serial.print("leftdistance: "); Serial.println(ldist);*/ if((fdist>=125)||(rdist>=150)||(ldist>=400)) {return;} // Cancelling out any error values...goes back to void loop().
  • 11. fsensor = false;rsensor = false;lsensor = false; // Setting up the booleans. if(rdist<=rthold) rsensor = true; if(ldist<=lthold) lsensor = true; if(fdist<=fthold) fsensor = true; // Left Wall Following Algorithm! // If left is closed- if((lsensor==true)) { // for a U-turn.. if((rsensor==true)&&(fsensor==true)) { j=j+1; i=i+1; dir[i] = 3; reduce(dir,i); digitalWrite(10,HIGH); digitalWrite(11,LOW); digitalWrite(12,LOW); digitalWrite(13,HIGH); delay(2*t); } // If Front is open.. else if(fsensor==false) { if((rsensor==false)&&(frontdist()>=40)) // If both front and right are open.. { i = i+1; j=j+1; if((found==true)&(dir[i]!=0)) // After reaching the end ... checks the s { rightturn();return; } else { if(found==false){ dir[i] = 0; // moving forward over right... reduce(dir,i); } /*Serial.print("for the jth turn ..");Serial.print(" =");Serial.print(j); Serial.print(" the i value is ");Serial.print(i);Serial.print("and the dir is ..");Serial.println(dir[i]);*/ timefr = tfr + 65*nf; nf=nf+1;
  • 12. stopit();delay(1000); for(int g=1;g<=10;g++){gofront();delay(timefr/10);} stopit();delay(1000); } } else {gofront();delay(300);} // Else moving forward .. only front is open. } //for a right turn.. else { i = i+1; j=j+1; dir[i] = 2; reduce(dir,i); float prevfdist = frontdist(); while( abs(frontdist()-prevfdist)<=(prevfdist/2)-2) {gofront();delay(300);if(frontdist()<=4.5){break;}} digitalWrite(10,HIGH); digitalWrite(11,LOW); digitalWrite(12,LOW); digitalWrite(13,HIGH); delay(t); float prevfrdist = frontdist(); while( abs(frontdist()- prevfrdist)<=15.2){gofront();delay(300);if(frontdist()<=4.5){break;}} } } else { //for a left turn.. i=i+1; j=j+1; if((found==true)&&(dir[i]!=1)){ if((dir[i]==2)&&(rightdist>=10)){rightturn();return;} else if((dir[i]== 0)&&(fsensor==false)) {frontturn();return;} } else{ dir[i]=1; // Left turn..
  • 13. nlr=nlr+1; reduce(dir,i); //calling reduce function to shorten the path dynamically..if path is not yet completed {gofront(); delay(tlbef);} digitalWrite(10,LOW); // takes a left turn.. digitalWrite(11,LOW); digitalWrite(12,HIGH); digitalWrite(13,LOW); delay(2*t); for(int n=1;n<=8;n++) { gofront();delay(tlaf/8);} stopit();delay(1000); } } delay(320); }