Pages: 1 [2]   Go Down
Author Topic: Stepper Motor Knob  (Read 2013 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Code:



#include <Stepper.h>

#define STEPS 100

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

int previous = 0;

void setup()

{
 
Serial.begin(9800);

int val = analogRead(0);

Serial.println(val);
 
stepper.setSpeed(100);
}

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

 
stepper.step(val - previous);

 
previous = val;
}
Logged

0
Offline Offline
Shannon Member
****
Karma: 159
Posts: 10409
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 504
Posts: 31325
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: 1 [2]   Go Up
Jump to: