Stepper motor controlled rpm

Hi, i am making a project to control stepper motor Nema34 with M556c driver.
I have driven motor with following code. but i want to stop motor exact after 120 turns. Because i am using void loop, so it continuously rotating. I also want to add two buttons, + & -, to give input to Arduino and stop motor after specific turns. also want to connect display to show no of turns, and reset after given turns. here is the code::::

#include <Stepper.h>
const int stepsPerRevolution = 1600;

Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  
   myStepper.setSpeed(200);
  
   Serial.begin(9600);
}

void loop ()
{
 
   Serial.println("clockwise");
   myStepper.step(stepsPerRevolution);
  }

Sounds like a school assignment?

What have you tried so far?

@red_car
Yes dear it is a school project to run some tester. I have used above mentioned code to run motor, but not able to stop it after specific turns :smirk:

The Stepper library is the wrong library for step/dir type of stepper drivers like the M556c driver. The Stepper library is written for drivers like the ULN3003 (unipolar) or the L29x drivers (bipolar). The M556c driver will not work with the Stepper library.

You should be using a library that is written for the step/dir drivers like the AccelStepper library or the MobaTools stepper library. I think MobaTools is easier to learn. There is documentation and examples to help to learn it.

Here is the manual for the M556c stepper driver. See page 3 for how to wire to a microcontroller. I would wire all of the - terminals to ground and the step, dir and enable terminals to outputs of the mystery Arduino board.

Please read the forum guidelines

What code have you actually written yourself?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.