Stepper motor help. How to stop motor

Hi all.
I have a stepper motor connected to uno R3. I am running the code below. Does anyone know how to put a command in to stop the motor as it is in a continuous cycle. Many thanks if anyone does.

[code][code]#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);

// the previous reading from the analog input
int previous = 0;

void setup()
  // set the speed of the motor to 30 RPMs

void loop()
  // get the sensor value
  int val = analogRead(0);

  // move a number of steps equal to the change in the
  // sensor reading
  stepper.step(val - previous);

  // remember the previous value of the sensor
  previous = val;



if (motorRunning) {
  stepper.step(val - previous);

I'll leave you to work out how to set the 'motorRunning' variable.


does setSpeed(0) lock the motor (current on) or does it allow free spin (no current=no power=no heat)?

goodchild1: Does anyone know how to put a command in to stop the motor as it is in a continuous cycle.

If this means that you want to be able to interrupt the continuous cycle the answer is NOT to use a continuous cycle.

Just move the motor one step at a time and check for the "stop" instruction between each step.

Normally when a stepper is stationary it will draw the normal current so that it won't lose position.

If (which is recommended) you are using a specialized stepper driver that takes step and direction signals (like a Pololu DRV8825) those drivers usually have an ENABLE pin that allows for the motor to be de-powered by the Arduino. But then you risk losing position, perhaps even just one step if it does not return to the exact same place when re-powered.

...R Stepper Motor Basics Simple Stepper Code