Im having a little issue with my stepper motor. I was using a basic code from the arduino Library but the motor will only turn in one direction even with a " - " infront of it. It will only vibrate when going in the other direction but not move.
I haven't changed the code but Maybe my motor isn't set up right
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
You cannot use the Stepper library with that type of stepper driver. For step/dir drivers like yours (A4988, DRV8825 to name 2) use the AccelStepper library or one of the many others. Lately I have been using MobaTools stepper library.
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
// step one revolution in the other direction:
Serial.println("counterclockwise");
myStepper.step(-stepsPerRevolution);
delay(500);
}
Hi,
In addition to this library not working with this driver,
your code does not match your step driver pins.
In your drawing the driver is connected to pins 0 and 3,
and in the code it says it should be 8, 9, 10, 11.
Remembering that pin 0 is used with the serial, and it is not recommended to use it with the I/O pin.