SlideShare a Scribd company logo
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.
Most read
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);
Most read
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()
{
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)

Line follower robot
Line follower robotLine follower robot
Line follower robot
UVSofts Technologies
 
4 bit Binary counter
4 bit Binary counter4 bit Binary counter
4 bit Binary counter
Jainee Solanki
 
Maze solver robot presentation
Maze solver robot presentationMaze solver robot presentation
Maze solver robot presentation
Naveed Ahmed
 
Autonomous maze solving robot (1/2)
Autonomous maze solving robot (1/2)Autonomous maze solving robot (1/2)
Autonomous maze solving robot (1/2)
Musfiqur Rahman
 
light follower robot
light follower robotlight follower robot
light follower robot
anuragyadav94
 
Line Following Robot
Line Following RobotLine Following Robot
Line Following Robot
Self-employed
 
The line follower robot
The line follower robotThe line follower robot
The line follower robot
Poonam Narang
 
Introduction to PLL - phase loop lock diagram
Introduction to PLL - phase loop lock diagramIntroduction to PLL - phase loop lock diagram
Introduction to PLL - phase loop lock diagram
Hai Au
 
Line follower robot
Line follower robotLine follower robot
Line follower robot
UVSofts Technologies
 
4 legged walking robot
4 legged walking robot4 legged walking robot
4 legged walking robot
Ravi Kumar Vilasagaram
 
Proximity Sensor
Proximity Sensor Proximity Sensor
Proximity Sensor
Arif, Mohammed Nazrul Islam
 
Line follower Robot using PID algorithm
Line follower Robot using PID algorithmLine follower Robot using PID algorithm
Line follower Robot using PID algorithm
Ifaz Ahmed Aflan
 
Arduino maze solving robot
Arduino maze solving robotArduino maze solving robot
Arduino maze solving robot
Mahmoud Salheen
 
Chapter 4: Combinational Logic
Chapter 4: Combinational LogicChapter 4: Combinational Logic
Chapter 4: Combinational Logic
Er. Nawaraj Bhandari
 
PLC programming example - Paint Spray
PLC programming example - Paint SprayPLC programming example - Paint Spray
PLC programming example - Paint Spray
ACC Automation
 
Line Follower Robot
Line Follower RobotLine Follower Robot
Line Follower Robot
Bikram Prasad
 
Line follower robot
Line follower robotLine follower robot
Line follower robot
Priya Hada
 
line following robot
line following robotline following robot
line following robot
Rehnaz Razvi
 
Two wheel self balancing robot
 Two wheel self balancing robot Two wheel self balancing robot
Two wheel self balancing robot
adeela aslam
 
JK flip flops
JK flip flopsJK flip flops
JK flip flops
Zakariae EL IDRISSI
 
Maze solver robot presentation
Maze solver robot presentationMaze solver robot presentation
Maze solver robot presentation
Naveed Ahmed
 
Autonomous maze solving robot (1/2)
Autonomous maze solving robot (1/2)Autonomous maze solving robot (1/2)
Autonomous maze solving robot (1/2)
Musfiqur Rahman
 
light follower robot
light follower robotlight follower robot
light follower robot
anuragyadav94
 
Line Following Robot
Line Following RobotLine Following Robot
Line Following Robot
Self-employed
 
The line follower robot
The line follower robotThe line follower robot
The line follower robot
Poonam Narang
 
Introduction to PLL - phase loop lock diagram
Introduction to PLL - phase loop lock diagramIntroduction to PLL - phase loop lock diagram
Introduction to PLL - phase loop lock diagram
Hai Au
 
Line follower Robot using PID algorithm
Line follower Robot using PID algorithmLine follower Robot using PID algorithm
Line follower Robot using PID algorithm
Ifaz Ahmed Aflan
 
Arduino maze solving robot
Arduino maze solving robotArduino maze solving robot
Arduino maze solving robot
Mahmoud Salheen
 
PLC programming example - Paint Spray
PLC programming example - Paint SprayPLC programming example - Paint Spray
PLC programming example - Paint Spray
ACC Automation
 
Line follower robot
Line follower robotLine follower robot
Line follower robot
Priya Hada
 
line following robot
line following robotline following robot
line following robot
Rehnaz Razvi
 
Two wheel self balancing robot
 Two wheel self balancing robot Two wheel self balancing robot
Two wheel self balancing robot
adeela aslam
 

Similar to Maze Solver Robot using Arduino (20)

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

Recently uploaded (20)

soulmaite review - Find Real AI soulmate review
soulmaite review - Find Real AI soulmate reviewsoulmaite review - Find Real AI soulmate review
soulmaite review - Find Real AI soulmate review
Soulmaite
 
The case for on-premises AI
The case for on-premises AIThe case for on-premises AI
The case for on-premises AI
Principled Technologies
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
IntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdfIntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdf
Luiz Carneiro
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)
Brian Ahier
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Top 25 AI Coding Agents for Vibe Coders to Use in 2025.pdf
Top 25 AI Coding Agents for Vibe Coders to Use in 2025.pdfTop 25 AI Coding Agents for Vibe Coders to Use in 2025.pdf
Top 25 AI Coding Agents for Vibe Coders to Use in 2025.pdf
SOFTTECHHUB
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to KnowWhat is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
SMACT Works
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Dancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptxDancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptx
Elliott Richmond
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUEIntroduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
soulmaite review - Find Real AI soulmate review
soulmaite review - Find Real AI soulmate reviewsoulmaite review - Find Real AI soulmate review
soulmaite review - Find Real AI soulmate review
Soulmaite
 
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...Your startup on AWS - How to architect and maintain a Lean and Mean account J...
Your startup on AWS - How to architect and maintain a Lean and Mean account J...
angelo60207
 
IntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdfIntroSlides-May-BuildWithAi-EarthEngine.pdf
IntroSlides-May-BuildWithAi-EarthEngine.pdf
Luiz Carneiro
 
Jeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software DeveloperJeremy Millul - A Talented Software Developer
Jeremy Millul - A Talented Software Developer
Jeremy Millul
 
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2Agentic AI: Beyond the Buzz- LangGraph Studio V2
Agentic AI: Beyond the Buzz- LangGraph Studio V2
Shashikant Jagtap
 
Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)
Brian Ahier
 
LSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection FunctionLSNIF: Locally-Subdivided Neural Intersection Function
LSNIF: Locally-Subdivided Neural Intersection Function
Takahiro Harada
 
Co-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using ProvenanceCo-Constructing Explanations for AI Systems using Provenance
Co-Constructing Explanations for AI Systems using Provenance
Paul Groth
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
Top 25 AI Coding Agents for Vibe Coders to Use in 2025.pdf
Top 25 AI Coding Agents for Vibe Coders to Use in 2025.pdfTop 25 AI Coding Agents for Vibe Coders to Use in 2025.pdf
Top 25 AI Coding Agents for Vibe Coders to Use in 2025.pdf
SOFTTECHHUB
 
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und AnwendungsfälleDomino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
Domino IQ – Was Sie erwartet, erste Schritte und Anwendungsfälle
panagenda
 
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to KnowWhat is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
What is Oracle EPM A Guide to Oracle EPM Cloud Everything You Need to Know
SMACT Works
 
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOMEstablish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Establish Visibility and Manage Risk in the Supply Chain with Anchore SBOM
Anchore
 
Dancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptxDancing with AI - A Developer's Journey.pptx
Dancing with AI - A Developer's Journey.pptx
Elliott Richmond
 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
 
If You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FMEIf You Use Databricks, You Definitely Need FME
If You Use Databricks, You Definitely Need FME
Safe Software
 
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
ELNL2025 - Unlocking the Power of Sensitivity Labels - A Comprehensive Guide....
Jasper Oosterveld
 
Evaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical ContentEvaluation Challenges in Using Generative AI for Science & Technical Content
Evaluation Challenges in Using Generative AI for Science & Technical Content
Paul Groth
 
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); }