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)

Sphero Write Up
Sphero Write UpSphero Write Up
Sphero Write Up
Sahil Parikh
 
Line maze solver
Line maze solverLine maze solver
Line maze solver
Sushil Dahal
 
Final Lab, Arduino Robot Challenge
Final Lab, Arduino Robot ChallengeFinal Lab, Arduino Robot Challenge
Final Lab, Arduino Robot Challenge
James Smith
 
Obstacle avoiding robot
Obstacle avoiding robotObstacle avoiding robot
Obstacle avoiding robot
Electronics - Embedded System
 
Obstacle Avoiding Robot Using Micro Controller
Obstacle Avoiding Robot Using Micro ControllerObstacle Avoiding Robot Using Micro Controller
Obstacle Avoiding Robot Using Micro Controller
Electronics - Embedded System
 
Lecture 12 localization and navigation
Lecture 12 localization and navigationLecture 12 localization and navigation
Lecture 12 localization and navigation
Vajira Thambawita
 
HandyBug Robot
HandyBug Robot HandyBug Robot
HandyBug Robot
Reyna M
 
Introduction to robotics
Introduction to roboticsIntroduction to robotics
Introduction to robotics
akhil_n12
 
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
 
Obstacle Avoidance Robot
Obstacle Avoidance RobotObstacle Avoidance Robot
Obstacle Avoidance Robot
Yash Sati
 
Pid controller for lego mindstorms robots
Pid controller for lego mindstorms robotsPid controller for lego mindstorms robots
Pid controller for lego mindstorms robots
Alban Avila
 
MexiLego
MexiLegoMexiLego
MexiLego
lalosam369
 
Ldr based line follower robot
Ldr based line follower robotLdr based line follower robot
Ldr based line follower robot
Akshay Sharma
 
Line Following Robot Presentation
Line Following Robot PresentationLine Following Robot Presentation
Line Following Robot Presentation
Oli ullah
 
Graph Exploration Algorithm- Term Paper Presentation
Graph Exploration Algorithm- Term Paper PresentationGraph 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...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
E017142429E017142429
E017142429
IOSR Journals
 
Introduction to Mobile Robotics
Introduction to Mobile RoboticsIntroduction to Mobile Robotics
Introduction to Mobile Robotics
Robots Alive India
 
Lecture2
Lecture2Lecture2
Lecture2
Fan Hong
 
Impediment detection robot using Arduino
Impediment detection robot using ArduinoImpediment detection robot using Arduino
Impediment detection robot using Arduino
Ayush Chhangani
 
Final Lab, Arduino Robot Challenge
Final Lab, Arduino Robot ChallengeFinal Lab, Arduino Robot Challenge
Final Lab, Arduino Robot Challenge
James Smith
 
Lecture 12 localization and navigation
Lecture 12 localization and navigationLecture 12 localization and navigation
Lecture 12 localization and navigation
Vajira Thambawita
 
HandyBug Robot
HandyBug Robot HandyBug Robot
HandyBug Robot
Reyna M
 
Introduction to robotics
Introduction to roboticsIntroduction to robotics
Introduction to robotics
akhil_n12
 
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
 
Obstacle Avoidance Robot
Obstacle Avoidance RobotObstacle Avoidance Robot
Obstacle Avoidance Robot
Yash Sati
 
Pid controller for lego mindstorms robots
Pid controller for lego mindstorms robotsPid controller for lego mindstorms robots
Pid controller for lego mindstorms robots
Alban Avila
 
Ldr based line follower robot
Ldr based line follower robotLdr based line follower robot
Ldr based line follower robot
Akshay Sharma
 
Line Following Robot Presentation
Line Following Robot PresentationLine Following Robot Presentation
Line Following Robot Presentation
Oli ullah
 
Graph Exploration Algorithm- Term Paper Presentation
Graph Exploration Algorithm- Term Paper PresentationGraph 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...A Comprehensive and Comparative Study Of Maze-Solving Techniques by Implement...
A Comprehensive and Comparative Study Of Maze-Solving Techniques by Implement...
IOSR Journals
 
Introduction to Mobile Robotics
Introduction to Mobile RoboticsIntroduction to Mobile Robotics
Introduction to Mobile Robotics
Robots Alive India
 
Impediment detection robot using Arduino
Impediment detection robot using ArduinoImpediment detection robot using Arduino
Impediment detection robot using Arduino
Ayush Chhangani
 
Ad

Recently uploaded (20)

Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf
Minuscule Technologies
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Create Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent BuilderCreate Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent Builder
DianaGray10
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
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
 
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
 
Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...
Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...
Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...
Scott M. Graffius
 
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
 
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
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptxISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
AyilurRamnath1
 
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
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)
Brian Ahier
 
Palo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity FoundationPalo Alto Networks Cybersecurity Foundation
Palo Alto Networks Cybersecurity Foundation
VICTOR MAESTRE RAMIREZ
 
Improving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevExImproving Developer Productivity With DORA, SPACE, and DevEx
Improving Developer Productivity With DORA, SPACE, and DevEx
Justin Reock
 
7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf7 Salesforce Data Cloud Best Practices.pdf
7 Salesforce Data Cloud Best Practices.pdf
Minuscule Technologies
 
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025Azure vs AWS  Which Cloud Platform Is Best for Your Business in 2025
Azure vs AWS Which Cloud Platform Is Best for Your Business in 2025
Infrassist Technologies Pvt. Ltd.
 
Create Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent BuilderCreate Your First AI Agent with UiPath Agent Builder
Create Your First AI Agent with UiPath Agent Builder
DianaGray10
 
Jira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : IntroductionJira Administration Training – Day 1 : Introduction
Jira Administration Training – Day 1 : Introduction
Ravi Teja
 
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
 
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
 
Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...
Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...
Mark Zuckerberg teams up with frenemy Palmer Luckey to shape the future of XR...
Scott M. Graffius
 
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
 
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
 
Data Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any ApplicationData Virtualization: Bringing the Power of FME to Any Application
Data Virtualization: Bringing the Power of FME to Any Application
Safe Software
 
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptxISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
ISOIEC 42005 Revolutionalises AI Impact Assessment.pptx
AyilurRamnath1
 
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
 
Your startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean accountYour startup on AWS - How to architect and maintain a Lean and Mean account
Your startup on AWS - How to architect and maintain a Lean and Mean account
angelo60207
 
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto CertificateCybersecurity Fundamentals: Apprentice - Palo Alto Certificate
Cybersecurity Fundamentals: Apprentice - Palo Alto Certificate
VICTOR MAESTRE RAMIREZ
 
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyesEnd-to-end Assurance for SD-WAN & SASE with ThousandEyes
End-to-end Assurance for SD-WAN & SASE with ThousandEyes
ThousandEyes
 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
 
Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)Trends Report: Artificial Intelligence (AI)
Trends Report: Artificial Intelligence (AI)
Brian Ahier
 
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); }