# How to find the RPM of the stepper motor

Hi I am using the following code to control a stepper motor. In line 4, I used a “_delay” variable to store the delay between the HIGH and LOW values. If this delay is less, stepper moves faster and vice versa. But my question is that how do I know that how fast (in RPM) is stepper moving for a particular amount of delay? Please help me out !!!

``````# define EN 8 // stepper motor enable , active low
# define X_DIR 3 // stepper motor direction control
# define X_STP 2 // stepper control
int _delay = 3;

void step (boolean dir, byte dirPin, byte stepperPin, int steps)
{
digitalWrite (dirPin, dir);
delay (50);

for (int i = 0; i <steps; i++)
{
digitalWrite (stepperPin, HIGH);
delay (_delay);
digitalWrite (stepperPin, LOW);
delay (_delay);
}
}

void setup () {
pinMode (X_DIR, OUTPUT); pinMode (X_STP, OUTPUT);
pinMode (EN, OUTPUT);
digitalWrite (EN, LOW);
}

void loop () {
step (false, X_DIR, X_STP, 200);
delay (1000);
step (true, X_DIR, X_STP, 200);
delay (1000);
}
``````

Don't use delay, use millis instead. That way you know for sure when things happen. And you can calculate the RPM from that. Know how big one step is.

The second example in this Simple Stepper Code uses millis() and micros() for the timing.

In both examples I hope the variable names I have chosen will make the timing (and hence speed) easy to understand.

The speed of a stepper motor is determined by the interval between steps. If you know that and the number of steps per revolution you can calculate the speed.

For example with 100 millisecs between steps and 200 steps per revolution it would take 20,000 milisecs (or 20 seconds) to do one revolution.

To follow on from what Robin wrote. Your stepper will never have an RPM if it never makes a complete rotation. Think about that. The common rate of movement for a stepper motor is: steps per minute or steps per second.

Paul