First off, this robot is my son's science fair project. His question was "How fast can a robot solve a maze?". He has told his teacher that he built the robot, and that I (his father) have written the coding for the robot. He gave his in class report on a failed experiment, even telling them that the robot had problems and was unable to complete the experiment, and the teacher thought his project was good enough that they selected him to go to the area science fair even though the robot was not functioning properly. I have spent the last three weeks trying (unsuccessfully) to get it to work without resetting in the middle of things. I have decided to ask for help, since it appears this problem is beyond me..
Our robot works (to a point) in that it drives forward until it detects an obstacle, then it sweeps the infrared sensor array (using a servo) to detect a clear path. It then rotates to that heading, and continues forward.
The problem I am having is that the robot would just stop with no apparent reason. I added a bunch of serial output from the robot so that we could see what was happening, and it looks like the setup() routine is being called when the robot just stops. This would indicate to me that the microprocessor is being reset somehow - I'm not sure what would cause that. Sometimes the robot resets after the first sweep of the servo, sometimes it can make 2 or three decisions before it resets.
Hardware wise, I am running the arduino, a motor control shield, bluetooth serial adaptor, and the servo all from a 7.2V 2200mAh LiPo battery pack, connected to an LM7805 voltage regulator giving +5V to the VCC on the arduino. The motors are 4.5V motors, connected to tank treads, and the servos are Tower Pro MG-90S servos on a pan/tilt assembly. I am not really using the tilt servo and have even disconnected it to see if that made any difference (it didn't).
I am including a copy of the code that runs the robot, in hopes that someone smarter than myself can point out where I may have gone wrong so that we can get this robot running before he has to present on Friday. (The source code exceeds the limits of the message post, so I have included a link to the file in my dropbox)
Any help would be appreciated.