code starts acting weird after unplugging usb

I'm developing an application with an Arduino Mega 2560 and all seams to work fine until I disconnect the USB cable.

The code loads fine, and the algorithm runs according the information coming from the sensor as expected. But immediately after I unplug the USB cable the algorithm stops working as before and the entire systems becomes rather unpredictable.

The application is a very simple robot with 2 DC motors, a servo and an Ir sensor. The power is supplied by a battery pack (9V in total)

Has anyone experienced this before? I'm using Arduino IDE 0021

Thanks

The application is a very simple robot with 2 DC motors, a servo and an Ir sensor. The power is supplied by a battery pack (9V in total)

What DC motors? How are they driven? Are you using a motor driver? An H-Bridge? What kind of batteries in the battery pack? How old are they?

The DC motors are driven by an Ardumoto shield - an H bridge. The DC motors are what I would call "small normal" toy type motors and the battery pack is made of 6 1,5V alkaline batteries. But they are not too old.

...just tried connecting the robot to another PC and the same behavior is observed. When connected works fine, if disconnected starts acting weird.

I'll try again with another set of batteries. But the what I see is not the sort of behavior I would expect from that system "running out" of battery

The best battery measurement is made while trying to actually power the load. 7.5 volts (under load) is the minimum value required, under that and the Arduino auto-voltage switching circuit is bound to act wierd.

Lefty

Thank you Lefty and Paul. All works fine now. It was in fact a battery problem. The voltage was close to 7,5 and not under load.

Cheers, Luís