Stepper Motor Control.

Hello,

I am trying to control a bipolar stepper motor using a 10K pot with the Arduino UNO. I have tried the "Stepper Motor Knob" sketch and it works, however, not the way I would like to.

I have also used the "Stepper One Revolution" sketch. With this sketch the stepper motor rotates clockwise and counter clockwise correctly, so I know the stepper motor is wired correctly.

I want to control the stepper motor like a servo using the pot to move the stepper motor. As I turn the pot clockwise I want the stepper motor to travel in the same direction and stop at the position of the pot, then reverse as I turn the pot counterclockwise.

I would like to have the stepper motor turn one and a half turns with one complete turn of the pot.

I hope I have described my problem in such a way that someone can understand what I would like to do in my sketch.

Thanks in advance for your help.

I hope I have described my problem in such a way that someone can understand what I would like to do in my sketch.

So, one full turn of the potentiometer should result in the stepper stepping some fixed number of times. So, what is the problem? What does the code you didn't post actually do? How does that differ from what you want?

HamRadio:
I would like to have the stepper motor turn one and a half turns with one complete turn of the pot.

Please post your program so we can see what you can see.
And please use the code button </>so your code looks like thisand is easy to copy to a text editor

Assuming that analogRead() returns 0 at one end of the movement of the pot and 1023 at the other end you need to map the range 0-1023 to the number of steps the stepper should make - perhaps 0 -300.

Then, if you use the AccelStepper library you can update the required position with stepper.moveTo() as the pot changes.

…R

The following code is what I have, which I believe was written by Tom Igor.
It uses the analog port 0 to read the pot. If you can suggest somewhere I could look for some help… a book or function.

With this sketch the motor rotates about five rev’s when the pot is moved full travel and then stops and vibrates. When the pot is rotated full travel in the reverse direction the motor will start to rotate five times then stop and vibrate. If the pot is moved while the motor is moving then the motor will change direction stop and vibrate this continues until power is removed.

I would like to have the stepper motor turn one and a half turns with one complete turn of the pot, but stop wherever the pot stops, so the stepper motor is controlled like a servo.
I am trying to position a variable cap in an antenna with the stepper motor.

/*

#include <Stepper.h>

// change this to the number of steps on your motor
#define STEPS 100

// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it’s
// attached to
Stepper stepper(STEPS, 8, 9, 10, 11);

// the previous reading from the analog input
int previous = 0;

void setup() {
// set the speed of the motor to 30 RPMs
stepper.setSpeed(30);
}

void loop() {
// get the sensor value
int val = analogRead(0);

// move a number of steps equal to the change in the
// sensor reading
stepper.step(val - previous);

// remember the previous value of the sensor
previous = val;
}

On any given pass through loop(), the stepper is at some position. On any given pass through loop(), the potentiometer is at some position (returns some value). What you need to do is step ONCE in some direction, if the stepper position is not the same as the potentiometer position (reading). Which direction to step depends on whether the potentiometer reading is larger or smaller then the current position.

Of course, this means that you need to keep track of the current stepper position, and map() the potentiometer reading to the same range required to get the stepper to step the required number of times to rotate the amount that you want.

HamRadio:
If you can suggest somewhere I could look for some help… a book or function.

I did. In Reply #2

…R

Thanks Paul & Robin,

I will work on this.

That code uses the 10 bit result of analogRead as a step count. I think you are just asking
"How can I scale the result for a different number of steps?", to which the answer is "scale
the result of the call to analogRead() using map()"