I'm using Arduino to control a stepper motor. I need it to make one revolution and then stop. I'm new to this and haven't ran it yet. Will this do for me?

#include <Stepper.h>

const int stepsPerRevolution = 200;  

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

void setup() {

void loop() {

1 Answer 1


No, that will not do what you want. That will continuously rotate the stepper round and round and round.

The clue as to why is in the name of the function you put the myStepper.step call: "loop". That function repeatedly loops around over and over again, so your step function will be called over and over again.

There is one piece of information lacking from your thinking at the moment, and that is when do you want the stepper to rotate? If it's just once when you turn the power on then it's as simple as doing everything (including calling myStepper.step) in setup() and leaving loop() empty. If not, then you will need to add appropriate logic to only run the step function when the required conditions are met.

  • what if I want it to make just 10 revolutions and then stop.
    – Vic
    Commented May 27, 2017 at 12:51
  • 1
    The same way as for 1 revolution but with 10x the steps?
    – Majenko
    Commented May 27, 2017 at 13:07
  • Yes, though another option is to put a for loop around the step command. For a few rotations just multiplying the count works, but the count argument appears to be limited to +32767 or -32768 (on an ATmega) Commented May 27, 2017 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.