Cut Power to Stepper Motor When Not in Use

When you first instantiate stepper (Stepper myStepperAz(stepsPerRevolution, Az1, Az3, Az2, Az4);), all outputs are zero.
After the stepper is used, one or more outputs are On.
How do you turn off the drive(all “zero”) with #include <Stepper.h>

The stepper driver has to have a "drive off" input (usually called ENABLE), which can be activated or deactivated using an MCU I/O pin.

I don't think the Arduino stepper library supports that function.

Note that the stepper won't hold position with the coils turned off.

Why do You need that?
Just stop stepping, pulsing to stop.

  • Write a sketch that doesn’t use a library, i.e. you manage stepping directly from your code.
    Write your zeros to the driver to turn off the coil current as needed.

Stepper.h doesn't do anything in the background, so you could just set the pins to LOW, and they will stay LOW until you call myStepperAz.step(...) again.

void driveAllLow(uint8_t p1, uint8_t p2, uint8_t p3, uint8_t p4,  ){
   digitalWrite(p1,LOW);
   digitalWrite(p2,LOW);
   digitalWrite(p3,LOW);
   digitalWrite(p4,LOW);
}

I came to the same conclusion after reviewing the source code for stepper, it leaves the outputs in the last step state.
It appear it will be easy to modify a clone copy of the source code to test if the number of steps requested is zero, then put all outputs to low. This will make powering down simple.
In my project, the stepper motor is geared down and the load is balanced which will only require a wait till the system stabilizes before powering down the steppers.

Cloned stepper source code, changed its name to StepperExt and changed all instances of "Stepper" to "StepperExt" in all code files. Note, only changed capital "Stepper", not lower case "stepper".
Modified the StepperExt.cpp as follows

/*
 * Moves the motor steps_to_move steps.  If the number is negative,
 * the motor moves in the reverse direction.
 */
void StepperExt::step(int steps_to_move)
{
  int steps_left = abs(steps_to_move);  // how many steps to take

  if(steps_left == 0)
  {
    digitalWrite(motor_pin_1, LOW);
    digitalWrite(motor_pin_2, LOW);
    digitalWrite(motor_pin_3, LOW);
    digitalWrite(motor_pin_4, LOW);

  }
  else
  {

         Excising Code

}

Copied the "StepperExt" folder into "...\Documents\Arduino\libraries"

In my Arduino script, I changed all instances of "Stepper" to "StepperExt" . Note, only changed capital "Stepper", not lower case "stepper".

Uploaded to my hardware and tested through a web browser that the stepper motor moved as requested. Verified that the stepper motor was power down after sending a zero step request.