document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2. Stepper Motor Control - speed control
  3.  
  4. This program drives a unipolar or bipolar stepper motor.
  5. The motor is attached to digital pins 8 - 11 of the Arduino.
  6. A potentiometer is connected to analog input 0.
  7.  
  8. The motor will rotate in a clockwise direction. The higher the potentiometer value,
  9. the faster the motor speed. Because setSpeed() sets the delay between steps,
  10. you may notice the motor is less responsive to changes in the sensor value at
  11. low speeds.
  12.  
  13. Created 30 Nov. 2009
  14. Modified 28 Oct 2010
  15. by Tom Igoe
  16.  
  17. */
  18.  
  19. #include <Stepper.h>
  20.  
  21. const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
  22. // for your motor
  23.  
  24.  
  25. // initialize the stepper library on pins 8 through 11:
  26. Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
  27.  
  28. int stepCount = 0; // number of steps the motor has taken
  29.  
  30. void setup() {
  31. // nothing to do inside the setup
  32. }
  33.  
  34. void loop() {
  35. // read the sensor value:
  36. int sensorReading = analogRead(A0);
  37. // map it to a range from 0 to 100:
  38. int motorSpeed = map(sensorReading, 0, 1023, 0, 100);
  39. // set the motor speed:
  40. if (motorSpeed > 0) {
  41. myStepper.setSpeed(motorSpeed);
  42. // step 1/100 of a revolution:
  43. myStepper.step(stepsPerRevolution / 100);
  44. }
  45. }
');