Advertisement
iyera20

Stepper Motor

Jun 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <Stepper.h>
  2.  
  3. //www.elegoo.com
  4. //2016.12.12
  5.  
  6. /*
  7. Stepper Motor Control - one revolution
  8.  
  9. This program drives a unipolar or bipolar stepper motor.
  10. The motor is attached to digital pins 8 - 11 of the Arduino.
  11.  
  12. The motor should revolve one revolution in one direction, then
  13. one revolution in the other direction.
  14.  
  15. */
  16.  
  17. #include <Stepper.h>
  18.  
  19. const int stepsPerRevolution = 500; // change this to fit the number of steps per revolution
  20.  
  21. // initialize the stepper library on pins 8 through 11:
  22. Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);
  23.  
  24. void setup() {
  25. // set the speed at 20 rpm:
  26. myStepper.setSpeed(20);
  27. // initialize the serial port:
  28. Serial.begin(9600);
  29. }
  30.  
  31. void loop() {
  32. // step one revolution in one direction:
  33. Serial.println("clockwise");
  34. myStepper.step(stepsPerRevolution);
  35. delay(500);
  36.  
  37. // step one revolution in the other direction:
  38. Serial.println("counterclockwise");
  39. myStepper.step(-stepsPerRevolution);
  40. delay(500);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement