Hello fellow Arduino users,
I'm working on a small project involving a Nema 17 stepper motor and the A4988 driver(hiletgo). The motor spins one direction no problem, but when it goes to spin the opposite direction the motor has a horrible vibration sound and barely moves the shaft. The schematic and code will be linked below. I can attach a video as well if that helps. Any feedback would be great. I adjusted the onboard potentiometer so that the Vref is 1.2 volts which is what a source told me to set it to. Power supply was set to 10 volts, I can adjust current if needed. I believe when the motor was running it was pulling about 0.5 A. Any help would be wonderful thank you!
// Define pin connections & motor's steps per revolution
const int dirPin = 2;
const int stepPin = 3;
const int stepsPerRevolution = 200;
void setup()
{
// Declare pins as Outputs
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop()
{
// Set motor direction clockwise
digitalWrite(dirPin, HIGH);
// Spin motor slowly
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(2000);
digitalWrite(stepPin, LOW);
delayMicroseconds(2000);
}
delay(1000); // Wait a second
// Set motor direction counterclockwise
digitalWrite(dirPin, LOW);
// Spin motor quickly
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin, LOW);
delayMicroseconds(1000);
}
delay(1000); // Wait a second
}
