The problem is it won't turn an exact revolution of 400 steps.
It also won't work properly unless the speed is 100 rpm. Doesn't seem to like going lower than that.
The Code
#include <Stepper.h>
const int stepsPerRevolution = 400; // change this Number to fit the number of steps per revolution
// for your motor
// initialize the stepper library on the motor shield
Stepper myStepper(stepsPerRevolution, 12,13);
// give the motor control pins names: = this converts the pin voltage signals to the outputs A+- B+-
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12; // = direction of rotation
const int dirB = 13; // = direction of rotation
void setup()
{
//stepper
// set the PWM and brake pins so that the direction pins // can be used to control the motor:
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
//stepper
//stepper
myStepper.setSpeed(100);
}
void loop(){
digitalWrite(pwmA, HIGH);//=5 v
digitalWrite(pwmB, HIGH);
//digitalWrite(brakeA, LOW);//=0volts
//digitalWrite(brakeB, LOW);
myStepper.step(4000); // =360 degrees for 1.8 degree stepper
digitalWrite(pwmA, LOW);//=5 v
digitalWrite(pwmB, LOW);
//digitalWrite(brakeA, HIGH);//=0volts
//digitalWrite(brakeB, HIGH);
delay(1000);
//digitalWrite(4,LOW);
// forward button
//digitalWrite(4,HIGH);
digitalWrite(pwmA, HIGH);//=5 v
digitalWrite(pwmB, HIGH);
//digitalWrite(brakeA, LOW);//=0volts
//digitalWrite(brakeB, LOW);
myStepper.step(-4000); // =360 degrees for 1.8 degree stepper
//digitalWrite(brakeA, HIGH);//=0volts
//digitalWrite(brakeB, HIGH);
digitalWrite(pwmA, LOW);//=5 v
digitalWrite(pwmB, LOW);
delay(1000);
}
End of Code
I have the wires of the motor connected correctly to the motor shield and it will move back and forth just fine, though it doesn't move a single revolution, it either moves just over or under one rev.