Arduino Uno + MSD-11-EM stepdriver + NEMA 17 I am working on Arduino code for stepper motor rotations control. I want to rotate a stepper for only 4 rotations.

The code is working fine but that will run only once as I have put that in setup().

I want to know if there will be any reverse current flowing in the circuit that would damage the Arduino or stepper. What if I want to run the stepper in the loop()? I tried but that will force the stepper to run continuously.

How can I run stepper for only 4 rotations and then stop?

I want to run it in loop().



Below is the code I am using:

#include &lt;Stepper.h&gt;

const int stepsPerRevolution = 2100;  
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(110);
  // initialize the serial port:
  Serial.begin(9600);
  for(int i=0;i&lt;25;i++) {
    Serial.println("Anti-clockwise");
    myStepper.step(stepsPerRevolution);
    delay(50);
  }
}
In loop add flag to change after what you desired plus a statement to check the flag.
Code below (assuming what is in for() being enough to do 4 revolutions):  

#include &lt;Stepper.h&gt;

const int stepsPerRevolution = 2100;  
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
bool flag = true;

void setup() {
 // set the speed at 60 rpm:
 myStepper.setSpeed(110);
 // initialize the serial port:
 Serial.begin(9600);     
}  

void loop {  
 if (flag) {  
   for(int i=0;i&lt;25;i++) {
     Serial.println("Anti-clockwise");
     myStepper.step(stepsPerRevolution);
     delay(50);
   }
   flag = false;
 }
}


This solution gives you a flexibility to add a pushbutton to change flag and do another 4 revolutions.