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 <Stepper.h>
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<25;i++) {
Serial.println("Anti-clockwise");
myStepper.step(stepsPerRevolution);
delay(50);
}
}