// Include the Arduino Stepper Library
#include <Stepper.h>
// Number of steps per output rotation
const int stepsPerRevolution = 200;
// make this one if you dont have gears
int gearReduction = 1;
// Current position of the motor
int currentPos = 0;
// Create Instance of Stepper library
Stepper myStepper(stepsPerRevolution, 3, 4, 5, 6);
void setup()
{
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop()
{
moveToPos(50);
delay(1000);
moveToPos(100);
delay(300);
}
void moveToPos(float targetPos){
//calculate how far to move the motor
int stepsToMove = (targetPos - currentPos) * gearReduction;
//move the motor
myStepper.step(stepsToMove);
//set current position
currentPos = targetPos;
}