stepper motor with DRV8825 not rotating

i bought today my first stepper motor , specifically the NEMA17 (JK42HS48-1684-08AF) and paired it with the DRV8825 stepper motor driver. I connected them accordingly to some tutorials i found. The motor though doesn’t rotate at all! It just vibrates and makes a noise when it is supposed to be enabled. I am supplying the arduino through the usb port and the driver/stepper through a 12v dc and i have tried a 9v battery too. None work. What am I doing wrong??? please help me! thanks

the code I found online:

// Define pin connections & motor’s steps per revolution
const int dirPin = 2;
const int stepPin = 5;
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
}

const int dirPin = 2;
const int stepPin = 5;

Is this on a CNC shield V3 by any chance? If so, you must enable the motors as they are disabled by default on the shield.

Make these changes:

// Define pin connections & motor's steps per revolution
const int dirPin = 2;
const int stepPin = 5;
const int enablePin = 8;

const int stepsPerRevolution = 200;

void setup()
{
  // Declare pins as Outputs
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);

  pinMode(enablePin, OUTPUT);
  digitalWrite(enablePin, LOW);
}

If that is not it, try slowing the motors even more. Like 20msec per step.

 for(int x = 0; x < stepsPerRevolution; x++)
  {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(10000);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(10000);
  }

It is not on a cnc. I tried everything you mentioned still not rotating. It does vibrate though it is apparent that it is trying to do what it is supposed to through the code.

I fixed i had to adjust the current potentiometer on the driver! Anyways thanks a lot for the help!! :slight_smile: