PWM for stepper motor

Hallo,
With the following code, I can change the speed of my step motor through one potentiometer.
How I can convert the “delayMicroseconds” to RPM ?
because I wanna see RPM (value) on LCD
Or there is another way to set RPM on “step pin”?

You need to do the math. For this you need to know the number of steps your motor needs for one cycle, or how large a single step is (this comes down to the same thing). After that you can calculate the RPM.

A microsecond is a millionth of a second, and there are 60 seconds in a minute. You should be able to do the math.

Just to be sure: This is the desired RPM you'll be displaying, there are circumstances that will prevent from reaching that speed. But this has nothing to do with your question.

Thank you for your answer. Do you know if there is another way that I can change the RPM directly?

No. Your motor does not care about RPM. It is constructed to step, not to rotate at a certain speed. In order to have it make steps fast enough, you need to control it correctly and the steps taken results in some RPM value reached. You can't usually immediately go from zero to the max speed, you'd need to ramp up the speed. If you want to display the RPM, you either need to calculate it, or measure it. Measuring it means additional hardware, and additional code, and so a lot more work and hassle. Depending on your application, you could create some fixed point, that can be sensed once every rotation. After that you can calculate (there it is again..) the RPM.

As you can see, more work and more stuff to learn from. But in the end it comes down to the same thing. Except, as stated before, that calculating tells you how fast it should run, and measuring tells you how fast it is running.

Thank you very much, You clarify a lot of questions I had.

Please include your code as text and not as a picture. I can't copy and paste from a picture.

In your code you have something like this

digitalWrite(pin, HIGH);
delay(sensorValue);
digitalWrite(pin, LOW);
delay(sensorValue);

With most stepper motor driver boards you don't need the first delay() as they only need a very short high pulse. So put all the "delay" in the second position. That also makes it easier to figure out the speed as you only need to consider one value.

digitalWrite(pin, HIGH);
digitalWrite(pin, LOW);
delay(sensorValue * 2);  // to give the same timing as the first code

...R

If you read the sticky post here about how to post it will explain all about posting

// code using the # button

For future visitors to this thread I would suggest its worth fixing your original posting.

I suggest looking at both the standard Stepper library and the AccelStepper library that you can download. AccelStepper handles ramping motor speed automatically.