Need help in stepper motor

Need help to stop the stepper motor from stepping continously. How can i alter this program to make it 12 steps. I am using 7.5 degree stepper motor which is 48 steps per revolutio.

#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() {
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one step:
  myStepper.step(1);
  Serial.print("steps:" );
  Serial.println(stepCount);
  stepCount++;
  delay(500);
}

How can i alter this program to make it 12 steps.

Several ways. One would be to set a global variable to zero before the loop() function then, before stepping the motor check that the variable is less than 12. After stepping the motor increment the variable. Once the value of the variable reaches 12 the motor will not step again.

Is the motor ever going to be started again ? If not put the motor move commands in a for loop in the setup() function and nothing in loop()

I suspect that either way you will have further questions so please feel free to ask them.

#include <Stepper.h>

const int stepsPerRevolution = 48; // 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() {
// initialize the serial port:
Serial.begin(9600);

for(int i = 0; i <= 12; i++){

myStepper.step(1);
Serial.print(“steps:” );
Serial.println(stepCount);
stepCount++;
delay(500);
}
}

void loop() {
// step one step:

}

this will make the motor move 12 steps once after booting the program( Or suppose to I dont have a stepper to test it out)

Thanks Mike and UKHE..that's great help it worked... :)

I'd encourage you to look at the AccelStepper library too...