I wanted to turn off a stepper motor without having to do so with a hardware solution and it was very simple to do, but only if you know how. Finding the method was a little buried, so I'm going to post a link here just so other people can find the information. As clarification for newbies like myself, it's the bit about digitalWrite ((pin) LOW).
Most people who have asked were simply grilled about their reason for wanting to do such a thing and then told to use something else (not a stepper). For those of us who have reasons and would simply prefer an answer instead of a life lesson which does not apply, here it is, and thanks go out to the school and teacher for supplying the info:
The site I found:
http://www.me.umn.edu/courses/me2011/arduino/technotes/stepper/arduinoStepper.html
Site's Contents:
Arduino Code for Controlling a Stepper Motor
The Arduino programming environment comes with a function library for controlling a stepper motor.
To use the library, in the Arduino Editor from the top menu bar: Sketch > Import Library > Stepper.
Copy the example code below into an Arduino program.
Arduino code example
Example Code Notes
/*---------------------------------------------
Demo that turns stepper 360 deg in one dir then the other then a wave.
All coils turned off at end to avoid battery drain.
----------------------------------------------*/
#include <Stepper.h> //include the function library
#define STEPS 48 // 48 steps per rev
Stepper stepper(STEPS, 5, 7, 6, 4); //create the stepper
void setup()
{
int i;
stepper.setSpeed(30); //set speed to 30 rpm
delay(1000); //pause for effect
stepper.step(48); //move 360 deg one direction
delay(1000); //pause for effect
stepper.step(-48); //move 360 deg in the other direction
delay(1000); //pause
stepper.setSpeed(60); //speed up
for (i=0;i<5;i++) {
stepper.step(10); //wave the flag
stepper.step(-10);
}
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
void loop()
{}
The example code assumes that the stepper is being controlled by Arduino pins 4, 5, 6 and 7, that control motor coil 1, 2, 3 and 4 (in that order) but you can use any set of four pins.
The "#define STEPS 96" line defines the number of steps per rev. A 3.75 deg motor has 96 steps/rev while a 7.2 deg motor has 48 steps/rev.
The "Stepper stepper(STEPS, 5, 7, 6, 4)" line is where you enter the four pins used to control the stepper. The order the pins are entered (coil 2, coil 4, coil 3, coil 1) is non-obvious, but can be understood if you want to dive deep into how the Arduino stepper library works.
The "stepper.setSpeed(x)" command sets the motor speed to x rpm.
The "stepper.step(x)" command turns the motor x steps at the speed last set in the stepper.setSpeed() command. The motor turns one direction for postive x and the reverse direction for negative x.
When the example program finishes, two of the coils will remain on, so all coils are turned off to prevent your battery from draining.
If you motor shudders but does not move, it is likely an error in the ordering of the coils.
Arduino Stepper Resources
Arduino tutorial for programming stepper motors:
Arduino stepper motor software library:
Example showing how to control a stepper with a potentiometer: