Confusion about wiring

Good afternoon everyone. I have a quick question. I have this code

// Turn on the Sensor to begin finding my location then turn
// on the servo motor to determine position
// Then turn on stepper motors to begin having the car move

#include <Servo.h>;
const int PingPin = 12;
const int ledPin = 13;
int pingpin1 = 8;
int pingpin2 = 9;
int pingpin3 = 10;
int pingpin4 = 11;

Servo myservo;    //create servo object to control a servo


int cm;

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  myservo.attach(7);
  //myStepper.setSpeed(40);
}

void loop()
{
  //Declare this as the main loop of the entire program
  //Turn on the servo motor to determine location
  //Servo myservo;  //create servo object to control a servo
  int angle = 0;
  Serial.println("SendA");

  for (angle = 0; angle < 180; angle += 1);
  {
    myservo.write(angle);
    delay(10);
  }
  for (angle = 180; angle >= 1; angle -= 1)
  {
    myservo.write(angle);
    delay(10);
  }
  
  Serial.println("You have succeeded up to this point");


  Serial.println("Now on to the Sensor");


  int cm = ping(12);
  Serial.println(cm);
  digitalWrite(13, HIGH);
  delay(cm * 10 ); //each centimeter adds 10 milliseconds delay
  digitalWrite(ledPin, LOW);
  delay( cm * 10);
  
  
// Activate stepper motors to move foward
// then begin looping if else statements
 if (cm <= 50) { 
   Serial.println("counterclockwise");
   digitalWrite(8, LOW);
   digitalWrite(9, HIGH);
   digitalWrite(10, HIGH);
   digitalWrite(11, LOW);
   digitalWrite(8,HIGH);
   digitalWrite(9,LOW);
   digitalWrite(10,LOW);
   digitalWrite(11,HIGH);
   delay(300);
   digitalWrite(8,LOW);
   digitalWrite(9,HIGH);
   digitalWrite(10,HIGH);
   digitalWrite(11,LOW);
   delay(600);
   delay(1000);
 }
 else
 {
   Serial.println("clockwise");
   digitalWrite(8, HIGH);
   digitalWrite(9, LOW);
   digitalWrite(10, LOW);
   digitalWrite(11, HIGH);
   delay(1000);
 }
  
}

int ping(int PingPin)
{
  long duration, cm;

  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  delayMicroseconds(2);
  digitalWrite(ledPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(ledPin, LOW);

  pinMode(PingPin, INPUT);
  duration = pulseIn(PingPin, HIGH);

  //convert the time into a distance
  cm = microsecondsToCentimeters(duration);
  return cm;
}
long microsecondsToCentimeters(long microseconds)
{
  return microseconds / 29 / 2;
}

uploaded onto an Arduino Uno and I have two little DC motors connected to an L298N H-Bridge. Now when this is all said and done I will be powering it with a battery pack that is going to be outputting 9 volts. My problem is that when I upload it just using the USB connection the DC motors work fine. However when I try to plug in just the battery pack then only the servo and the sensor will work. How exactly would I go about trying to fix this because I am honestly confused.

Please post how you have it wired? I suspect the problem is with wiring - nothing in that sketch should behave differently when running off external power as far as I can tell.

I suspect issues with power wiring, or possibly the battery being insufficient for the load. It's not one of those little rectangular 9v batteries is it? You can't use them for much of a load - I suspect that motor qualifies as such. Those 9v batteries really kinda suck.

The battery pack is actually being ran off of 6 AA batteries

The battery pack is connected at the far end of the breadboard.
The blue wire is connected to the 5v block on the Arduino.
The white wire is connected to a GND port and I have it connected to the GND area of the battery pack.
I was told that I should have the battery pack powering the H-bridge. Do i have it set up correctly or is there something I need to change?

blink seriously?

I'm not even going to try to trace out the wires in that rat's nest from a photo. Ever see the dupont jumpers that come as ribbon cable, so you can, say, pull off 6 wires you need for one thing and wire those up (you can go further and replace the housings, or get jumper cable without housings on it - though I couldn't find any of that except in F-F). They make wiring a lot neater; I would have lost my mind a while ago if I was using un-connected jumpers like you are. Anyway, to get anywhere, I'd need a schematic.

http://www.ebay.com/sch/i.html?_nkw=dupont+jumper

Would it be easier if I dismantled everything but the way I have the H-Bridge wired?

Can't see where the battery connections are. Your wiring is impossible to trace with one photo. Do your small motors work at 5V? When they were working, the USB connection was connected, was the battery also connected?

If the motors work at 5V, you connect battery 9V to arduino VIN and battery ground to arduino GND.

If motors can work at 9V, split connection of battery 9V to the motor controllers.

Well I took of everything but the wiring for the H-bridge. Rather than post another bad picture ill try to explain everything.
On the Arduino I have one wire connected to the VIN port which I have connected on the breadboard to the positive section of the battery pack.
The IN1 pin on the H-bridge is connected to Pin 8
IN2- Pin 9
IN3- Pin 10
IN4-Pin 11
The white wire is connected to another GND pin on the Arduino which I have connected to the negative half of the battery pack
On the H-Bridge I have the VCC port connected(by like a brownish wire) to the positive end of where the battery is supplying power.
GND is connected by a green wire which is connected to where the negative half of the battery pack is supplying its power.
And the 5V pin which is the pure Red Wire is connected to where the positive end of the battery pack is supplying power

This picture goes along with what I just replied

So far I am only able to get the wheels to move when it is powered by USB.

And the 5V pin which is the pure Red Wire is connected to where the positive end of the battery pack is supplying power

The positive end of the battery is 9V. The 5V pin is on what device, H-bridge? Whatever it is on, it doesn't sound right to connect 9V to 5V, does it?