Motor Shield Direction not working

Hi guys, I’ve looked all over and can’t seem to find the solution to this problem.

I’ve got an Arduino UNO hooked up with a motor shield. I tried to run a script to test the motors: running them in one direction and then in the other. The code is below

/*motor test script

*/

const int AMotorSpeed = 3;        //Pins for Motor A
const int AMotorDir = 12;
const int AMotorBrake = 9;

const int BMotorSpeed = 11;       //Pins for Motor B
const int BMotorDir = 13;
const int BMotorBrake = 8;

void setup() {
  Serial.begin(9600);             // initialize serial communications at 9600 bps:
}

void loop() {
  //Motor A
  //Start Motor
  digitalWrite (AMotorDir, HIGH);        
  digitalWrite (AMotorBrake, LOW);
  analogWrite (AMotorSpeed, 200);
  Serial.print ("ON FWD A");
  delay (5000);
  //Speed Up
  analogWrite (AMotorSpeed, 500); 
  Serial.print ("-HIGH");  
  delay (5000);
  Serial.println();
  //Brake A
  analogWrite (AMotorSpeed, 0);
  digitalWrite (AMotorBrake, HIGH);
  Serial.print ("Brake A");
  Serial.println();
  delay (500);
  //Reverse Motor
  digitalWrite (AMotorDir, LOW);        
  digitalWrite (AMotorBrake, LOW);
  analogWrite (AMotorSpeed, 200);
  Serial.print ("ON FWD A");
  delay (5000);
  //Speed Up
  analogWrite (AMotorSpeed, 500);
  Serial.print ("-HIGH");
  Serial.println();  
  delay (5000);
  //Brake A
  analogWrite (AMotorSpeed, 0);
  digitalWrite (AMotorBrake, HIGH);
  Serial.print ("Brake A");
  Serial.println();
  delay (500);
  
  //-------------------------------------------------------
  
  //Motor B
  //Start Motor
  digitalWrite (BMotorDir, HIGH);        
  digitalWrite (BMotorBrake, LOW);
  analogWrite (BMotorSpeed, 200);
  Serial.print ("ON FWD B");
  delay (5000);
  
  //Speed Up
  analogWrite (BMotorSpeed, 500);
  Serial.print ("-HIGH");  
  delay (5000);
  Serial.println();
  
  //Brake B
  analogWrite (BMotorSpeed, 0);
  digitalWrite (BMotorBrake, HIGH);
  Serial.print ("Brake B");
  Serial.println();
  delay (500);
  
  //Reverse Motor
  digitalWrite (BMotorDir, LOW);        
  digitalWrite (BMotorBrake, LOW);
  analogWrite (BMotorSpeed, 200);
  Serial.print ("ON REVERSE A");
  delay (5000);
  
  //Speed Up
  analogWrite (BMotorSpeed, 500);
  Serial.print ("-HIGH");
  Serial.println();  
  delay (5000);
   
  //Brake B
  analogWrite (BMotorSpeed, 0);
  digitalWrite (BMotorBrake, HIGH);
  Serial.print ("Brake B");
  Serial.println();
  delay (500);
 
}

The problem occurs when the direction pins are set to “HIGH”. At those stages of the script above, the motor makes a high pitched whining noise, but doesn’t move. It’s similar to if the motor were jammed. If Direction is set to “LOW”, then it works beautifully.

I know it isn’t a problem with the motors, because they switched directions when I connected directly to the battery and switched polarity.

Someone please help me get this working.

Why don't you try the code right out of an Instructable to see if it works.

Here is the link.

That code was roughly the same as the one I wrote. I tried it nevertheless. Still didn't work :frowning:

Post a picture of you setup with the the wires clearly visible. Something may be wrong there.

Is it the official Arduino motor shield or a clone?

It’s an official Arduino shield. I can’t post a picture right now, but I doubt it can be wrongly connected. I’ve connected nothing other than the 2 motors to the positive and negative screw terminals on the motor shield (in both A and B). Power is from a USB cable plugged into my laptop.

How much current does each motor take?

If the motors work directly off the battery but they don't work when using the USB, then most likely the USB can't supply enough power to run the motors.

It can't be a question of current supply, can it? Like I said, they both work in one direction but not the other. In any case, One of them runs at 12V optimum (It was cannibalised from a USB vacuum cleaner), and the other runs at 9V optimum (Bought that from a store).

Yes, it can be a problem with current and voltage requirements.
The max voltage from a USB port is 5 volts. There are voltage drops in the H bridge.
What about current? How much current does each motor take?

Turn the motors on with the program and measure the voltage across the motor leads.

So, what happened?

Sorry, been out of town without access to my stuff for a while. I won't be able to check the voltage until I'm back home. In the meantime, Is it possible to measure the voltage across the leads using one of the pins? I remember seeing something in the shield's page that a couple of the pins are dedicated to current sensing of the motors. I'm asking this because I don't actually have access to a multimeter.