Stepper Motor Knob

On this example there is no information on how to connect the potentiometer to the circuit. It says the potentiometer is connected to the analog 0 of the Arduino. The pot has three legs. How do i conect it?
I am building a circuit to controll two steppers with a joystick. Two axes ( vertical and horizontal).
How should i modify this code:

/*

#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;
}

to control my two steppers?
Thanks so much.

Connect the middle terminal to your analogue input, connect one of the two remaining legs to +5 volts, connect the other to arduino ground. If the direction of travel is opposite to that you desire then reverse the connections to +5 and ground terminals.
jack

Thank you so much.
One more question:
Is it possible to use a joystick to controll a stepper back and forth and with variable speed depending on how far i push the joystick?
I´d like to build a circuit with two steppers and two drivers for this experiment. And of course in case there is a code that could allow that. I want to build this setup to test linear stages and steppers performance.Thanks again

There are two sorts of joystick, one that is proportional that has pots in them, they can be wired up just like the pot.
The other type are digital, these give just an on / off signal. It is possible to use this type but you need to write the software to time how long they have been pushed and move the motor accordingly.

This is the joystick i have.(http://www.sparkfun.com/products/9032).They do have pots. I am building his circuit and will try out. I am using the Arduino sample circuit with the SN754410NE H-bridge. It would be wonderful to be able to vary the speed from mid point up or down, left or right.I´ll try it out and post my results.

Well seeing the description says:-

Directional movements are simply two potentiometers - one for each axis. Pots are ~10k each.

Then yes.

Hi again, I´ve been trying to make it work precisely like Arduino claims but there on precision at all.
The code i am using is this:

#include <Stepper.h>

#define STEPS 100

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

int previous = 0;

void setup()
{

stepper.setSpeed(30);
}

void loop()
{

int val = analogRead(0);

stepper.step(val - previous);

previous = val;
}

The stepper moves back and forth following the pot but very erratically. I tried to change some of the numbers and nothing works. The pot is working but in a very small portion of the cursor limits. This code does not allow much changing or i dont know how to make these changes.
Maybe there is somebody out there that made this example work like it claims. Any word?
Thanks

Motor Knob.jpg

Get it to print out the values from the pot so you can see what range you are getting. Are you using that joystick? You don't always get the full travel from a joystick.

Since I'm not experienced with programming i would not know how to print the values from the pot. I am not using the joystick, i have a 10K pot hooked up. I can change speed and number of steps but need to learn about that pot values changing task.Thanks Mike.

Since I'm not experienced with programming i would not know how to print the values from the pot

put in the setup:-
Serial.begin(9600);

then add after:-
int val = analogRead(0);

Serial.println(val);

On the photograph you have supplied it appears that the top connection on the pot isn't soldered to the connecting wire. This might be the source of your erratic behaviour.
Apart from that I like your "breadboard" (or should that be MDF) layout
jack

Thanks Jack,
The pot connections are all positively connected. The sweeper goes to 0 analog, the top goes to the +5V and the bottom goes to ground. Yes i mounted the breadboard, motors and Arduino to a rectangle MDF plate i had around. And the soldering is also very good on all three leads despite the appearance. I even inverted the stepper wire connections on the H bridge chips. First i want to make one motor work and after that try to make them both respond to the thumb joystick not shown on the photo.

Mike,
I will try that and post the result. Thanks for the teaching.

Hi again.
This is the code that does not work properly.

#include <Stepper.h>

#define STEPS 100

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

int previous = 0;

void setup()
{

stepper.setSpeed(30);
}

void loop()
{

int val = analogRead(0);

stepper.step(val - previous);

previous = val;
}

I tried to add the serail.begin(9600)
and int Val= analogRead(0)
and Serial.println(val)

But could not figure out where to write these. I ask to please tell me where exactly should they go. After the curly braces? or before?

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;
}

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.

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.