Here are the code fragments that would help you.
Connect the three wires from the potentiometer to your board. The first goes from one of the outer pins of the potentiometerto ground. The second goes from the other outer pin of the potentiometer to 5 volts. The third goes from the middle pin of the potentiometer to the analog pin A0
.
Here is the connection schematic:

Here is the code to read the analog value from port A0:
int sensorValue = analogRead(A0);
this would assign a value ranging fro 0-1023 to sensorValue
according to the position of the Pot.
int stepsPerRevolution = 200;
//this variable holds the no of steps the motor rotates to complete a full circle rotation.
int stepCount = 0; // number of steps the motor has taken
stepsPerRevolution = map(sensorReading, 0, 1023, 0, 200);
// step 1/100 of a revolution:
myStepper.step(stepsPerRevolution / 100);
Here is an example program for controlling the direction of stepper using microswitches:
#define stepPin 2
#define dirPin 3
#define pinLimitswitchLeft 4 // these can be either left or right depending on motor wiring and dir pin.
#define pinLimitswitchRight 5 // these switches must be N.O. types
int stepDelay = 100; // this is the step delay in microseconds. Reduce this to speed up motor rotation and vice versa.
void setup()
{
pinMode (stepPin, OUTPUT);
pinMode (dirPin, OUTPUT);
pinMode (pinLimitswitchLeft, INPUT_PULLUP);
pinMode (pinLimitswitchRight, INPUT_PULLUP);
}
void loop()
{
digitalWrite(dirPin, HIGH); // set direction pin, the direction that the motor will rotate is dictated by it's wiring
while (digitalRead(pinLimitswitchLeft) == HIGH) // move motor until left limit switch is pressed.
{
stepMotor();
}
digitalWrite(dirPin, LOW); // set direction pin, the direction that the motor will rotate is dictated by it's wiring
while (digitalRead(pinLimitswitchRight) == HIGH) // move motor until right limit switch is pressed.
{
stepMotor();
}
}
void stepMotor()
{
digitalWrite(stepPin, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin, LOW);
delayMicroseconds(stepDelay);
}
Change the control from the control switch to the number of steps taken by your motor when the switch is pressed and it will work as you require.
I have not included the header files.
Please edit the program as you require