L298n shield v2.1 problems

hi there. first post here
i am having trouble with the L298n shield v2.1.

http://www.elechouse.com/store/bbs/viewtopic.php?f=8&t=12

i am running on a arduino mega and a 7.2v 2map battery for the motors

the wiring looks good, the motors run but it doesnot do what the code intends to:

int pwm_a = 10;  //speed right motor
int pwm_b = 9;  //speed left motor
int dir_fa = 12;  //forward motor right
int dir_ba = 13;  //backwards motor right
int dir_fb = 11;  //forward motor left
int dir_bb = 8;  //backwards motor left

void setup()
{
  pinMode(pwm_a, OUTPUT);  //Set control pins to be outputs
  pinMode(pwm_b, OUTPUT);
  pinMode(dir_fa, OUTPUT);
  pinMode(dir_ba, OUTPUT);
  pinMode(dir_fb, OUTPUT);
  pinMode(dir_bb, OUTPUT);
  
  analogWrite(pwm_a, 100);  //set both motors to run at (100/255 = 39)% duty cycle (slow)
  analogWrite(pwm_b, 100);
  
}

void loop()
{
  digitalWrite(dir_fa, HIGH);  //GO FORWARD
  digitalWrite(dir_ba, LOW);
  digitalWrite(dir_fb, HIGH);
 digitalWrite(dir_bb, LOW); 
  
  delay(5000);
  
   digitalWrite(dir_fa, LOW);  // GO BACKWARDS
  digitalWrite(dir_ba, HIGH);
  digitalWrite(dir_fb, LOW);
 digitalWrite(dir_bb, HIGH); 
  
  delay(5000);
  
}

i got this code from a website and changed the values, it should make the motors run forwards for 5 seconds then backwards for 5 secondes and loops, however the motors run back and forth on their own.

is the a problem with the code? please help,
Thanks Paulo

however the motors run back and forth on their own.

Not sure what you mean, do you mean they change direction randomly?
The code looks good to me, it must be your wiring or power supply not being able to give enough current for the motors.
Alternatively it could be the motors generating interference and resetting the arduino. Put a single blink of the Pin 13 LED in the setup to see if it keeps resting.

hey grumpy mike
yes hey change direction randomly,
i just put a led on pin 13 and turned on and was flickering, like the motors.
i then switched the power wires from volt in and ground to the vex and gnd screw pins on the shield and it works.
i will assemble the robot now see if does the other codes like turn and stops.
thank you very much for the idea.