UNO R3 with Adafruit MotorShield V2.3 not driving motors consistently

My setup includes the following:

  • Arduino UNO R3
  • Adafruit MotorShield V2.3
  • Four DC 130 motors
  • Battery Pack with five NiMH Rechargeable AA batteries (checked for charge)

The code is here:

/* 
This sketch drives a robot with four DC 130 motors back and forth.  It is designed to be used with
an Uno and an Adafruit MotorShield V2 ---> http://www.adafruit.com/products/1438

Wiring Schematic is here: LINK

Written by Steve Cline
WizardsRobotics 19 July 2017
*/

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 

// Set up motors
Adafruit_DCMotor *RF = AFMS.getMotor(1); // Right Front is M1
Adafruit_DCMotor *LF = AFMS.getMotor(2); // Left Front is M2
Adafruit_DCMotor *RR = AFMS.getMotor(3); // Right Rear is M3
Adafruit_DCMotor *LR = AFMS.getMotor(4); // Left Rear is M4

void setup() {

  AFMS.begin();  // create with the default frequency 1.6KHz

}

void loop() {
  uint8_t i; // declares i for later use as an unsigned 8-bit integer (0 to 255)

// All motors forward
  RF->run(FORWARD);
  RF->setSpeed(500);  
  LF->run(FORWARD);
  LF->setSpeed(500);
  RR->run(FORWARD);
  RR->setSpeed(500);
  LR->run(FORWARD);
  LR->setSpeed(500);

  delay(500);// go for .5 seconds

// All motors stop
  RF->run(RELEASE);
  LF->run(RELEASE);
  RR->run(RELEASE);
  LR->run(RELEASE);

  delay(1000);

// Turn Around 
  RF->run(BACKWARD);
  RF->setSpeed(140);  
  LF->run(FORWARD);
  LF->setSpeed(140);
  RR->run(BACKWARD);
  RR->setSpeed(140);
  LR->run(FORWARD);
  LR->setSpeed(140);

  delay(3000); // This is the duration of the turn.  This will vary based on setup.

}

I have been able to run this at times but it is intermittently failing (i.e. no response from the motors). I have changed batteries and even plugged into 9V DC adapter. I have tried it with two different UNOs and two different shields.

Any debugging suggestions are appreciated.

Four DC 130 motors

Which are what? What voltage? How much current do they draw?

Battery Pack with five NiMH Rechargeable AA batteries (checked for charge)

which probably do not output enough current to drive 4 motors at the same time.

Your 9v adapter, what is its capacity? Is it a wall wart? Frequently those provide very little current and probably do not output enough current to drive 4 motors at the same time.