SlideShare a Scribd company logo
4
Most read
5
Most read
7
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);
}
Ad

Recommended

Line Maze Solver Presentation
Line Maze Solver Presentation
SoujanyaChatterjee1
 
AUTONOMOUS MAZE SOLVING ROBOT
AUTONOMOUS MAZE SOLVING ROBOT
Musfiqur Rahman
 
Présentation intelligence émotionnel
Présentation intelligence émotionnel
Yasmine Tounsi
 
Chapitre 5 échantillonnage.pptx
Chapitre 5 échantillonnage.pptx
FadilaFE
 
Obstacle detection Robot using Ultrasonic Sensor and Arduino UNO
Obstacle detection Robot using Ultrasonic Sensor and Arduino UNO
Sanjay Kumar
 
School LAC Plan for school and classroom uses.docx
School LAC Plan for school and classroom uses.docx
IvyLood1
 
Schizophrenia
Schizophrenia
MingMing Davis
 
Mercedes benz pld mr y adm
Mercedes benz pld mr y adm
Claudio Iglesias
 
Line Following Robot
Line Following Robot
Vikram Jha
 
Line follower robot
Line follower robot
Priya Hada
 
line following robot ppt
line following robot ppt
Suchit Moon
 
Line Following Robot
Line Following Robot
Self-employed
 
Final report of line follower robot
Final report of line follower robot
Rohit Dadoriya
 
Line follower robot
Line follower robot
Rohit Dadoriya
 
How to make a Line Follower Robot
How to make a Line Follower Robot
roboVITics club
 
Final report obstacle avoiding roboat
Final report obstacle avoiding roboat
Shubham Thakur
 
line following robot
line following robot
Rehnaz Razvi
 
Pick & place robot ppt
Pick & place robot ppt
Rahul Banerjee
 
Traffic light controller
Traffic light controller
" Its-CooL " is said " Iskool "
 
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
raosandy11
 
Obstacle avoiding robot.doc
Obstacle avoiding robot.doc
Electronics - Embedded System
 
Smart traffic light controller using verilog
Smart traffic light controller using verilog
VaishaliVaishali14
 
Chapter 1 introduction to control system
Chapter 1 introduction to control system
LenchoDuguma
 
Transistor Transistor Logic
Transistor Transistor Logic
surat murthy
 
Fire fighting robot ppt
Fire fighting robot ppt
athmeg
 
Four way traffic light conrol using Verilog
Four way traffic light conrol using Verilog
Utkarsh De
 
Minor Project Report: Automatic Door Control System
Minor Project Report: Automatic Door Control System
Saban Kumar K.C.
 
Final report on line follower
Final report on line follower
Priya Hada
 
Sphero Write Up
Sphero Write Up
Sahil Parikh
 
Line maze solver
Line maze solver
Sushil Dahal
 

More Related Content

What's hot (20)

Line Following Robot
Line Following Robot
Vikram Jha
 
Line follower robot
Line follower robot
Priya Hada
 
line following robot ppt
line following robot ppt
Suchit Moon
 
Line Following Robot
Line Following Robot
Self-employed
 
Final report of line follower robot
Final report of line follower robot
Rohit Dadoriya
 
Line follower robot
Line follower robot
Rohit Dadoriya
 
How to make a Line Follower Robot
How to make a Line Follower Robot
roboVITics club
 
Final report obstacle avoiding roboat
Final report obstacle avoiding roboat
Shubham Thakur
 
line following robot
line following robot
Rehnaz Razvi
 
Pick & place robot ppt
Pick & place robot ppt
Rahul Banerjee
 
Traffic light controller
Traffic light controller
" Its-CooL " is said " Iskool "
 
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
raosandy11
 
Obstacle avoiding robot.doc
Obstacle avoiding robot.doc
Electronics - Embedded System
 
Smart traffic light controller using verilog
Smart traffic light controller using verilog
VaishaliVaishali14
 
Chapter 1 introduction to control system
Chapter 1 introduction to control system
LenchoDuguma
 
Transistor Transistor Logic
Transistor Transistor Logic
surat murthy
 
Fire fighting robot ppt
Fire fighting robot ppt
athmeg
 
Four way traffic light conrol using Verilog
Four way traffic light conrol using Verilog
Utkarsh De
 
Minor Project Report: Automatic Door Control System
Minor Project Report: Automatic Door Control System
Saban Kumar K.C.
 
Final report on line follower
Final report on line follower
Priya Hada
 
Line Following Robot
Line Following Robot
Vikram Jha
 
Line follower robot
Line follower robot
Priya Hada
 
line following robot ppt
line following robot ppt
Suchit Moon
 
Line Following Robot
Line Following Robot
Self-employed
 
Final report of line follower robot
Final report of line follower robot
Rohit Dadoriya
 
How to make a Line Follower Robot
How to make a Line Follower Robot
roboVITics club
 
Final report obstacle avoiding roboat
Final report obstacle avoiding roboat
Shubham Thakur
 
line following robot
line following robot
Rehnaz Razvi
 
Pick & place robot ppt
Pick & place robot ppt
Rahul Banerjee
 
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
raosandy11
 
Smart traffic light controller using verilog
Smart traffic light controller using verilog
VaishaliVaishali14
 
Chapter 1 introduction to control system
Chapter 1 introduction to control system
LenchoDuguma
 
Transistor Transistor Logic
Transistor Transistor Logic
surat murthy
 
Fire fighting robot ppt
Fire fighting robot ppt
athmeg
 
Four way traffic light conrol using Verilog
Four way traffic light conrol using Verilog
Utkarsh De
 
Minor Project Report: Automatic Door Control System
Minor Project Report: Automatic Door Control System
Saban Kumar K.C.
 
Final report on line follower
Final report on line follower
Priya Hada
 

Similar to Maze Solver Robot using Arduino (20)

Sphero Write Up
Sphero Write Up
Sahil Parikh
 
Line maze solver
Line maze solver
Sushil Dahal
 
Final Lab, Arduino Robot Challenge
Final Lab, Arduino Robot Challenge
James Smith
 
Obstacle avoiding robot
Obstacle avoiding robot
Electronics - Embedded System
 
Obstacle Avoiding Robot Using Micro Controller
Obstacle Avoiding Robot Using Micro Controller
Electronics - Embedded System
 
Lecture 12 localization and navigation
Lecture 12 localization and navigation
Vajira Thambawita
 
HandyBug Robot
HandyBug Robot
Reyna M
 
Introduction to robotics
Introduction to robotics
akhil_n12
 
2015_1009_Line following - Braitenberg, robot examples.ppt
2015_1009_Line following - Braitenberg, robot examples.ppt
r_sadoun
 
Obstacle Avoidance Robot
Obstacle Avoidance Robot
Yash Sati
 
Pid controller for lego mindstorms robots
Pid controller for lego mindstorms robots
Alban Avila
 
MexiLego
MexiLego
lalosam369
 
Ldr based line follower robot
Ldr based line follower robot
Akshay Sharma
 
Line Following Robot Presentation
Line Following Robot Presentation
Oli ullah
 
Graph Exploration Algorithm- Term Paper Presentation
Graph Exploration Algorithm- Term Paper Presentation
Varun Narang
 
A Comprehensive and Comparative Study Of Maze-Solving Techniques by Implement...
A Comprehensive and Comparative Study Of Maze-Solving Techniques by Implement...
IOSR Journals
 
E017142429
E017142429
IOSR Journals
 
line following robot
line following robot
Rehnaz Razvi
 
Introduction to Mobile Robotics
Introduction to Mobile Robotics
Robots Alive India
 
Lecture2
Lecture2
Fan Hong
 
Final Lab, Arduino Robot Challenge
Final Lab, Arduino Robot Challenge
James Smith
 
Lecture 12 localization and navigation
Lecture 12 localization and navigation
Vajira Thambawita
 
HandyBug Robot
HandyBug Robot
Reyna M
 
Introduction to robotics
Introduction to robotics
akhil_n12
 
2015_1009_Line following - Braitenberg, robot examples.ppt
2015_1009_Line following - Braitenberg, robot examples.ppt
r_sadoun
 
Obstacle Avoidance Robot
Obstacle Avoidance Robot
Yash Sati
 
Pid controller for lego mindstorms robots
Pid controller for lego mindstorms robots
Alban Avila
 
Ldr based line follower robot
Ldr based line follower robot
Akshay Sharma
 
Line Following Robot Presentation
Line Following Robot Presentation
Oli ullah
 
Graph Exploration Algorithm- Term Paper Presentation
Graph Exploration Algorithm- Term Paper Presentation
Varun Narang
 
A Comprehensive and Comparative Study Of Maze-Solving Techniques by Implement...
A Comprehensive and Comparative Study Of Maze-Solving Techniques by Implement...
IOSR Journals
 
line following robot
line following robot
Rehnaz Razvi
 
Introduction to Mobile Robotics
Introduction to Mobile Robotics
Robots Alive India
 
Ad

Recently uploaded (20)

Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
The Future of Data, AI, and AR: Innovation Inspired by You.pdf
The Future of Data, AI, and AR: Innovation Inspired by You.pdf
Safe Software
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Enabling BIM / GIS integrations with Other Systems with FME
Enabling BIM / GIS integrations with Other Systems with FME
Safe Software
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Powering Multi-Page Web Applications Using Flow Apps and FME Data Streaming
Safe Software
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
 
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
"How to survive Black Friday: preparing e-commerce for a peak season", Yurii ...
Fwdays
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
 
June Patch Tuesday
June Patch Tuesday
Ivanti
 
The Future of Data, AI, and AR: Innovation Inspired by You.pdf
The Future of Data, AI, and AR: Innovation Inspired by You.pdf
Safe Software
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
PyCon SG 25 - Firecracker Made Easy with Python.pdf
PyCon SG 25 - Firecracker Made Easy with Python.pdf
Muhammad Yuga Nugraha
 
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
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); }