Maze Solving Robot


i working on maze solving using ir led sensor (it gives digital input arduino), motor driver ic l293d , arduino uno (atmega 328). it's not running hardware arrangement ok , code.
when storing character in array bot doesn't follow line , hangs. think there bug in code

// code maze solver

int stage=0;

char path[500]={};

int l=0;

void setup()
{
// initialisation of pins
pinmode(5,input);
pinmode(6,input);
pinmode(2,input);
pinmode(3,input);
pinmode(4,input);
pinmode(8,output);
pinmode(9,input);
pinmode(12,output);
pinmode(11,output);
pinmode(10,output);
pinmode(7,output);
serial.begin(9600);
}

void loop()

{

// read ir array sensor  
int a1=digitalread(5);           // a1 reads value of ir sensor1

int a2=digitalread(6);          // a2 reads value of ir sensor 2

int a3=digitalread(2);         // a3 reads value of ir sensor 3

int a4=digitalread(3);        // a4 reads value of ir sensor 4

int a5=digitalread(4);       // a5 reads value of ir sensor5

int a6=digitalread(9);      // a6 reads value of ir sensor6

digitalwrite(7, high);

// searching maze or searching end point of maze

// follow line simply

if(stage==0)
{
   
   if(a1 == 0 && a3 == 0 )
   {
   
     digitalwrite(8, high);
     digitalwrite(12, low);
     digitalwrite(11, high);
     digitalwrite(10, low);
     if(path[l-2]=='b')
     {
       shortpath();
     }
   
     path[l]='s';// storing straight turn
     
      l++;
     
     serial.println("breakpoint 1");

     }

  if( a5 == 0 && a6 == 0 )
 
  {
     digitalwrite(8,low);               /* code turning motor left
     digitalwrite(12, high);
     digitalwrite(11, high);
     digitalwrite(10, low);            */
     
     path[l]='l'; // storing left turn
     
     l++;
     
     if(path[l-2]=='b')
     
     {
       shortpath();
     }
     
     serial.println("breakpoint 2");
    }
   
     if(  a4 == 0 && a2 == 0)
   
    {
     digitalwrite(12, low);
     digitalwrite(8, high);
     digitalwrite(11, low);
     digitalwrite(10, low);
   
    path[l]='r';//storing right turn
   
     l++; // array increment
   
      serial.println("breakpoint 3");
     
     if(path[l-2]=='b')
     {
       shortpath();
     }
    }
   
    if(a1==1 && a2==1 && a3==1 && a4==1 && a5==1 && a6==1)
   
    {
   
     digitalwrite(12, low);
     digitalwrite(8, high);
     digitalwrite(11, low);
     digitalwrite(10, high);
   
       path[l]='b'; // storing turnaround move
     
        l++;
     
      serial.println("breakpoint 4");
   }
   if(a1 == 0 && a2 == 0 && a3 == 0 && a4 == 0 && a5 == 0 && a6 == 0)
   {
     digitalwrite(12, low);
     digitalwrite(8, low);
     digitalwrite(11, low);
     digitalwrite(10, low);
     serial.println("breakpoint 5");
     
       if(a1==0 && a2==0 && a3==0 && a4==0 && a5==0 && a6==0)
        {
       
       digitalwrite(12, low);
       digitalwrite(8, low);
       digitalwrite(11, low);
       digitalwrite(10, low);
       stage==1;
       replay();
       serial.println("breakpoint 6");
       delay(2000);
     }
    }
   }
  }
// shortening path or reduce unnecessary move    
void shortpath()
{
 int shortdone=0;
 if(path[l-3]=='l' && path[l-1]=='r')
{
  l-=3;
  path[l]='b';
  shortdone=1;
}

if(path[l-3]=='l' && path[l-1]=='s' && shortdone==0)
{
  l-=3;
  path[l]='r';
  shortdone=1;
}
if(path[l-3]=='r' && path[l-1]=='l' && shortdone==0)
{
  l-=3;
  path[l]='b';
  shortdone=1;
}

if(path[l-3]=='s' && path[l-1]=='l' && shortdone==0)

{
 l-=3;
 path[l]='r';
 shortdone=1;
}

if(path[l-3]=='s' && path[l-1]=='s' && shortdone==0)

{
 l-=3;
 path[l]='b';
 shortdone=1;
}

if(path[l-3]=='l' && path[l-1]=='l' && shortdone==0)

{
l-=3;
path[l]='s';
shortdone=1;
}

}
// final path
void replay()
{

if(stage==1)

{

for(l=0; path[l]<='\0'; l++)

{

if(path[l]=='s')

   {

     digitalwrite(13, high  );
     digitalwrite(12, low);
     digitalwrite(11, high);
     digitalwrite(10, high);
 
}
if(path[l]=='l')

   {

     digitalwrite(13, high);
     digitalwrite(12, low);
     digitalwrite(11, low);
     digitalwrite(10, low);

   }
if(path[l]=='r')

 {
   digitalwrite(13, low);
   digitalwrite(12, low);
   digitalwrite(11, high);
   digitalwrite(10, low);
 }
else
{
   digitalwrite(8, low);
   digitalwrite(12, low);
   digitalwrite(11, low);
   digitalwrite(10, low);
 }
}
}
}
plz me out code  and find bug. asap

well start use code tag (not quote) edit first post , insert tag before , after code , rid of second duplicate post ugly.

then ask question. need? works, not?what's behavior versus think should get?


Arduino Forum > Using Arduino > Programming Questions > Maze Solving Robot


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'