Jump to content
Sign in to follow this  

Library stepper.h

Recommended Posts

Hey guys,

I´m using a stepper motor in half step mode. In half step my motor has 400 steps. I wanna make it move one step at time with short pauses between each movement (2,5s). Also, after it completes the 400 steps it should start moving on the opposite direction. I´m using the library stepper.h but I´m having some doubts about it, this is my code at the moment:


#include <Stepper.h>

int x = 1; // step
int z = 0;
int w = -1;

const int stepsPerRevolution = 400; // number of steps in half step mode
Stepper myStepper(stepsPerRevolution, 8,9,10,11);

void setup() {
  myStepper.setSpeed(60); // 60 rpm

void loop() {
    delay(2500); // pause between each step 2,5s
    if(x==stepsPerRevolution) z=1; // when 400 steps then move in the opposite direction
      if(w==-stepsPerRevolution) z=0 && x=1;

I don´t know if it is configure correctly. Should I use stepsPerRevolution = 200 (number of steps in full step mode) with x increasing in 0.5 by time? Also, can I use myStepper.step that way?  Thank you!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this