Jittery Motion With 24 volt Nema 23

I'm trying to control a 24 volt Nema 23 stepper motor with an Arduino Nano and a stepper driver. Here are links for the motor and driver.

Motor:
https://www.amazon.com/Jinwen-Stepper-Motor-Channels-Single/dp/B019MFIOD8

Driver:

Currently I'm using a 12 volt 3 A DC power supply for the motor. I understand the motor is 24 volts, but I've read 12 volts will be ok as long as the motor can get enough current. The motor's coils are rated at 2.8 A so I believe 3 A from the power supply should be enough. Is this my first mistake?

My issue is, the motor does not turn smoothly. I'm trying to have it turn 180 degrees in either direction based on an input. Below is my code. I do not think the code is the issue since I can get this to work fine with a Nema 17.

The wiring is very simple.

For the motor driver:
ENA- ==> Not used
ENA+ ==> Not used
DIR- ==> Pin 5
DIR+ ==> 5 volts
PUL- ==> Pin 6
PUL+ ==> 5 volts

For the stepper:
Yellow ==> A+
Green ==> A-
Red ==> B+
Blue ==> B-

#include <AccelStepper.h>
AccelStepper stepper(1, 6, 5);


int stepVal;

void setup() {
  Serial.begin(9600);

  stepper.setMaxSpeed(150);
  stepper.setAcceleration(100);
  stepper.setCurrentPosition(0);

}

void loop() {

  if (Serial.available() > 0) {
    char input = Serial.read();

    if (input == '0') {
      stepVal = 1;
    } else if (input == '1') {
      stepVal = 2;
    } else if (input == '2') {
      stepVal = 3;
    }
  }

  switch (stepVal) {
    case 1:
      stepper.runToNewPosition(0);
      stepper.run();
      break;

    case 2:
      stepper.runToNewPosition(-200);
      stepper.run();
      break;

    case 3:
      stepper.runToNewPosition(0);
      stepper.run();
      delay(200);
      stepper.runToNewPosition(-200);
      stepper.run();
      delay(200);
      break;
  }
}

The voltage rating of a stepper motor is usually irrelevant. The current rating is per winding, so in principle, the motor could safely draw up to 5.6 A.

However, with 1.1 Ohm windings, the motor will draw around 22 A from a 12V supply, so to what value did you set the current limit on the driver?

If the current limit is set too high, your power supply will be overloaded and may momentarily shut down, causing the symptoms you observe.

jawzzz:
I'm trying to control a 24 volt Nema 23 stepper motor with an Arduino Nano and a stepper driver. Here are links for the motor and driver.

No such thing as a 24V stepper - its a 2.8A stepper. Current driven motors only have a current rating.

Currently I'm using a 12 volt 3 A DC power supply for the motor. I understand the motor is 24 volts, but I've read 12 volts will be ok as long as the motor can get enough current. The motor's coils are rated at 2.8 A so I believe 3 A from the power supply should be enough. Is this my first mistake?

Yes, but not the way you think. The driver will output more current to the motor winding than it
takes from the supply. Its a power converter, not a linear regulator. That supply will handle several
such motors (at low speed) in fact.

My issue is, the motor does not turn smoothly. I'm trying to have it turn 180 degrees in either direction based on an input. Below is my code. I do not think the code is the issue since I can get this to work fine with a Nema 17.

The wiring is very simple.

For the motor driver:
ENA- ==> Not used
ENA+ ==> Not used
DIR- ==> Pin 5
DIR+ ==> 5 volts
PUL- ==> Pin 6
PUL+ ==> 5 volts

For the stepper:
Yellow ==> A+
Green ==> A-
Red ==> B+
Blue ==> B-

#include <AccelStepper.h>

AccelStepper stepper(1, 6, 5);

int stepVal;

void setup() {
  Serial.begin(9600);

stepper.setMaxSpeed(150);
  stepper.setAcceleration(100);
  stepper.setCurrentPosition(0);

}

void loop() {

if (Serial.available() > 0) {
    char input = Serial.read();

if (input == '0') {
      stepVal = 1;
    } else if (input == '1') {
      stepVal = 2;
    } else if (input == '2') {
      stepVal = 3;
    }
  }

switch (stepVal) {
    case 1:
      stepper.runToNewPosition(0);
      stepper.run();
      break;

case 2:
      stepper.runToNewPosition(-200);
      stepper.run();
      break;

case 3:
      stepper.runToNewPosition(0);
      stepper.run();
      delay(200);
      stepper.runToNewPosition(-200);
      stepper.run();
      delay(200);
      break;
  }
}

Why aren't you calling runToNewPosition upon reading the command byte from serial? You just
need run() in the rest of the loop, that's all.

Anyway your problem is that you are not using move() or moveTo() calls, which implement
acceleration. You need acceleration for smooth and consistent operation. Strip out that runToPosition
stuff, its not how to do things.

@jremington I see. I have the limit set at 2.8A. I've tried to use lower limits but still get the same jittery motion. The power supply led stays lit so i do not think its failing.

@MarkT I tried your suggestions. I used a moveTo() call when I receive the input from Serial but still get the jittery motion. Also, I cannot get the motor to move backward. I'm new to using the AccelStepper library. I've used the runToNewPosition() call with a Nema 17 motor and had no issue which is why I used it with the larger motor. I tried two versions of new code. The first is the Random example from the AccelStepper library.

#include <AccelStepper.h>

AccelStepper stepper(1, 6, 5);

void setup()
{  
}

void loop()
{
  if (stepper.distanceToGo() == 0)
  {
    delay(1000);
    stepper.moveTo(rand() % 200);
    stepper.setMaxSpeed((rand() % 200) + 1);
    stepper.setAcceleration((rand() % 200) + 1);
  }
  stepper.run();
}

The second, I used the moveTo() call.

#include <AccelStepper.h>
AccelStepper stepper(1, 6, 5);

void setup() {

  Serial.begin(9600);

}

void loop() {
  stepper.run();
  if (Serial.available() > 0) {
    char input = Serial.read();

    if (input == '0') {
      stepper.moveTo(200);
      stepper.setMaxSpeed(200);
      stepper.setAcceleration(150);
    } else if (input == '1') {
      stepper.moveTo(-200);
      stepper.setMaxSpeed(200);
      stepper.setAcceleration(150);
   }
 }
}

I found I had to add the setMaxSpeed() and setAcceleration() calls in order to get something out of the stepper. Still get jittery motion and cannot get the stepper to reverse direction.

The power supply led stays lit so i do not think its failing.

The LED is unlikely to tell you anything useful. An oscilloscope (or perhaps even a multimeter) on the power supply will, though.

Hi,
Have you tried this code and connection, from the dfrobot site.

Its pretty simple and doesn't use a library.

Tom.... :slight_smile:

jawzzz:
@MarkT I tried your suggestions. I used a moveTo() call when I receive the input from Serial but still get the jittery motion. Also, I cannot get the motor to move backward. I'm new to using the AccelStepper library. I've used the runToNewPosition() call with a Nema 17 motor and had no issue which is why I used it with the larger motor. I tried two versions of new code. The first is the Random example from the AccelStepper library.

You've checked the electrical connections to the motor, and that you've identified the two windings correctly?
Both windings are intact and the same resistance?

You have it set up for microstepping of course?

@TomGeorge Thanks for the link. Turns out the wiring was incorrect. I switched the green and blue wires from the stepper motor and things are working smoothly.

@MarkT Thanks for the help with the calls. I realize now when you call newToNewPosition() you have to wait for the routine to finish before sending another command. While moveTo() allows direct control of the motor.

@jremmington The power supply seems to be working just fine now. Thanks for the tips though.

For anyone else coming across this thread, here is the working code and wiring.

From motor:
Yellow goes to A+
Blue goes to A-
Red goes to B+
Green goes to B-

From motor driver:
PUL+ and DIR+ goes to 5V on Arduino
PUL- goes to pin 7
DIR- goes to pin 6

#include <AccelStepper.h>

const int pulPin = 7;  //PUL- from stepper driver
const int dirPin = 6;  //DIR- from stepper driver

AccelStepper stepper(1, pulPin, dirPin);

void setup() {
  Serial.begin(9600);
  stepper.setCurrentPosition(0);
}

void loop() {

  stepper.run();
  if (Serial.available() > 0) {
    char input = Serial.read();

    if (input == '0') {
      stepper.moveTo(200);
      stepper.setMaxSpeed(200);
      stepper.setAcceleration(150);
    } else if (input == '1') {
      stepper.moveTo(0);
      stepper.setMaxSpeed(200);
      stepper.setAcceleration(150);
    }
  }
}