Hello, I've got a little problem regarding my stepper motor. I'm using Stepper Motor 17HS4401 with pololu A4988 driver and for the controller I'm using arduino Mega.
So, here is my problem. I want to test whether my motors are working correctly, so I'm using a simple code which is used to turn the motor left and right simultaneously. However, the motors only rotating on clockwise direction and sometimes randomly rotating counter clockwise. I've try several motors and several drivers and the result is still the same. The code itself is supposedly contained no error.
Here is the code I'm using:
const int stepPin = 3;
const int dirPin = 4;
void setup() {
// Sets the two pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
}
void loop() {
digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
// Makes 200 pulses for making two full cycle rotation
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1500); // One second delay
digitalWrite(dirPin,LOW); //Changes the rotations direction
//Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
delay(1500);
}
Can anybody help me with this matter, please? Thank you very much