Skip to content

Instantly share code, notes, and snippets.

@cangevine
Created January 10, 2014 21:44
Show Gist options
  • Save cangevine/8363273 to your computer and use it in GitHub Desktop.
Save cangevine/8363273 to your computer and use it in GitHub Desktop.
Stepper motor example
// Wiring configuration to the stepper driver: yellow & red, gray & green
#include <Stepper.h>
const int STEPS_PER_REV = 200;
Stepper _stepper(STEPS_PER_REV, 12, 13);
const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
void setup() {
pinMode(pwmA, OUTPUT);
pinMode(pwmB, OUTPUT);
pinMode(brakeA, OUTPUT);
pinMode(brakeB, OUTPUT);
digitalWrite(pwmA, HIGH);
digitalWrite(pwmB, HIGH);
digitalWrite(brakeA, LOW);
digitalWrite(brakeB, LOW);
// Trying to look up information on max & min RPMs.
// Datasheet on this website leads me to guess it's 53...
// http://motion.schneider-electric.com/downloads/quickreference/NEMA17.pdf
_stepper.setSpeed(53);
}
void loop() {
_stepper.step(STEPS_PER_REV);
_stepper.step(-STEPS_PER_REV);
delay(100);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment