IR becon pololu with arduino mega

hi , i have problem my project is robot follow people (tracking) by using pair of pololu IR becon ,but after download code on arduino , a robot does not move forward and back ,only Tire is move left and right ,anyone can help me please .

this is my code i hope get help:
Preformatted text

#include "ArduinoMotorShieldR3.h"
ArduinoMotorShieldR3 md;


#define NORTH A38
#define SOUTH  A36
#define EAST  A34
#define WEST  A32

int NORTH =0;
int SOUTH =0;
int EAST =0;
int WEST =0;

void setup() {

Serial.begin(9600);

pinMode(NORTH,INPUT);
pinMode(SOUTH,INPUT);
pinMode(EAST,INPUT);
pinMode(WEST,INPUT);

md.init();  
}

void loop() {

            
SCANDIRECTION();
 WHICHDIRECTION();
 delay(1000); 


Serial.println(analogRead(A38));
Serial.println(analogRead(A36));
Serial.println(analogRead(A34));
Serial.println(analogRead(A32));
delay(2000);}

 void WHICHDIRECTION( ){
  if (NORTH < 900 && SOUTH > 500 && EAST > 500 && WEST > 500) 
 
 {   md.setSpeeds(200,200); }


 
 
 else if (NORTH > 500 && SOUTH < 900 && EAST > 500 && WEST > 500)
 {   md.setSpeeds(-200,-200);} 



 
 else if (NORTH > 500 && SOUTH > 500 && EAST < 900 && WEST > 500)
 {   md.setSpeeds(200,0); }


 else if (NORTH > 500 && SOUTH > 500 && EAST > 500 && WEST < 900) 
 {   md.setSpeeds(0,200); }
}






void SCANDIRECTION(){
NORTH = analogRead(A38);
SOUTH = analogRead(A36);
EAST = analogRead(A34);
WEST = analogRead(A32);}`Preformatted text`

Hello.

Have you tried removing the IR beacon and hard-coding your motors to spin in each direction to make sure there is not a problem with your connections or motors?

It also looks like your code is only reading the beacon signals once every 3 seconds, which is probably making it seem unresponsive. You might try removing the delay(1000) after calling WHICHDIRECTION() and reducing the delay(2000) to something much shorter (like delay(100)).

It looks like you are using a motor shield; another thing to check is to see what pins the motor shield and motor shield library are using to make sure they do not conflict with the pins you are using to read the beacon signals.

By the way, the IR beacon outputs digital signals (5V when it does not detect anything and 0V when it sees the other beacon), and it looks like you are reading them with analogRead(). While this should still work, there is no specific benefit to treating them as analog, and digitalRead() should be much faster.

If none of those suggestions help, can you post a video of how it is behaving as well as your updated code?

Brandon