Go Down

Topic: Stepper Motor Knob (Read 5115 times) previous topic - next topic


This code works a little better but the motor keeps oscilating back and forth while i turn the pot slowly back and forth. Is this the way it works or i should have a smooth motor movement that follows how i turn the pot?Maybe the circuit is too rudimentary?


#include <Stepper.h>

#define STEPS 100

Stepper stepper(STEPS, 8, 9, 10, 11);

int previous = 0;

void setup()


int val = analogRead(0);


void loop()
int val = analogRead(0);

stepper.step(val - previous);

previous = val;


I would suggest first ensuring the motor works by testing it at several speeds/directions and step counts explicitly.

Then separately test that you are getting reasonable values from the analogRead.

Then test the combination - it should just work with that code AFAICT, you have to narrow down the cause of the problem in a systematic way.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]


Thanks Mark,
The motors are in perfect condition and have been tested for many hours using the Easy Driver 4.4 and Adafruit's Motor shield.  I am positive the motor is perfect in full, half and microstep. How would i test the values from analogRead? What would be reasonable values? An oscilloscope?
Is the value 9600 related to 9.6KHoms? or something else? I tried different values and it does change how the motor responds. But always with a non smooth movement. And without precise control. Sometimes the motor turns to either direction continuously and if i work the pot back and forth it stops and goes back. But always in a oscilating fashion.
I will keep playing with it some more to see what happens.Later i will build the circuit using the L293. Anyway it's been fun. Thanks again for the reply.


It sounds like you are getting erratic analogue input readings.
What do you see in the monitor window when you run this?

You either have the pot wired up wrong, or it is too high a value of pot. A 10K is the ideal value.

Go Up