1 /* YourDuino.com Example Software Sketch
2 Small Stepper Motor and Driver V1.3 11/30/2013
3 http://arduino-direct.com/sunshop/index.php?l=product_detail&p=126
4 Shows 4-step sequence, Then 1/2 turn and back different speeds
7 /*-----( Import needed libraries )-----*/
10 /*-----( Declare Constants, Pin Numbers )-----*/
11 //---( Number of steps per revolution of INTERNAL motor in 4-step mode )---
12 #define STEPS_PER_MOTOR_REVOLUTION 32
14 //---( Steps per OUTPUT SHAFT of gear reduction )---
15 #define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 //2048
17 /*-----( Declare objects )-----*/
18 // create an instance of the stepper class, specifying
19 // the number of steps of the motor and the pins it's
22 //The pin connections need to be 4 pins connected
23 // to Motor Driver In1, In2, In3, In4 and then the pins entered
24 // here in the sequence 1-3-2-4 for proper sequencing
25 Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
28 /*-----( Declare Variables )-----*/
31 void setup() /*----( SETUP: RUNS ONCE )----*/
33 // Nothing (Stepper Library sets pins as outputs)
34 }/*--(end setup )---*/
36 void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
38 small_stepper.setSpeed(1); // SLOWLY Show the 4 step sequence
39 Steps2Take = 4; // Rotate CW
40 small_stepper.step(Steps2Take);
43 Steps2Take = STEPS_PER_OUTPUT_REVOLUTION / 2; // Rotate CW 1/2 turn
44 small_stepper.setSpeed(100);
45 small_stepper.step(Steps2Take);
48 Steps2Take = - STEPS_PER_OUTPUT_REVOLUTION / 2; // Rotate CCW 1/2 turn
49 small_stepper.setSpeed(700); // 700 a good max speed??
50 small_stepper.step(Steps2Take);
53 }/* --(end main loop )-- */