a code correction

#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor



Stepper myStepper(stepsPerRevolution, 7,8);

int stepCount = 0;  // number of steps the motor has taken

void setup() {
  // nothing to do inside the setup
}

void loop() {
  // read the sensor value:
  int sensorReading = analogRead(A0);
  // map it to a range from 0 to 100:
  int motorSpeed = map(sensorReading, 0, 1023, 0, 103);
  // set the motor speed:
  if (motorSpeed > 0) {
    myStepper.setSpeed(motorSpeed);
    
    myStepper.step(stepsPerRevolution);
  }
} ...

i just want to 200steps/rev whatever my speed .speed is controll by the potentiometer.anybody call tell me my code is right or not ?

Part of writing code is proving things out for yourself. Write code, test what you wrote, write some more, test it . . .

"tell me my code right or not?" You can tell us by testing it.

.

image_uiu12: i just want to 200steps/rev whatever my speed .speed is controll by the potentiometer.anybody call tell me my code is right or not ?

Whether or not it takes 200 steps to make a revolution is a property of the motor, not the code. You have to tell the Stepper library how many steps per revolution for the motor. But there's nothing you can do in the code to change the number of steps it takes a stepper to make one revolution.

thanks delta

const int stepsPerRevolution = 200;
myStepper.step(stepsPerRevolution);
except this 2 line
i need to add any new line to tell the stepper motor 200steps/rev

LarryD: Part of writing code is proving things out for yourself. Write code, test what you wrote, write some more, test it . . .

"tell me my code right or not?" You can tell us by testing it.

. [/sir am not confident about this code .i really try to understand.pardon me for language ]

I believe there are some examples that come with the library. Have you tried to understand them?

https://www.arduino.cc/en/Reference/Stepper

.

image_uiu12: thanks delta

const int stepsPerRevolution = 200; myStepper.step(stepsPerRevolution); except this 2 line i need to add any new line to tell the stepper motor 200steps/rev

You don't need to tell the stepper motor anything. That's what I'm trying to tell you. If you want to do something with that number in your code, like be able to tell the stepper to turn one full revolution then fine. But you don't have to tell the stepper squat. If it's a 200 step per rev motor then it's a 200 step per rev motor no matter what you do in your code.

Thank you sir Delta for your time and support .is it possible with this code for microstepping?

Frankly, I think that if you’ve gone this far in the three threads I’ve seen so far from you and still don’t get any little piece of it then it’s probably hopeless. Maybe you should find a different idea for your bachelors project. If you can’t get through this then you really don’t have much of a chance of finishing a 3D printer. It’s going to get a LOT harder doing that project. You’re going to have to be at least smart enough to be able to write and test your own code. If you can’t even load it up on your Arduino and you need us to tell you if it will work or not then this is way way over your head. Not trying to be mean. Just being honest.

Delta sir actually am became hopeless with arduino code.i got a new value for for the maximum rpm.its about 667rev/min.when i put this value after 400 rev/min the motor became noisy and vaibrate .the rev/min i can see from the serial ploter and there is also another problem because i used block function .but when i use maximum 200 or 100 rmp in maping that time the motor run smoothly .