Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. Stepper Motor Controller
  2.  language: Wiring/Arduino
  3.  
  4.  This program drives a unipolar or bipolar stepper motor.
  5.  The motor is attached to digital pins 8 and 9 of the Arduino.
  6.  
  7.  The motor moves 100 steps in one direction, then 100 in the other.
  8.  
  9.  Created 11 Mar. 2007
  10.  Modified 7 Apr. 2007
  11.  by Tom Igoe
  12.  
  13.  */
  14.  
  15. // define the pins that the motor is attached to. You can use
  16. // any digital I/O pins.
  17.  
  18. #include <Stepper.h>
  19.  
  20. #define motorSteps 200     // change this depending on the number of steps
  21.                            // per revolution of your motor
  22. #define motorPin1 8
  23. #define motorPin2 9
  24. #define ledPin 13
  25.  
  26. // initialize of the Stepper library:
  27. Stepper myStepper(motorSteps, motorPin1,motorPin2);
  28.  
  29. void setup() {
  30.   // set the motor speed at 60 RPMS:
  31.   myStepper.setSpeed(60);
  32.  
  33.   // Initialize the Serial port:
  34.   Serial.begin(9600);
  35.  
  36.   // set up the LED pin:
  37.   pinMode(ledPin, OUTPUT);
  38.   // blink the LED:
  39.   blink(3);
  40. }
  41.  
  42. void loop() {
  43.   // Step forward 100 steps:
  44.   Serial.println("Forward");
  45.   myStepper.step(100);
  46.   delay(500);
  47.  
  48.   // Step backward 100 steps:
  49.   Serial.println("Backward");
  50.   myStepper.step(-100);
  51.   delay(500);
  52.  
  53. }
  54.  
  55. // Blink the reset LED:
  56. void blink(int howManyTimes) {
  57.   int i;
  58.   for (i=0; i< howManyTimes; i++) {
  59.     digitalWrite(ledPin, HIGH);
  60.     delay(200);
  61.     digitalWrite(ledPin, LOW);
  62.     delay(200);
  63.   }
  64. }