Go Down

Topic: New Stepper Motor Example code that works (Read 376 times) previous topic - next topic


Code: [Select]
  Stepper Motor Control - one revolution

  This program drives a unipolar or bipolar stepper motor.
  The motor is attached to digital pins 8 - 11 of the Arduino.

  The motor should revolve one revolution in one direction, then
  one revolution in the other direction.

  Created 11 Mar. 2007 by Tom Igoe
  Modified 30 Nov. 2009 by Tom Igoe
  Modified 24 Aug. 2016 by Dave Gordon https://www.youtube.com/channel/UCw0RquafdM8U-0hfqNQz8AQ


#include <Stepper.h>

const int stepsPerRevolution = 2048;  // change this to fit the number of steps per revolution for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,  10, 9, 11);

void setup() {
  // set the speed at 10 rpm: (15 or less for most motors and controllers)
  // initialize the serial port:

void loop() {
  // step one revolution  in one direction:

  // step one revolution in the other direction:

Changes: Changed StepsPerRevolution to be more in line with current stepper motors
             Changed initiating the Stepper class - pins changed to reflect most stepper motor driver pin out documentation
             Changed StepperSpeed to 10 most motors from kits don't work over 15 RPM
             Changed delay to 50. 500ms was too long.

Go Up