The speed of a stepper motor depends on the interval between steps. You can detect the position of a potentiometer with analogRead() and convert the value into a suitable interval.
int dirpin = 2;
int steppin = 3;
int potPin = A1;
int potValue = 0;
void setup() {
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
}
void loop() {
potValue = analogRead(potPin) / 8;
digitalWrite(dirpin, LOW);
digitalWrite(steppin, LOW);
delay(potValue);
digitalWrite(steppin, HIGH);
}
This code works fine. But he is going really fast from fast to slow. There isn't a big area to control the stepper motor. When I turned the potmeter half you barely see the stepper motor turn.