Step 2: Control a stepper with joy stick
Next we need to control a stepper motor the potentiometer on the joystick.
Hardware:
Joystick -> Arduino (analog in) -> Arduino (digital out) -> Stepper driver -> stepper motor
I ran this using the EasyDriver from Sparkfun by www.SchmalzHaus.com/EasyDriver
It is well labeled and can run a medium sized stepper motor from the USB power supply. (in this example I am using a NEM17 from Keling Technology).
The screw sheild is by ZachHoeken: http://reprap.org/bin/view/Main/Arduino_Breakout_1_4
Code to control stepper motor from joystick potentiometer
/////////////////////// Arduino ///////////////////////
//******* POT to control a stepper speed and direction ******//
//declare pins
int potPin = 1;
int Step_X = 13;
int Dir_X = 12;
int Enable_X = 8;
//declare values
int Speed_X = 0; //step speed (delay between steps)
int val= 0;
int j = 0;
void setup() {
pinMode(Step_X, OUTPUT);
pinMode(Dir_X, OUTPUT);
pinMode(Enable_X, OUTPUT);
//Serial.begin(9600); // note that serial comm can be used to debug
// but it will slow down the code and slow down the stepper motor alot
//(and be confusing to me)
}
void loop() {
val = analogRead(potPin); // read the value from the sensor
j = val - 517; // 517 is center positions - how far from center?
j = abs(j); //absolute value
Speed_X = 70000/j; //This math inverts the value and scales as needed
//(value found through trial and error)
// The delay between steps will determine the speed of the motor
// So, delay up = speed down
if (val >= 520){
digitalWrite(Enable_X,LOW); // enable
digitalWrite(Dir_X, HIGH); // Set direction
digitalWrite(Step_X,HIGH);
delayMicroseconds(2);
digitalWrite(Step_X,LOW);
delayMicroseconds(Speed_X);
}
if (val <= 510) {
digitalWrite(Enable_X,LOW);// enable
digitalWrite(Dir_X, LOW); // Other direction
digitalWrite(Step_X,HIGH);
delayMicroseconds(2);
digitalWrite(Step_X,LOW);
delayMicroseconds(Speed_X);
}
if (val <=520 && val >= 510) {
digitalWrite(Enable_X,HIGH); // disable the stepper motor if the joystic is in the center
}
}
Remove these ads by
Signing Up































































Visit Our Store »
Go Pro Today »




can you send me the code for two stepper; Stepper X, Stepper Y for pan and tilt http://www.youtube.com/watch?v=ZulNF2enrd0
i have 2 stepper motors, 2 EasyDriver, Arduino uno and Joistick
black_daysro@yahoo.com
thanks in advance ;)
the motors are installed in a 4 wheeler cart.
i made a code to control the cart forward and backward using the motors+drivers+Arduino uno+potentiometer
and then i made another code without the potentiometer
using 3 Arduinos ( 1 master and two slaves) each slave is connected to a motor
the code is to apply speed to one of the motors for ex 10 rpm and the other motor
5 rpm .. just to make the cart turns left or right ...
THE QUESTION NOW WHAT IS THE CODE FOR THE STEERING USING THE POTENTIOMETER ??
there will be 2 POTs one for steering and the other for moving.
PLEASE HELP !!!
I need your help, I'm doing a project similar to yours, a pan tilt head and I need to control two stepper motors with a joystick.
Can you help me with the code? How would two stepper motors?
I'd appreciate if you can send photos or a wiring diagram.
Thank you very much.
There are alot of examples of pan-and-tilt using hobby servo motors.
Here is an example of pan/tilt using servos and joystick: http://www.practicalarduino.com/news/id/411
the code is here: https://github.com/practicalarduino/PanTiltControl/blob/master/PanTiltControl.pde
spark fun has parts: http://www.sparkfun.com/products/10335
Good luck!
I like to use stepper motors because they have strength and are accurate. Project where you use your joystick, you use a stepper motor, could you help me with the code to use 2 stepper motors?
I know nothing about programming, so I ask for help.
Thanks for everything,
Greetings.