0

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() {
 myStepper.setSpeed(60);
}
void loop() {
 myStepper.step(stepsPerRevolution);
}
jfpoilpret
9,1627 gold badges38 silver badges54 bronze badges
asked May 27, 2017 at 8:04

1 Answer 1

2

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.

answered May 27, 2017 at 10:42
3
  • what if I want it to make just 10 revolutions and then stop. Commented May 27, 2017 at 12:51
  • 1
    The same way as for 1 revolution but with 10x the steps? 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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.