Only one diretion stepper motor

Hi, I tried to do this test code ```// Example sketch for testing direction
const int DIR_PIN = 2; // Your DIR pin
const int STEP_PIN = 3; // Your STEP pin
const int STEPS_PER_REV = 200; // Adjust for your motor

void setup() {
pinMode(DIR_PIN, OUTPUT);
pinMode(STEP_PIN, OUTPUT);
// pinMode(MS1, OUTPUT); // If you're using microstepping pins
// pinMode(MS2, OUTPUT);
// pinMode(MS3, OUTPUT);
// digitalWrite(MS1, LOW); // Full step mode
// digitalWrite(MS2, LOW);
// digitalWrite(MS3, LOW);
digitalWrite(ENABLE_PIN, LOW); // If you have an ENABLE pin
Serial.begin(9600);
}

void loop() {
Serial.println("Turning one way...");
digitalWrite(DIR_PIN, HIGH); // Set direction
for (int i = 0; i < STEPS_PER_REV; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(500); // Adjust for speed
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(500);
}
delay(2000); // Wait 2 seconds

Serial.println("Trying other way...");
digitalWrite(DIR_PIN, LOW); // Change direction
for (int i = 0; i < STEPS_PER_REV; i++) {
digitalWrite(STEP_PIN, HIGH);
delayMicroseconds(500);
digitalWrite(STEP_PIN, LOW);
delayMicroseconds(500);
}
delay(2000); // Wait 2 seconds
}``` with the A4988 driver, but the stepper motor only turns in one direction for some reason. I know it's ok because I've connected it to a 3D printer a few times and it worked fine, so do you know how to fix this? Thanks.

Please edit your post to add code tags (use the post editor <code> button).
Also, post a wiring diagram and picture of your setup.

1 Like

When pasting code, make sure that the ``` characters at the start and end of your code are on separate lines, separate from the code (or any other text) — it should look like this:

Hi, I tried to do this test code with the A4988 driver:

```
// Type or paste your code here (between the two ``` lines).
```

However, the stepper motor only turns in one direction