I use Arduino and I'm beginner. I use the code below, but I don't understand what stepper.step(num) and STEPS in Stepper stepper(STEPS, 2,3,4,5) are, and I want to use stepper for specific degree and I don't know what I can do. for example if I want to use stepper for 40 degree what are STEP and num?

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 2,3,4,5);

// the previous reading from the analog input
int previous = 0;

void setup()
  // set the speed of the motor to 30 RPMs

void loop()
  // get the sensor value
  //int val = analogRead(0);

  // move a number of steps equal to the change in the
  // sensor reading
  //stepper.step(val - previous);
 // stepper.step(-5);

  // remember the previous value of the sensor
  //previous = val;

-----------------------------------------EDIT #2----------------------------- my stepper is the first one in this link: https://grahamwideman.wikispaces.com/file/view/28byj48_models_table.jpg/538898220/604x265/28byj48_models_table.jpg ( I think! ) and I don't know what it means? ------------------------------------------EDIT #3---------------------------- Thank you very much, I saw the link.

Step Angle (8-Step sequence: Internal Motor alone): 5.625° (64 steps per revolution)

and I run this code for 45deg :

#include <Stepper.h>

#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64  //2048  
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 2, 3, 4, 5);

int  Steps2Take;

void setup()   


void loop()   /*----( LOOP: RUNS CONSTANTLY )----*/

  Steps2Take  =  STEPS_PER_OUTPUT_REVOLUTION / 8.11;          

because I understand each turn has 2048 steps, for example if I want to have 1/2 turn, I have to have num=1024 ( 2048/2). ok, So, for 45deg, it's 1/8 turn so I have to set num=2048/8. but for example for 33 deg what should I do? I thought num= 33*5.61 so for 45deg I use num=45*5.61 you know we have a lot of floating point and I'm not sure we do it correct. right? I'm a little confused.

1 Answer 1


stepper.step(num)is used to rotate your motor 'num'-step. i.e. num=25, then calling stepper.step will cause your motor do 25-step.

STEPS is number of steps per revolution for your motor. It will be depending on the motor you used. For more information, you can check here.

You have to check for your motor stepper resolution. Most common motor stepper has 200 steps per revolution, which means 1 step is 360/200 = 1.8 degree. If you try Stepper.step(1), your motor will rotate 1.8 degree.

So in your case, if you already found out the resolution of your motor stepper, just do a simple conversion task:

const float resolution  = xx.xx; // put your step resolution here
int step_degree(float desired_degree){
    return (desired_degree/resolution);}

This can be use by calling

stepper.step(step_degree(40)); //rotate 40 degree.

You can check this link, since it (perhaps) using same motor stepper (24BYJ48)

Based on 24BYJ48 datasheet, it has 5.625 degree resolution / 64 steps per revolution.

  • 1
    Do you mean 1 step is 360/200 = 1.8deg?
    – Mark Smith
    Nov 16, 2016 at 9:12
  • I sent a link, the firs one is my stepper. but I don't know what they are. Would you please tell me what is my resolution?
    – Fazeleh
    Nov 17, 2016 at 7:55
  • I set 200 and I expect with num=1 I have to see 1.8 degree but it wasn't.
    – Fazeleh
    Nov 17, 2016 at 7:56
  • 1
    Instead of put in comment, it will be better if you put edit your question so others can quickly notice it :)
    – duck
    Nov 17, 2016 at 8:02

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.