stepper motors not working correctly with a4988

i have arduino uno, A4988 Driver and stepper motor model:17HS4401S. i'm trying get it to spin, i connected all as shown in photo1

and here is the code i'm using:

 const int stepPin = 2; //X.STEP
  const int dirPin = 5; // X.DIR
 
 void setup() {
 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 one full cycle rotation
 for(int x = 0; x < 200; x++) {
 digitalWrite(stepPin,HIGH); 
 delayMicroseconds(500); 
 digitalWrite(stepPin,LOW); 
 delayMicroseconds(500); 
 }
 delay(3000);
 }

the problem is that the motor just starts jumping and glitching back and forward (strange movement)

where could the problem be?

Start with a very much slower speed - at least 10 times slower.

Have a look at this Simple Stepper Code

If you need more help please post a link to the datasheet for your stepper motor and tell us what motor power supply you are using (volts and amps).

...R
Stepper Motor Basics

And please make your image visible in your Post - See this Simple Image Posting Guide

i looked at your code then i loaded it on arduino and again weird noise, but without cables connected to A4988 driver stepPIN and dirPIN stepper motor also makes wierd noise.

i'm using 12V and 1.5A power supply

and heres datasheet datasheet url

That is a 1.7 amp motor and an A4988 is going to struggle with anything more than about 1.4 amps - a DRV8825 should be suitable. How have you adjusted the current limit on the A4988? The motor may provide enough torque for your project with the current limit set at 1.4 amps

Be VERY CAREFUL never to disconnect the wires between the motor and the stepper driver while the driver is powered up. The driver will be instantly destroyed.

...R

how to correctly adjust current limit?

AND yeah i disconnect motor from driver and plug it back i saw sparkles, how can i know if it's destroyed?

(i have more than 1 driver)

l_nem:
how to correctly adjust current limit?

The Pololu A4988 web page has all the details. However you need to check whether the current-sense resistor on your board is the same as theirs.

AND yeah i disconnect motor from driver and plug it back i saw sparkles, how can i know if it's destroyed?

You have to ask?

The simplest way to test is by trying another driver.

...R

l_nem:
how to correctly adjust current limit?

AND yeah i disconnect motor from driver and plug it back i saw sparkles, how can i know if it's destroyed?

You can assume its junk now, they fry very readily if you do this.

i tryed with new a4988 and motor just doesent want to spin it makes wierd noice... with first driver that i destroyed shows 12v on evry output and that's the only way i can spin the motor but it goes very fast if i change the order of wires it spins in other way but on new drivers it just doesnt spins.. i have 5 more motors, 3 of them not even tested yet

i tryed with this code

// testing a stepper motor with a Pololu A4988 driver board or equivalent

// this version uses millis() to manage timing rather than delay()
// and the movement is determined by a pair of momentary push switches
// press one and it turns CW, press the other and it turns CCW

byte directionPin = 9;
byte stepPin = 8;

byte buttonCWpin = 10;
byte buttonCCWpin = 11;

boolean buttonCWpressed = false;
boolean buttonCCWpressed = false;

byte ledPin = 13;

unsigned long curMillis;
unsigned long prevStepMillis = 0;
unsigned long millisBetweenSteps = 25; // milliseconds

void setup() {

     Serial.begin(9600);
     Serial.println("Starting Stepper Demo with millis()");

     pinMode(directionPin, OUTPUT);
     pinMode(stepPin, OUTPUT);
     pinMode(ledPin, OUTPUT);
     
     pinMode(buttonCWpin, INPUT_PULLUP);
     pinMode(buttonCCWpin, INPUT_PULLUP);
     
}

void loop() {
   
    curMillis = millis();
    readButtons();
    actOnButtons();
   
}

void readButtons() {
   
    buttonCCWpressed = false;
    buttonCWpressed = false;
   
    if (digitalRead(buttonCWpin) == LOW) {
        buttonCWpressed = true;
    }
    if (digitalRead(buttonCCWpin) == LOW) {
        buttonCCWpressed = true;
    }
}

void actOnButtons() {
    if (buttonCWpressed == true) {
        digitalWrite(directionPin, LOW);
        singleStep();
    }
    if (buttonCCWpressed == true) {
        digitalWrite(directionPin, HIGH);
        singleStep();
    }
}

void singleStep() {
    if (curMillis - prevStepMillis >= millisBetweenSteps) {
            // next 2 lines changed 28 Nov 2018
        //prevStepMillis += millisBetweenSteps;
        prevStepMillis = curMillis;
        digitalWrite(stepPin, HIGH);
        digitalWrite(stepPin, LOW);
    }
}

and this one

// Defines pins numbers
const int stepPin = 9;
const int dirPin = 8; 

int customDelay,customDelayMapped; // Defines variables
 
void setup() {
  // Sets the two pins as Outputs
   Serial.begin(9600); 
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
 
  digitalWrite(dirPin,HIGH); //Enables the motor to move in a particular direction
}
void loop() {
  int sensorValue = analogRead(A5);

  Serial.println(sensorValue);
  
  customDelayMapped = speedUp(); // Gets custom delay values from the custom speedUp function
  // Makes pules with custom delay, depending on the Potentiometer, from which the speed of the motor depends
  digitalWrite(stepPin, HIGH);
  delayMicroseconds(customDelayMapped);
  digitalWrite(stepPin, LOW);
  delayMicroseconds(customDelayMapped);
}
// Function for reading the Potentiometer
int speedUp() {
  int customDelay = analogRead(A5); // Reads the potentiometer
  int newCustom = map(customDelay, 0, 1023, 300,4000); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
  return newCustom;  
}

what can i do to make them spin?

l_nem:
what can i do to make them spin?

The first thing is to stop switching between programs. Stick with a single program until you have got things working. I know that the programs in my Simple Stepper Code work and I am familiar with them. I suggest you stick with the first of my programs.

Are you sure you have the motor correctly connected to the A4988 and have the current limit set correctly? All of this is detailed on the Pololu A4988 web page.

I cannot visualise what this means

with first driver that i destroyed shows 12v on evry output and that's the only way i can spin the motor but it goes very

It's not even clear if you have a program running, or what the program is.

If you have an A4988 driver that you have never used (so you can be sure you have not damaged it) then I suggest you set that up strictly in accordance with the advice on the Pololu website and try that with my program. It is much less likely that the motors have been damaged.

...R