Skip to content

Instantly share code, notes, and snippets.

@alyatwa
Created September 15, 2019 21:51
Show Gist options
  • Save alyatwa/87fba5586a27ef7ff7eaecd11d28916e to your computer and use it in GitHub Desktop.
Save alyatwa/87fba5586a27ef7ff7eaecd11d28916e to your computer and use it in GitHub Desktop.
stepper motor
// Arduino stepper motor control code
#include <Stepper.h> // Include the header file
// change this to the number of steps on your motor
#define STEPS 32
// create an instance of the stepper class using the steps and pins
Stepper stepper(STEPS, 8, 10, 9, 11);
int val = 0;
void setup() {
Serial.begin(9600);
stepper.setSpeed(200);
}
void loop() {
if (Serial.available()>0)
{
val = Serial.parseInt();
stepper.step(val);
Serial.println(val); //for debugging
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment