Nema 23 Stepper Motor with tb6600 driver not moving a full step

A total beginner here , i am currently working on a project where I am trying to rotate nema 23 using tb6600 driver , arduino uno and a power supply of 24V.

// Pin Definitions
#define dirPin 2   // Direction
#define stepPin 3  // Step Pulse
#define enaPin 4   // Enable Motor
#define STPR 200   // Steps per Revolution

// Variables
int stepDelay = 600; // Delay between steps in microseconds
int stepsToMove = STPR * 2; // Number of steps to move (2 revolutions)

void setup() {
  // Set pin modes
  pinMode(enaPin, OUTPUT);
  digitalWrite(enaPin, LOW); // Enable motor
  
  pinMode(dirPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
}

void loop() {
  // Move 2 revolutions in clockwise direction
  digitalWrite(dirPin, HIGH); // Set direction to clockwise
  for (int i = 0; i < stepsToMove; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(stepDelay);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(stepDelay);
  }
  delay(1000); // Delay for 1 second
  
}

The above code is rotating the arduino by an angle of only 180* instead of 720* even though I have chosen the microstepping as a full step and current as 3Amps on the driver tb6600.

Any help would be greatly appreciated.

Going by the angles it is turning by , it seems to be running at a microstepping of 1/4th , don't know why.

Test increasing the second delay to 10 - 20 milliseconds. The stepping rate might be too high.

Are u suggesting increasing the delay between setting the pin High and Low to 10-20 milliseconds ? (The stepDelay ) ?

No. Increase the delay on the line after stepPin, LOW. That sets the delay between steps.

void loop() {
  // Move 2 revolutions in clockwise direction
  digitalWrite(dirPin, HIGH); // Set direction to clockwise
  for (int i = 0; i < stepsToMove; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(stepDelay);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(20000);
  }
  delay(1000); // Delay for 1 second
  
}

Stepper motors have inertia, they obey the laws of physics so won't be able to jump from a standstill to 833 steps a second instantly, so the motor will miss-step or stall.

You have to ramp the speed up, for instance like the AccelStepper library.

Thanks alot man.

Thanks a lot man , will give it a look.

If you find that you need acceleration to get the speed that you want, try the MobaTools libraray. It will do non-blocking acceleration. I find it easier to learn and use than AccelStepper. MobaTools is available for installation via the IDE library manager.

How are the DIP switches (microstepping) set on the stepper driver? Post a photo.

Hi man , firstly thanks a lot for your reply. I got my stepper motor to work. There is another problem that I am facing now , I want my stepper motor to run at low rpms without missing any steps , any idea how could that be done.

#include <Servo.h> //Servo library
// Pin Definitions
#define dirPin 2   // Direction
#define stepPin 3  // Step Pulse
#define enaPin 4   // Enable Motor
#define STPR 200   // Steps per Revolution

 
Servo myservo; //Servo name is myservo

// Variables
int stepDelay = 1000; // Delay between steps in microseconds
int stepsToMove = 540; // Number of steps to move (5 steps = 5*(1.8) = 9 , since gear ration 6:1 , main motor would move by 1.5* and 360/240nails=1.5 degrees)
 
 
void setup() {
Serial.begin(9600);
// myservo.attach(9); // attaches the servo signal pin on pin D6
// Set pin modes
  pinMode(enaPin, OUTPUT);
  digitalWrite(enaPin, LOW); // Enable motor
  
  pinMode(dirPin, OUTPUT);
  pinMode(stepPin, OUTPUT);

 
}
 
void loop() {


digitalWrite(dirPin, HIGH); // Set direction to clockwise
  for (int i = 0; i < stepsToMove; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(stepDelay);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(stepDelay);
  }
  delay(2000); // Delay for 1 second

}

This code works just fine , however I want to reduce the rpms and for that when I increase the stepDelay to say something like 2000 , the entire things stops working after say 1-2 rotations.

Any ideas how could it be done . Complete beginner here , any help would be appreciated.

Supplying it a current of 2.5A

Please post a datasheet of your stepper and show the dip settings of your driver.
How much current can your PSU provide?

This is never used. What do you want to do with that?


This is the dataSheet for my nema 23 stepper motor , The power supply has a rated output of 24V at 3A , and on the tb6600 , I am using the current setting corresponding to 2.8A denoted by off , off , on positions


Also i plan on controlling a servo motor from the same arduino in a sequential manner , that's why a part of it is commented in the code , currently trying to figure out how to run the stepper at low rpms

@chingam12321 ,

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

Thanks a lot man , will keep that in mind , as soon as someone mentioned this on the other topic , I soon tried closing it by making it a solution.

Does nothing? Vibrates? How do you get it working again?
At a first glance I cannot see anything wrong in your settings. For a test you could try reducing the current. Can you show a photo of your setup where all wiring can be seen?

It entirely stops , i then have to switch off the power supply to get it to work again but it stops again after 1-2 revolutions , only when I have a stepDelayTime which is pretty small does it work properly , but having a small delay time results in a high rpm which I don't want.


This is what my setup looks like except that I have my enabe pin connected to digital port 4 of the arduino.


This is my stepper motor nema 23 I am actually trying to make it rotate another wheel like structure which has gears in the ratio 6:1 as visible from the images below , I would like the stepper motor to move as slowly as possible since moving it at high speeds is causing the bigger wheel to move abruptly , the larger wheel is unable to move accurately when nema 23 is moving at high rpms.


Any ideas/lead and what should I try doing ?

for (int i = 0; i < stepsToMove; i++) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(stepDelay);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(3000);
  }

I tried to increase the time between the start of the next signal and current signal as delayMicroseconds(3000); but this is making the motor make loud noises and is also making it stop although being able to move it at speeds it is running at with this code is something I would have liked.

Did you try reducing the current?

Usually a stepper can be moved as slowly as you like. To tell the truth, in the moment I don't have any idea what could be your problem... :thinking:
Maybe someone else has an idea.