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;
}
}