Here is a tutorial on how to make 2 servos move with a mouse using the Arduino board.
There is not a simple tutorial than this one and I have search the web looking for one with no result.
This one is simple and easy for everybody to follow. Enjoy! ;)
Dont forget to vote for me on the Arduino Challenge!!

Note: This tutorial is for those who are using the Arduino already. But If you haven't just yet with this tutorial you can.

Step 1: Materials

You will need the following: (not in a particular order)

1. Arduino Board (my version is UNO).
2. 2 servos Parallax (Radio Shack).
3. Web Cam (optional) to see the movement.
4. 2 rubber bands to hold the Webcam in position.
5. Bread Board to make any connections easy.
6. 1 cable tie
7. Something to hold the servos in place.
8. A computer.                  

1. Arduino Software (to upload the code to move the 2 servos).
2. Process Software (to move the servos using the mouse)
<p>This is great, it works really good! I am on my way creating a etch a sketch so this was really helpful. Thanks ;)</p>
<p>Hi! biomech75, u can do it with dc servo??</p>
<p>yes but you need the motor shield for that and they are not that precise</p>
<p>runs great through serial moniter but running it on micro i had to move the servos to 8 and 9</p><p>processing code doesnt like me for some reason though</p><p>doesnt want COM10 and says there is an error at line 11</p>
<p>conseguiiiiiiii </p><p>agou tentando ler na entrada do Joystick ....para ler esses dados</p><p><br></p>
<p>my project involve measuring the distance to an object. i want my servos to point at the object that i want to measure the distance to. is there any way i can superimpose the image from a camera so that i can see the object on the processing screen, and when i place my mouse over the object the servos point at it?</p>
<p>my servo's run when I implement the code from the Arduino IDE. But, they continuously run without stopping when the code is run. I can even type 0 or 45x etc into the serial monitor to make the servos run faster. the gui box pops up when i run the code in Processing, but it doesn't give me control over the servos, they just continue to spin around. Do you have any idea what Im doing wrong? thanks for the great project idea by the way</p>
<p>sir, kindly inform me soon, because i am working on my final year project. I am working on a robotic arm control by a mouse.the mouse is directly connected to arduino uno not to computer.</p>
<p>sir kindly inform me that,can i connect mouse to arduino uno directly or not.</p>
<p>Thank you a lot for this tutorial . It worked effortlessly . </p><p>The question i have is can you just modify the code so that my servo's remain stable at all position . I mean the point that you mentioned about spoiling the servo's . </p>
<p>how can i change the port in processing software</p>
<p>how can i change my port in processing software</p>
<p>how can i change my port in processing software</p>
<p>how can i change my port in processing software</p>
<p>how can i change my port in processing software</p>
<p>how can i change my port in processing software</p>
<p>Do you know how should i change the code if i have continuous servo?</p>
<p>Great project but running the bare processing code on a mega 2560 the servos wont move.</p><p>If I just type x and y values eg. x10 y10 etc. into IDE serial monitor (not running processing) it will move the servos to required position so my issue is in the processing software. Using processing 2.2.1 and IDE 1.5.6 r2</p><p>Tried changing the serial value from 0 to 1 to 2 an still no joy.</p><p>Have ports 1,3,5 and my mega is on port 5 as my UNO uses port 3</p><p>Can i manually set the port some other way as I think that is my issue ?</p>
<p>I will try and I will let you know</p>
<p>Now working in an XP VM just fine. Just didnt like win 7 x64 for some reason.</p>
<p>thank you soooooo much for this tutorial, IVE made it and it works absolutely perfectly!!!! your amazing.</p><p>i do have one question to ask.</p><p>have you been able to come up with a code to control servos with the computer keyboard? ive looked on google for codes but they have nothing so i thought i would ask you.</p><p>if you do, would you mind emailing me or posting it or if anyone else has any ideas @ <a href="mailto:musical_mike@hotmail.co.uk" rel="nofollow">musical_mike@hotmail.co.uk</a>.</p><p>thank you very much for your help guys :)</p>
<p>SURE!!! ill try a new code for it ..... and I will let you know</p>
<p>Hi,<br><br>Great project! I am real novice, and i want to implement your design to move x and y tracks for a 3d printer, and i was wondering would this work by using stepper motors(12v 4wire) and if so what would the circuit look like? and would the code change much?<br><br>thanks in advance, any direction would be so helpful! </p>
<p>yup dylanpahina but the power source must be an external one because the 12v power required by those servos</p>
<p>I used this example to control a remote Helicopter via servos to handheld remote.</p><p>Thanks for posting this!</p>
Hello sir Biomech75! I want to ask for your help. How can I put the video frames from the webcam (as I plan to use a webcam) in the same box in the processing software where the mouse is being moved for servos positioning? i will use it for my project in school. <br>Thank you sir! I would appreciate any help. :-)
Very nice, I thought of connecting it with a x-bee and bluetooth modem to a computer and then mounting it on a rc car.
great idea!!
Good day.! We are having our thesis(Computer controlled taser gun) right now, we are in need of a program that will control 3 servos via computer individually. The 1st servo must be in charge of horizontal movement, then the 2nd for vertical movement and the 3rd one for triggering the taser gun. We do appreciate your help and advice Sir. Thank u for ur kind consideration :-)
Have you try my other tutorial - 2 servos move by a thumbstick?<br>I hope this works If not let me know
I've seen ur tutorial - 2 servos move by a thumbstick Sir it was very nice :-) <br>But as much as possible Sir we would like to control the 3 servo by using the keypad of the computer. What I mean Sir, is that we would like to use ur great idea of controlling 2 servos by the mouse(horizontally &amp; vertically) then the 3rd servo w/c is for triggering the gun will be controlled by computer keypads like the command &quot;ENTER&quot; or by right clicking(pressing) the mouse. Thank you very much Sir.! <br>
Got the Arduino software...Where do you download the Process Software (to move the servos using the mouse)??? <br> <br>I can't find the Processing program for download anywhere <br> <br>
Thank you so much for the tutorial, it worked perfectly. However, I was trying to change the x-axis servo to a 360 degree servo and it just kept spinning. Can you please help me change the code for Alduino and Processing? <br>(I would want it to spin from degree 0 to 360 or close, but not all the way around. If this is not possible with the mouse control, is there a way to &quot;convert&quot; the 360 degree servo to a 180 degree servo?) <br>On forehand thank you!
Played two days with processing and servos. Added some new features to processing interface. Available at http://www.megafileupload.com/en/file/410547/two-servos-key-mouse-rar.html <br> <br>The BIG plan is to make several servo pairs with lasers/high powered leds, and via FFT library construct light show :) <br> <br>Big thanks to biomech75! <br> <br>https://www.youtube.com/watch?feature=player_embedded&amp;v=LyGXzYBQ3gg :)
Thanxxx and I am glad that everyone here can use this tutorial to start their own projects...to the outstanding world of Arduino... ;)
Friend this is an awesome tutorial!! and can u plz give me the link to the process software please!!
http://processing.org/download/ <br>
Thanxxx alexanderall ;)
This is a very cool sketch! I've sitting here for 10 minutes looking at the pan/tilt-system moving! Thanks biomech75!
No Problem! This is the basics. Now use your imagination!!!
Hello<br>I connected the two servos right on schedule. The Arduino software is playing up compile, and upload.<br>then the Arduino software closed.<br>Unfortunately I can not move the servo with the mouse.<br>I use it a Sony VAIO Laptop:<br><br>Maybe I can give a tip whoever.<br>Thank you <br><br>
Maybe is the Arduino Software version I have been having issues with the newest version therefore I am using version 0023. Hope this helps ;
did you open the process software??? <br>after you close the arduino you copy and paste the code to the process software and click run. Then you will see a grey box with the mouse pointer there, move that to start moving the servos
I was using a laptop and a usb mose during that time hope this help ;)
please help me. <br>I would like to control 3 servo by mouse. <br>I don&acute;t know how to do it. <br> <br>//Arduino code: <br>#include <br> <br>Servo yservo; Servo xservo; Servo zservo; // servos for x and y <br>//set initial values for x and y <br>int ypos = 0; <br>int xpos= 0; <br>int zpos= 0; <br> <br>void setup(){ <br> xservo.attach(14); //(analog pin 0) for the x servo <br> yservo.attach(15); //(analog pin 1) for the y server <br> zservo.attach(16); <br> <br> Serial.begin(19200); // 19200 is the rate of communication <br> Serial.println(&quot;Rolling&quot;); // some output for debug purposes. <br> <br>} <br> <br>void loop() { <br> static int v = 0; // value to be sent to the servo (0-180) <br> if ( Serial.available()) { <br> char ch = Serial.read(); // read in a character from the serial port and assign to ch <br> switch(ch) { // switch based on the value of ch <br> case '0'...'9': // if it's numeric <br> v = v * 10 + ch - '0'; <br> /* <br> so if the chars sent are 45x (turn x servo to 45 degs).. <br> v is the value we want to send to the servo and it is currently 0 <br> The first char (ch) is 4 so <br> 0*10 = 0 + 4 - 0 = 4; <br> Second char is 4; <br> 4*10 = 40 + 5 = 45 - 0 = 45; <br> Third char is not a number(0-9) so we drop through... <br> */ <br> break; <br> case 'x': // if it's x <br> /* <br> ....and land here <br> where we send the value of v which is now 45 to the x servo <br> and then reset v to 0 <br> */ <br> xservo.write(v); <br> v = 0; <br> break; <br> case 'y': <br> yservo.write(v); <br> v = 0; <br> zservo.write(v); <br> v = 0; <br> break; <br> <br> } <br> } <br>} <br> <br>//Processing code: <br>import processing.serial.*; <br> <br>int xpos=90; // set x servo's value to mid point (0-180); <br>int ypos=90; // and the same here <br>int zpos=90; <br>Serial port; // The serial port we will be using <br> <br>void setup() <br>{ <br> size(360, 360); <br> frameRate(100); <br> println(Serial.list()); // List COM-ports <br> //select second com-port from the list (COM3 for my device) <br> // You will want to change the [1] to select the correct device <br> // Remember the list starts at [0] for the first option. <br> port = new Serial(this, Serial.list()[0], 19200); <br>} <br> <br>void draw() <br>{ <br> fill(175); <br> rect(0,0,360,360); <br> fill(255,0,0); //rgb value so RED <br> rect(180, 175, mouseX-180, 10); //xpos, ypos, width, height <br> fill(0,255,0); // and GREEN <br> rect(175, 180, 10, mouseY-180); <br> update(mouseX, mouseY ); <br>} <br> <br>void update(int x, int y) <br>{ <br> //Calculate servo postion from mouseX <br> xpos= x/2; <br> ypos = y/2; <br> zpos = y/2; <br> //Output the servo position ( from 0 to 180) <br> port.write(xpos+&quot;x&quot;); <br> port.write(ypos+&quot;y&quot;); <br> port.write(zpos+&quot;y&quot;); <br>} <br> <br>thank for response.

About This Instructable


143 favorites


Bio: Evo 8, Honda K, B Engines Mods
More by biomech75: Arduino thumbstick controller Arduino+Servo+Potentiometer Arduino Robotic Arm
Add instructable to: