Arduino Uno R3 and Motor Shield not working properly on battery power.

I have my Uno R3 setup with the Arduino recommended motor shield. I am using both channels to power some fairly small motors (see this amazon product: http://www.amazon.com/gp/product/B00GLO5SMY/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1 ). I also have a small pushbutton hooked up to a breadboard. My code is attached at the bottom. When connected to both a 9V battery via the Arduino's power port and USB, the code works fantastic. Later, when I unplug the USB the motors do not spin with just the 9V battery. When unplugging the 9v battery and leaving just the USB the motors spin very slowly in the way that they do when the shield cannot get enough power. I tried resetting the Arduino when on just 9V and everything. I also tried hooking up the battery box that came with the amazon product with the 9v to the motor shield's vin and ground terminals, and I tried just the battery box by itself, but still no luck.

After searching around on the internet I came across this post: http://forum.arduino.cc/index.php?topic=233578.0 but my Arduino is not fried because any other sketches I try work fine.

const int buttonPin = 2;
int buttonReading;

void setup() {
  pinMode(buttonPin, INPUT);
  
  //Setup Channel A
  pinMode(12, OUTPUT);
  pinMode(9, OUTPUT);

  //Setup Channel B
  pinMode(13, OUTPUT);
  pinMode(8, OUTPUT);
}

void loop() {
  buttonReading = digitalRead(buttonPin);
  
  while (buttonReading == LOW) {
    motorSequence();
    buttonReading = digitalRead(buttonPin);
  }
  allStop(); //Remove this line for the car to keep going after release.
}
void motorSequence() {
  motorAForward();
  motorBForward();
}

void motorAForward() {
   //Motor A forward @ full speed
  digitalWrite(12, LOW); //Establishes forward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 255);   //Spins the motor on Channel A at full speed
}

void motorBForward() {
  //Motor B forward @ full speed
  digitalWrite(13, LOW); //Establishes forward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 255);   //Spins the motor on Channel B at full speed
}

void motorBBack() {
  //Motor B forward @ full speed
  digitalWrite(13, HIGH); //Establishes backward direction of Channel B
  digitalWrite(8, LOW);   //Disengage the Brake for Channel B
  analogWrite(11, 255);   //Spins the motor on Channel B at full speed
}

void motorABack() {
  //Motor A forward @ full speed
  digitalWrite(12, HIGH); //Establishes backward direction of Channel A
  digitalWrite(9, LOW);   //Disengage the Brake for Channel A
  analogWrite(3, 255);   //Spins the motor on Channel A at full speed
}

void allStop() {
  digitalWrite(9, HIGH);   //Engage the Brake for Channel A
  digitalWrite(8, HIGH);   //Engage the Brake for Channel B
  analogWrite(3, 0);   //Spins the motor on Channel A at no speed
  analogWrite(11, 0);   //Spins the motor on Channel B at no speed
}

When connected to both a 9V battery

A smoke detector battery? Put the battery back in the smoke detector before you burn your house down and get a real battery (pack).

I tried with the attached battery pack (4 AA batteries) and still no luck. What's wrong with 9V batteries anyways?

You will get much better results if you use a pack of 6 AA's. Make sure they are rechargeable batteries as this works out much cheaper. As a tip connect the batteries to the motor shield not directly to the Arduino.

Why won't a PP3 do the job - the short answer is that it just is not big enough - its not really that good for the arduino alone. If the batteries fell warm your over using them.

Mark

What's wrong with 9V batteries anyways?

Have you ever seen firefighters putting out a fire by pissing on it?

Of course not. They use big hoses that can pump out lots of water.

Using a 9V battery to power a robot is like pissing on a forest fire.