Arduino Uno rev3 + A4988 driver + NEMA17 4.2 Kgcm Stepper motor (Not running)

I am using A4988 driver (A4988 driver) with Arduino Uno rev3 to drive a bipolar NEMA17 4.2 Kgcm Stepper motor (Stepper motor), currently without any load.

I am powering the stepper driver with a 12V 1.08A power supply.

I am running the following code:

// defines pins numbers
    const int stepPin = 2; 
    const int dirPin = 3; 
    const int enablePin = 4; 
    
    void setup() {
      // Sets the two pins as Outputs
      pinMode(stepPin,OUTPUT); 
      pinMode(dirPin,OUTPUT);
      pinMode(enablePin,OUTPUT);
      digitalWrite(enablePin,LOW); // Enables the motor to move in a particular direction
    }
    void loop() {
      digitalWrite(dirPin,HIGH); // Enables the motor to move in a particular direction
      delayMicroseconds(1000);
        // Makes 200 pulses for making one full cycle rotation
      for(int x = 0; x < 200; x++) {
        digitalWrite(stepPin,HIGH); 
        delayMicroseconds(200); 
        digitalWrite(stepPin,LOW); 
        delayMicroseconds(200); 
      }
      delay(1000); // One second delay
      
      digitalWrite(dirPin, LOW); //Changes the rotations direction
      delayMicroseconds(1000);
        // Makes 400 pulses for making two full cycle rotation
      for(int x = 0; x < 200; x++) {
        digitalWrite(stepPin,HIGH);
        delayMicroseconds(200);
        digitalWrite(stepPin,LOW);
        delayMicroseconds(200);
      }
      delay(1000);
    }

However, the stepper motor is just doing rhythmic vibrations and not moving most often. It is rotating only say, 1 out of 30 times, after retuning the current limiter and restarting. Also, even if it is rotating, a) the direction is not changing properly and b) it is rotating more than one revolution per for loop(probably).

What can be the mistake that I am making?

To what value did you set the current limit?
The power supply can provide at most 500 mA/winding, steady state.

Try this Simple Stepper Code. Note that there is no need to connect the enable pin (and I can't remember if it should be HIGH or LOW to make the motor work).

Try putting a large capacitor across the power supply. Your power supply can provide about 12 watts and the motor only requires about 5 watts (E&OE).

...R
Stepper Motor Basics

Thanks everyone. I have found that I made wrong connections in the motor phase coils (my silly mistake).

Now it's running properly.

@ Robin2: I had read that tutorial long ago. Thanks for that tutorial.

panini:
I made wrong connections in the motor phase coils (my silly mistake).

You are not the first and you won't be the last :slight_smile:

...R