Introduction: Head Mouse With MPU6050 and Arduino Micro

Hi everyone, here it is my new project, a mouse controlled with the movement of the head!
I decided to make this project once I received my accelerometer/gyroscope MPU6050 from IC Station, and I wanted to do something useful with this.
Then I found out that a "Head Mouse" already exists, made by Martin Millmore with another accelerometer/gyroscope:

Well here it is my version, made with an Arduino Micro and a MPU6050.

Thanks to IC Station for the accelerometer/gyroscope they sent me, allowing me to create this project!

Step 1: Materials and Tools Needed

Picture of Materials and Tools Needed

Materials needed:
- Arduino Micro;
- accelerometer/gyroscope MPU6050;
- a Compeed box (I found this comfortable as Martin Millmore said in his guide);
- an elastic band;
- micro USB cable to USB type B (like those used for Android smartphones);
- cables;
- a pcb board;
- glue, or better, Sugru.

Tools needed:
- a computer with the Arduino IDE installed;
- soldering station;
- mini drill.

Step 2: Building

Picture of Building

1) Solder on the pcb board the pins like in the image: pin 2 of Arduino to pin SDA, pin 3 to SCL, pin 5V to PWR, pin GND to GND.
2) Make a hole with the dremel on the Compeed box so the micro USB cable can reach the Arduino Micro, and two straight holes for the elastic band.
3) glue the board to the box and add the elastic band.

Step 3: Code

Connect the board to your computer and load first the "Test" code to the Arduino to test if everything work fine. You'll probably need to change some values (everything is written in the code's comments) since I had to add a constant, beacuse values from the gyroscope are not "zero" when I'm not moving.
Use the Serial Monitor to check if you need to fix the "zero" of the gyroscope.
Once you found the right values you can load the program deleting the "Serial.print" part, that is equivalent to the standard code.
If you want the click function after a delay of time since the pointer has been in a 10x10 pixel zone load the code "with_click" to Arduino Micro.

Here there are the codes:

- standard code with only movement:

- code to test the output:

- code with movement and click after 2 seconds:

To use them you'll need the MPU6050 and I2C libraries:

MPU 6050:


In this site I found the libraries and the code from which I developed the programs of my project:

Link to Martin Millmore's project with the LSM9DS0 instead of the MPU6050:


ICStation13 (author)2017-07-20

Thanks for your awesome project. Great~~

Ayudas ParaT (author)2017-07-07

great work,congratulations

YoyOA2 (author)2017-04-28

can this be done with a arduino mega ?

Gabry295 (author)YoyOA22017-04-29

No, you need an Arduino Micro or Leonardo, which have the "ATmega32u4" that interfaces directly with the PC and can be recognized as mouse or keyboard. See more by Googling "Arduino Leonardo" and "Arduino Micro" and check the description on the Arduino official sites.

YoyOA2 (author)Gabry2952017-05-29


i could implement other tasks, such as sustained click or secondary click, this with respect to programming?

PhilL76 (author)2017-05-28

I made a version which runs on every Arduino model using serial communication and python, but apparently I can't post the link here D:

MagicKreator made it! (author)2017-04-20

I made this, with an arduino due, the only problem that i have is that sometimes some axis change their value "random" and this cause that sometimes the pointer move down, Sorry for my english, Thanks for the project

PhilL76 (author)MagicKreator2017-05-28

Maybe you could let the program automatically determine the offset every time it starts. Take a look at the calibrate() function of my version if you don't know how to do this:

Gabry295 (author)MagicKreator2017-04-29

Hi MagicKreator, well done! :D
I'm sorry for your problem, I think it's in your accelerometer/gyroscope module, or in your Arduino Due board. Less probable it's the code.

ph77894456 (author)2016-10-25

Hi Gary, can u tell me what is "200" in your sketch? Thank u very much :)

PhilL76 (author)ph778944562017-05-28

The sensitivity.

As the sensor values can vary quite a lot this helps to keep the pointer calm.

If you increase it, the pointer becomes slower,

if you decrease it, the pointer becomes faster.

ParthT12 (author)2017-02-25

how can I include right click along with lest click option

nourdiri (author)2016-12-18

Hi, I need to know what is the principle of working of the gyroscope, accelerometer and magneometer? please.

Gabry295 (author)nourdiri2016-12-18

That explanation is up to Wikipedia! :) here it is:

It would be too long to explain here :P

throbscottle (author)2016-09-13

Very clever, but I don't think I'd like having to keep moving my head to move the cursor!

Now, an EYE tracking mouse, that would be ultra cool! (I bet you could do it with a webcam)

ScottW66 (author)throbscottle2016-09-13

Yeah, an EYE tracking mouse would be super cool!!! Haven't a clue how to do it!

avashi (author)ScottW662016-11-26

look at the EYETRACKER a open source project easily available and very cheap to make

HafizuddinA3 (author)avashi2016-12-07

using arduino nano can use for this project ? where to get libraries for mouse.h

Gabry295 (author)HafizuddinA32016-12-10

Arduino Nano won't work for this project since it has a different processor and can't be interfaced to the PC like a mouse.

Library Mouse.h is already installed when you install the Arduino IDE

throbscottle (author)avashi2016-11-27

Cool - I didn't realise there were these projects around! And now I find it slightly creepy!

avashi (author)2016-11-27

i dont think it will work arduino mini dont have capabilities to act like a usb input device like mouse or keyboard please explain me if i am wrong

Gabry295 (author)avashi2016-11-29

Right, it's impossible to do with an Arduino Mini since it has an "ATmega328" and other board such Micro and Leonardo has the "ATmega32u4"

avashi (author)Gabry2952016-12-01

yes it work perfectly but their is one issue right now when i connect my Arduino micro and upload the code it work fine but when i disconnect it and it didn't work perfectly it lag too much in movements of cursor and i have to again upload the code to work any solution i am new to atmega32U4 I only work on atmega 328 p , atmega 32 and some pic

ClintH16 (author)2016-09-14

I'd be worried about static electricity being generated by that headband touching the components directly.

Gabry295 (author)ClintH162016-11-17

Me not! There are no dangerous voltages:)

PetrB14 (author)2016-09-13

How do you turn around in games like the one on the video or CS or so?? :)

MatthewG147 (author)PetrB142016-09-13

well, maybe, it could be like a VR, but on a smaller screen like a phone or tablet. So you could play like in your chair or something. It's not totally impossible. what do you think?

PetrB14 (author)MatthewG1472016-09-14

I asked how to turn around with this in the game. I mean how to turn more 180 degrees like 360 or more... You probably won't be turning on your chair during the game thus loosing eye contact with screen... So? Any suggestions?

MatthewG147 (author)PetrB142016-09-14

I mean, you have the screen attached to your head so when you move your head the video moves but the device stays in front of you.

Gabry295 (author)PetrB142016-09-14

You can set the senisbility so when you rotate your head you cover a bigger angle in the game and you can see behind you without turning your neck too much :)
Anyway I'm still thinking about other solutions, in the end the VR is the best... The screen moves with you!

craighissett (author)MatthewG1472016-09-14

You could use a VNC Server on the gaming PC, and a VNC Client on your phone/tablet to show your PC's screen?

millmore (author)2016-09-13

Thanks for the shout out! Looks like a good version that you did.

Jopapa (author)2016-09-12

Simple y magnifico montaje, gracias por compartir.

Gabry295 (author)Jopapa2016-09-12

Thank you too! :)

About This Instructable




Bio: Hi, I'm Gabry295, and I like doing electronic things, even if at the moment I have only one Instructable :) I like robots and everything ... More »
Add instructable to: