I'm using an Arduino Mega 2560 board on a Raspberry Pi. Whenever I upload my program I can start using it, however 1-2 minutes after I start the program it'll disconnect and the code will (obviously) stop working. I can reupload the program by going into Tools and then clicking on the port, but I need my code to run for a long time so that isn't sustainable. Also, I can't attach my code because it exceeds the maximum character limit, but I'll write a small blurb below describing how it works.
Thanks.
Essentially what my code should do is if it receives <1,5> from the serial port it'll check a series of ultrasonic sensors to see if there is an object close enough, and if there is then it'll move a servo. Similarly, if I send <1,9> to it, it'll see if an object is too far and then move a servo. If I send <2,x> (where x is an integer), it'll send <3,x> back and then print x later. (Yes this is necessary and yes I know that I could just print x normally if I wanted to.)
The code is attached. Though I honestly don't think that's relevant. I'm pretty sure its a problem with the Arduino, though, not the code.
As for the circuitry it's four LEDs, 4 ultrasonic sensors, 4 photoresistors, and 4 servos all attached to the Arduino Mega 2560. Oh, and there's a shield to enable Xbee communication.
I found the problem. The circuit was drawing too much power from my Arduino, causing it to malfunction whenever I asked it to perform a task that used a lot of juice. I hooked it up to an external power supply and now it works like a charm.
I hope this helps anyone else with the same problem.