I am making a maze-solving robot using Arduino uno, mpu 6050 gyroscope and encoder. My program crashes after some time (usually 10-13seconds) after I run the robot. It seems to get stuck in the TravelStraightForward18cm() since it spends most of the time in that function. I think it might be that gyroscope values are being overfilled into the arduino and do not get cleared in the stack. The code does use a lot of gyroscope readings to correct for angular deviations, make turns and the whole navigation. Can anyone let me know how i can improve my code to avoid such a crash.
Gold_Detection.ino (32.1 KB)