Picture of Arduino + 2 servos + mouse
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

Picture of 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)
1-40 of 52Next »
anto pV16 days ago

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?

dlanday2 months ago

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

Hi, I wrote the initial sketches which this guy is passing off as his own.
You are using continuous servos which take a velocity (speed it turns) rather than a direction between 0 and 180degrees.
I'd suggest sending a value of x or y divided by 4 instead of 2 so its in the range of 0-90.
To allow it to stop when you centre the mouse set up a dead zone. So before sending xpos or ypos check that they are greater than a value, perhaps 5-10?
So in the function update() try:
if (xpos >= 10){
xpos= x/4;

Do a similar thing for ypos and see if that sorts things. I'd also suggest doing some easing on it to make it move faster the further it moves from home.
Perhaps using something like : xpos=x/4*(x*0.01)
//Get x, divide by 4 to get 0 - 90. //Multiply that by x*0.01 which would be a value between 0 and 0.9.

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.

sir kindly inform me that,can i connect mouse to arduino uno directly or not.

ShrobonB8 months ago

Thank you a lot for this tutorial . It worked effortlessly .

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 .

TylerS28 months ago

how can i change the port in processing software

undefined158 KB
TylerS28 months ago

how can i change my port in processing software

undefined158 KB
TylerS28 months ago

how can i change my port in processing software

undefined158 KB
TylerS28 months ago

how can i change my port in processing software

undefined158 KB
TylerS28 months ago

how can i change my port in processing software

undefined158 KB
TylerS28 months ago

how can i change my port in processing software

undefined158 KB
t3rm1t9 months ago

Do you know how should i change the code if i have continuous servo?

Great project but running the bare processing code on a mega 2560 the servos wont move.

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

Tried changing the serial value from 0 to 1 to 2 an still no joy.

Have ports 1,3,5 and my mega is on port 5 as my UNO uses port 3

Can i manually set the port some other way as I think that is my issue ?

biomech75 (author)  BallscrewBob11 months ago

I will try and I will let you know

Now working in an XP VM just fine. Just didnt like win 7 x64 for some reason.

thank you soooooo much for this tutorial, IVE made it and it works absolutely perfectly!!!! your amazing.

i do have one question to ask.

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.

if you do, would you mind emailing me or posting it or if anyone else has any ideas @ musical_mike@hotmail.co.uk.

thank you very much for your help guys :)

biomech75 (author)  musicalmike11 months ago

SURE!!! ill try a new code for it ..... and I will let you know


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?

thanks in advance, any direction would be so helpful!

biomech75 (author)  dylanpahina11 months ago

yup dylanpahina but the power source must be an external one because the 12v power required by those servos

Fearce11 year ago

I used this example to control a remote Helicopter via servos to handheld remote.

Thanks for posting this!

Alibata1 year ago
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.
Thank you sir! I would appreciate any help. :-)
David973 years ago
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.
biomech75 (author)  David973 years ago
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 :-)
biomech75 (author)  bonzlee1 year ago
Have you try my other tutorial - 2 servos move by a thumbstick?
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 :-)
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 & vertically) then the 3rd servo w/c is for triggering the gun will be controlled by computer keypads like the command "ENTER" or by right clicking(pressing) the mouse. Thank you very much Sir.!
SCORN1532 years ago
SCORN1532 years ago
Got the Arduino software...Where do you download the Process Software (to move the servos using the mouse)???

I can't find the Processing program for download anywhere

h3nrikoo2 years ago
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?
(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 "convert" the 360 degree servo to a 180 degree servo?)
On forehand thank you!
Danijel0frk2 years ago
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

The BIG plan is to make several servo pairs with lasers/high powered leds, and via FFT library construct light show :)

Big thanks to biomech75!

https://www.youtube.com/watch?feature=player_embedded&v=LyGXzYBQ3gg :)
biomech75 (author)  Danijel0frk2 years ago
Thanxxx and I am glad that everyone here can use this tutorial to start their own projects...to the outstanding world of Arduino... ;)
Vaibhav1o12 years ago
Friend this is an awesome tutorial!! and can u plz give me the link to the process software please!!
biomech75 (author)  alexanderall2 years ago
Thanxxx alexanderall ;)
Stealth01132 years ago
This is a very cool sketch! I've sitting here for 10 minutes looking at the pan/tilt-system moving! Thanks biomech75!
biomech75 (author)  Stealth01132 years ago
No Problem! This is the basics. Now use your imagination!!!
PiJo3 years ago
I connected the two servos right on schedule. The Arduino software is playing up compile, and upload.
then the Arduino software closed.
Unfortunately I can not move the servo with the mouse.
I use it a Sony VAIO Laptop:

Maybe I can give a tip whoever.
Thank you

biomech75 (author)  PiJo2 years ago
Maybe is the Arduino Software version I have been having issues with the newest version therefore I am using version 0023. Hope this helps ;
biomech75 (author)  PiJo3 years ago
did you open the process software???
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
1-40 of 52Next »