3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

CRANE GAME

Step 2Control a stepper with joy stick

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


 
 

« Previous StepDownload PDFView All StepsNext Step »
7 comments
May 9, 2012. 3:56 PMyel-shourafa says:
sorry i forgot to say : As you know the two POTs will be the joystick ;)
May 9, 2012. 3:53 PMyel-shourafa says:
yeah me too i have to control two steppers which have 20 n.m torque '' big motors '' and i have the stepper drivers.
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 !!!
Mar 30, 2012. 1:08 AMjuande3003 says:
Hello,

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.
Apr 3, 2012. 5:36 AMjuande3003 says:
Yes, I need to do it with stepper motors, is difficult to code for two engines?
May 8, 2012. 1:21 AMjuande3003 says:
Thanks for responding,
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.

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
41
Followers
16
Author:marc.cryan
Looking for access to land or water in Boston Metrowest area.