Need help with controlling a stepper motor

#include <Stepper.h>

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

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

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, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
}
}

i am new in coading.i want to use this code in my class project.if my motor maximum speed 103rpm .can i write this line
int motorSpeed = map(sensorReading, 0, 1023, 0, 103);it will be correct ?
and if i write
myStepper.step(stepsPerRevolution / 103); it will be correct?

and what does this line myStepper.step(stepsPerRevolution / 100); means

i get maximum rpm using this
http://www.daycounter.com/Calculators/Stepper-Motor-Calculator.phtml

plz plz plz help me .

i want to controll my stepper motor speed with potentio meter .i made a calculation which gives me 103 maximum rpm i want to use this following code

#include <Stepper.h>

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

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

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, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
}
}

my question is in this line
int motorSpeed = map(sensorReading, 0, 1023, 0, 100); i need replace 100 by 103

myStepper.step(stepsPerRevolution / 100); this line also replace 100 by 103 ?

myStepper.step(stepsPerRevolution / 100); what does this line mean ?

plz kindly help me

image_uiu12:
my question is in this line
int motorSpeed = map(sensorReading, 0, 1023, 0, 100); i need replace 100 by 103

Is the 100 in that line RPM like your 103 is? Is RPM what setSpeed takes? Why don't you look at the documentation for the stepper library you're using and see?

image_uiu12:
myStepper.step(stepsPerRevolution / 100); this line also replace 100 by 103 ?

Is that 100 an RPM? What number do you feed to step? Again, why don't you check the documentation and see? It's explained really really well on that page. Here's a link in case you don't know how to google. Arduino - Stepper

image_uiu12:
myStepper.step(stepsPerRevolution / 100); what does this line mean ?

What does that line mean? Did you look at the comment above it? Again, a quick look at the step function in the stepper library docs would answer this. I am of course assuming that you do understand that the /100 part means divided by one hundred.

sorry sir actually i am totally new in coading .i try to understand this but didnt get it.i just want to know in this code this 100 means my maximum motor rpm or not ? and the last line why i need to divide stepperrevolution /100.what will be outcome here.plz really i try learn it

I'd be glad to help!

  • 'Plz' is spelled 'please'. 'Coading' is spelled 'coding'. 'i' is usually uppercase. Sentences start with an uppercase letter, and have a space after the full-stop.
  • Use code tags when posting code to this forum.
  • Read the sticky post http://forum.arduino.cc/index.php?topic=97455.0 , paying close attention to item #6.
  • Read the course notes for your class. Unless your teacher is radically incompetent, there will be some clue in there as to what that line that puzzles you means.
  • Google "C++ tutorial" and work through the first few chapters of any of the free, online C++ tutorials on the web. You can stop when you start reading about classes.

The last three of those bis of advice boil down to the same thing: you are doing this course, you have to do the reading, you have to make the intellectual effort to understand the subject. Someone else can't understand it for you.

yes sir i am looking this
Arduino - Stepper and try to figure out this from
Tom Igoe's notes on steppers.

Stepper: setSpeed(rpms)

Description

Sets the motor speed in rotations per minute (RPMs). This function doesn't make the motor turn, just sets the speed at which it will when you call step().

So you read this and seriously don't understand what the number for the setSpeed function means?

Stepper: step(steps)

Description

Turns the motor a specific number of steps, at a speed determined by the most recent call to setSpeed(). This function is blocking; that is, it will wait until the motor has finished moving to pass control to the next line in your sketch. For example, if you set the speed to, say, 1 RPM and called step(100) on a 100-step motor, this function would take a full minute to run. For better control, keep the speed high and only go a few steps with each call to step().

You seriously read this and don't understand what the number in the step call tells it to do? The comment above that line explains it pretty damned well, but even without that, the quote above from the documentation makes it very very clear what that number means.

If I were going to try to explain it to you it would look a lot like what I just quoted, so if you don't get it there you wouldn't get it if I repeated that. You're going to have to put your thinking cap on. This doesn't take programming skill. Just the ability to read.

Not to mention this is a cross-post. On the same board no less.

Cross posted here. Please answer there.
http://forum.arduino.cc/index.php?topic=456320.0

sir

Stepper: setSpeed(rpms)

int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
here i set this rpm when i tuning my potentio meter.and here its maping so i need to put this 103 right ?

myStepper.setSpeed(motorSpeed);
this line would be like
myStepper.setSpeed(103);
is it ok ?

image_uiu12:
myStepper.setSpeed(motorSpeed);
this line would be like
myStepper.setSpeed(103);
is it ok ?

If you just put 103 there, then the whole reading of the pot and the map call are kind of useless aren't they. If you want to control the speed with the pot, then you probably want to use the speed you calculated in that variable.

am gonna to be mad.then in this code where i use my maxmimum rpm 103.if i dont use it then how this code will be understand which value will be maximum rpm

Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

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

void setup() {
stepper.setSpeed(103);
}

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, 100);

now its ok ?

I thought you wanted to control the speed with the pot. If you just want to set the speed at the maximum all the time then what's the rest of that code for?

ok sir but my speed limitation is 0-103.if i dont put this 103 value in this code how can this will understand wich will be my maximum range.i just want to know in this whole code where i put this value

Does setSpeed set the maximum speed? Or does it set the speed at which the motor will run? (see reply #4)

Do you know what this line does?

int motorSpeed = map(sensorReading, 0, 1023, 0, 100);

If not, it’s time to head back to the reference and read up on map.

const int stepsPerRevolution = 200
this line dedicated for steps
Stepper myStepper(stepsPerRevolution, 7,8)
this line dedicated for pin number
int stepCount = 0;
this line starting count

int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
this is only one line which is left with the digit
int motorSpeed = map(sensorReading, 0, 1023, 0, 103);

now its ok ?

image_uiu12:
now its ok ?

Answer my questions. Don't just post another guess and ask if it is OK. I'm not going to play that game with you. If you want to learn, you will if you try to answer my question. If you just want to know when you've guessed right then load the code onto your Arduino and see what heppens.

sir
map(value, fromLow, fromHigh, toLow, toHigh)

int sensorReading = analogRead(A0);
// map it to a range from 0 to 100:
int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
value-sensorreading
0-0
1023-103

because my high value is 103
i have no other value

int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
// set the motor speed:
if (motorSpeed > 0) {
myStepper.setSpeed(motorSpeed);
setSpeed will be motor speed which is controll by potentiometer

please replay me