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.