## 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() {

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

So Marc, this is almost inline with a project I'm starting. I would like to create a 2 servo mechanism that controls pitch and yaw for a telescope. I have a couple of easy step controllers and a joystick ( 27800 2 axis ), I'm new to arduino so I am unsure if I need to incorporate that into the design - such as the coding. Have you come across a design for this sort of project? Thanks <br> <br>bill
Hey bill long shot here as your post is 3 years ago but i am working on something very similar. If you get this let me know<br>
I can't believe your wife let you put this in your doorway! And she even helped you with it. :P<br /> <br /> Awesome project, by the way! Looks like fun. :) Now make one with two axes!<br />
It does have two axis... Y and Z!<br /> ( y = left/right&nbsp; Z = up/down)<br /> <br /> But yeah... go for a 3-axis x / y / x ! <br /> <br /> Build the gantry... one track on the first wall, the second on the other... do the whole room! (Evil grin)<br />
Y and Z? Two axes? That's ridiculous!<br /> <br /> Everybody knows X is left and right and Y is up and down!<br /> <br /> Get your facts straight. :P<br /> Only joking, of course. Once again, nice project.<br />
Wrong again. X is left right, y is forwards backwards, and z is up down.
wow my family broke my pinball machine hey maybe claw machine next has top be tougher
Your family is rude then to you
could you have run a DC motor in place of the stepper motor with the same code which is used to run the DC motor?? <br>please reply <br>ps: excuse me if i am being lame n stupid
Dc motors aren't accurate enough to be used
<p>Hi, nice project!<br><br>i was wondering if you can do this with two stepper motors?<br>and what would the circuit look like?<br><br>thanks in advance!</p>
<p>i didn't find any diagram for this project ...</p><p>can you help my to get diagram</p>
<p>How did you make the Funzo?? </p>
help me <br>can you send me the code for two stepper; Stepper X, Stepper Y for pan and tilt http://www.youtube.com/watch?v=ZulNF2enrd0 <br>i have 2 stepper motors, 2 EasyDriver, Arduino uno and Joistick <br>black_daysro@yahoo.com <br>thanks in advance ;)
http://www.robofun.ro/shields/driver-l298-asamblat <br> <br>i heve this type of motor shield.
You should be able to add a second copy of the same code, subing the pins being used for the second motor.<br><br>Try looking at steps, 3, 15, 16<br><br>Step 3 shows the code for a stepper (which you probably dont need).<br>Step 15 shows code for a second dc motor.<br>Step 16 shows these three peices of code combined.<br><br>Good luck!
i have that motor shield, but i can't make the skech to drive 2 motors. <br>I use youre sketch and it works fine, i don't know how to modify for 2 motors.
I think you are looking for an H-bridge circuit. Also - I recomend the motor sheild from adafriut for things like this.
sorry i forgot to say : As you know the two POTs will be the joystick ;)
yeah me too i have to control two steppers which have 20 n.m torque '' big motors '' and i have the stepper drivers. <br>the motors are installed in a 4 wheeler cart. <br>i made a code to control the cart forward and backward using the motors+drivers+Arduino uno+potentiometer <br>and then i made another code without the potentiometer <br>using 3 Arduinos ( 1 master and two slaves) each slave is connected to a motor <br>the code is to apply speed to one of the motors for ex 10 rpm and the other motor <br>5 rpm .. just to make the cart turns left or right ... <br>THE QUESTION NOW WHAT IS THE CODE FOR THE STEERING USING THE POTENTIOMETER ?? <br>there will be 2 POTs one for steering and the other for moving. <br>PLEASE HELP !!!
Hello,<br><br>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.<br>Can you help me with the code? How would two stepper motors?<br><br>I'd appreciate if you can send photos or a wiring diagram.<br><br>Thank you very much.
Do you have to use stepper motors? <br> <br>There are alot of examples of pan-and-tilt using hobby servo motors. <br> <br>Here is an example of pan/tilt using servos and joystick: http://www.practicalarduino.com/news/id/411 <br>the code is here: https://github.com/practicalarduino/PanTiltControl/blob/master/PanTiltControl.pde <br> <br>spark fun has parts: http://www.sparkfun.com/products/10335 <br>
Yes, I need to do it with stepper motors, is difficult to code for two engines?
Yeah -- hobby servos have built in feedback, you just need to tell them the angle and they go. If you use stepper motors you need a circuit to drive the motors and some sensors to get feedback on the position of the motors. On the other hand, stepper motors are usually sturdy with more power; so it might be worth it.<br><br>Good luck!
Thanks for responding, <br>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? <br>I know nothing about programming, so I ask for help. <br> <br>Thanks for everything, <br> <br>Greetings.
I love this! Maybe you could remount the joystick on the ps2 controller?
Incredible! Thanks for sharing, how would you do it to make it &quot;stiffer&quot;? Like the arcade games. Thanks!
OMG its funzo from the simpsons
Great Instructable - congratulations! One quick question: would it maybe make more sense to use a machine screw for the center of the claw, rather than a wood screw? For one thing, you don't risk drilling a hole in the object you're picking up. :-) Second, the wood screws have decreasing diameter near the tip, which might make the mechanism slip. Finally, machine screws could give you finer and better control due to the diameter thing and typically more threads per inch. Again - GREAT job!!
COOL&nbsp;<br /> <br /> the kids&nbsp;are so adorable!!!
&quot;writhing funzo's in my sack, makes me happy, makes me hurt my back&quot;<br />
&nbsp;i KNEW it was funzo. i was just thinking: that doll looks soooo familiar....
Any interest in a Crane Game kit?<br /> <br /> It would be&nbsp;an Arduino sheild with a Joystick, Buttons, and Motor Drivers.<br /> <br /> I started using BatchPCB.com last night and boy is it fun!<br /> <br /> <br /> <br />
&nbsp;We need an instructable on how to make that helmet next!
Yeah - until then you'll have to go to pre-school to learn that one!
&nbsp;Have her teach you, and make an instructable at the same time. That would be cute.
Thanks- that's a great idea!
Ive got another idea.&nbsp; Why dont you set up four motors, one in each of the corners of the room, which act as pullies?&nbsp; You can control the precise position in all three axies, and have more stability.
<em>Why dont you set up four motors, one in each of the corners of the room, which act as pullies?<br /> </em><br /> You could certainly try this - but it sounds a bit tricky.&nbsp; I've had better luck with very short drive trains.&nbsp;&nbsp; In this project I've avoid gears and belts as much as possible.<br /> <br /> -Marc
You can do that, but it is not necessary.&nbsp; It only takes three strings and a weight at the end of the three connected strings to ensure stability.&nbsp; One extra motor would make the crane capable of moving all over the room though.
<p>Gotcha - that is an intersting idea.</p>
.How do you think this would be like in an arcade cabinet?<br />
<em>How do you think this would be like in an arcade cabinet?<br /> <br /> </em>Awsome!<br /> <br /> It is fun to cheat - so I would leave out the glass.<br />
Really cool. I&nbsp;like the idea too! Makes me want to take apart my computer now. XD
I'm not sure which is better the project or the videos! Cool idea, thoughtfully executed and well documented. When will it be strong enough to pick up something useful like say.. a bottle of beer? ;-)
<br /> I'm a Weiner!!!<br /> <br /> Wanderwolf - I'm going to put a link to your Xmega board with USB bootloader.&nbsp;<br /> <br /> Here it is - <br /> <br /> <a href="http://www.bostonandroid.com/EVAL-USB-256.html" rel="nofollow">http://www.bostonandroid.com/EVAL-USB-256.html</a><br /> <br /> <br /> -Marc
Congrats Husband on your big win. I&nbsp;can't wait to use &quot;my&quot; new netbook. <br /> Oh, and you still need to fill in the holes in the doorway. <br />
done!
&nbsp;parab&eacute;ns pelo seu projeto, gostei muito da sua criatividade de usar materiais alternativos para constru&ccedil;&atilde;o.