running stepper motor using pot

im having trouble getting the stepper motor to run forwards or backwards in sync with the potentiometer
heres the code:

#include <AFMotor.h>

AF_Stepper motor(48, 2);
int potpin = 0;
int val = 0;

void setup() {
  Serial.println("stepper test!");

void loop() {
  val = analogRead(potpin);
  if(val < 513)
    motor.step(96, FORWARD, SINGLE);
    motor.step(96, BACKWARD, SINGLE);

i also wish the program would update the serial monitor faster

any help


What problem are you having?

I'm not familiar with that stepper library, but I suspect you may be commanding the stepper to step too quickly.

A stepper motor cannot instantly go from zero to full speed, you must start with slow steps and work up to fast steps. If you try to exceed the rate at which the motor can accelerate with whatever load it is carrying it will not turn smoothly and may stall.

Try putting a delay(100) in your loop so that it reads the potentiometer and steps the stepper 10 times each second. This should be slow enough to eliminate most mechanical problems with an unloaded stepper, but fast enough that you will see it turning.

If that does not work, remove the analogRead and serial write and simply drive the stepper in one direction, with a 500mS delay per step. If that doesn't work something else is screwed up. :slight_smile: