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
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?