Is my stepper motor, driver, or arduino bad?

I'm trying to control a NEMA 17 stepper motor with my UNO, and I am using an A4988 driver to do so. The motor will step about half as much as I would expect to when it kinda works with one motor that turns at 400 steps/rev, and it will also step the wrong direction towards the end of the loop. With another motor I have that turns at 200 steps/rev, it only takes a few steps initially before dying. With both motors, the amount of noise will decrease the longer the UNO is plugged in until they both go silent after about 20 seconds. There's a decrease in torque associated with this decrease in noise.

I'm currently pulling 12V from the Vin pin to power the motor, and there's a 68 micro Farad capacitor between the 12V input and ground. I also tried powering it with a 240W 24V power supply I have. I've tried two different drivers and widely varied the delay constant I'm using for steps only to get similar results.

Below is my arduino code:

const int stepPin = 2; 
const int dirPin = 5; 
const int del = 500;
 
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

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

  delay(1000); // One second delay
  
  digitalWrite(dirPin,LOW); //Changes the rotations direction

  for(int x = 0; x < 400; x++) {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(del);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(del);
  }
  delay(1000);
}

Original motor specs: http://www.wantmotor.com/product/42byghm.html
A4988 specs: https://www.pololu.com/product/1182/specs

Since changing out the drivers and motors didn't seem to make a huge difference, I'm afraid my board may be bad in some way. Has anyone else had similar issues? Does anyone have any advice?

Try it with del = 10. You may not even need a delay between DigitalWrites. You prob'ly need a delay about 20mS between steps for testing, like:

for(int x = 0; x < 400; x++) {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(del);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(del);
    delay(20);
  }

Have you tried the AccelStepper library? I like it.
BTW make sure the current limit is set correctly to suit your motor, very important!

johndavis726:
I'm currently pulling 12V from the Vin pin to power the motor,

DO NOT power a motor from an Arduino board. And stepper motors require very large spikes of current to work properly.

There are several motors on that list - which one is yours?

Have you the current limit correctly set on your A4988?

Try your code with a much slower step rate - say 10 steps per second or fewer.

I suggest as a general measure you change your code to this (assuming the variable del2 is twice what del would be).

   digitalWrite(stepPin,HIGH);
    delayMicroseconds(10);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(del2);

It makes life much easier if all the "speed" is in one place.

If that does not help then please make a pencil drawing showing how everything is connected and post a photo of the drawing. Please note that Fritzing diagram and photos of your hardware are usually useless for showing wiring connections clearly.

...R
Stepper Motor Basics
Simple Stepper Code

  1. Have you set the A4988 current correctly for your motor (s)? You can set the current a little lower than nominal to reduce heat issues.

  2. The 24V supply is the one to use. Higher voltage will give faster max speed.

  3. 68uF is nothing for a motor. 4700uF might make a difference though.

  4. A4988's probably need active cooling with a fan if using higher range of current (1A and above),
    or they will thermally cut out

  5. You need to ramp the step rate, motors cannot respond to an instantaneous change in step rate,
    so use the AccelStepper library and experiment to find the max step rate and max acceleration for
    your motor/load combination. Use microstepping(*) if the motor has no load or you'll get bad resonance
    issues (you can get bad resonance with a load when full-stepping, but you certainly will with no load).

(*) try x8 or x16 in the first instance

I plugged in the 24V supply and couldn't get the motor to even turn. I double checked all of my connections with no luck. I tried using the Vin pin again afterwards, and I was able to at least get some noise of of the motor but no rotation.

I had set the potentiometer on the driver to the correct voltage in earlier testing and remeasured it again to make sure it was at a good value. I changed my code to decrease the delay in between the high and low outputs from the arduino and included an LED blink to verify that it was running.

The specific motor I am using is model 42BYGHM809 from the link I previously posted. I'll post a wiring diagram in a little bit.

const int stepPin = 2; 
const int dirPin = 5; 
const int del = 10;
int led = 13;
 
void setup() {
  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT); 
  pinMode(dirPin,OUTPUT);
  pinMode(led, 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 < 400; x++) {
    digitalWrite(stepPin,HIGH);
    digitalWrite(led, HIGH);
    delayMicroseconds(del); 
    digitalWrite(stepPin,LOW);
    delayMicroseconds(2*del);
    delay(1000);
    digitalWrite(led, LOW);
    delay(1000);
  }
  delay(1000); // One second delay
  
  digitalWrite(dirPin,LOW); //Changes the rotations direction
  for(int x = 0; x < 400; x++) {
    digitalWrite(stepPin,HIGH);
    digitalWrite(led, HIGH);
    delayMicroseconds(del); 
    digitalWrite(stepPin,LOW);
    delayMicroseconds(2*del);
    delay(1000);
    digitalWrite(led, LOW);
    delay(1000);
  }
  delay(1000);
}

The Pololu A4988 web page has a good wiring diagram.

I think you misunderstood my code suggestion. You cannot expect the motor to move with a step interval as short as 20 microseconds.

I was trying to differentiate between the necessary duration of the pulse (10 µsecs) and the step interval which bears no relationship to the pulse duration. Look at my code examples.

Start with a step interval of 200 millisecs. If that works, then experiment with shorter intervals to see what max can be achieved.

For high maximum speeds you may need to accelerate from stationary - but leave that for later.

...R

I finally got the motor working after I connected the sleep and reset pins as some tutorials suggest. I didn't do anything with them in the past since I thought they were unnecessary.

Read the datasheet, you should never assume anything - read the docs, double check your connections, only
then apply power. Over eagerness to power something up will lead to expensive mistakes.