Introduction: Head Mouse - Game Controller or Disability Aid

Picture of Head Mouse - Game Controller or Disability Aid

My kids wanted to have a head controlled mouse for playing Minecraft - they wanted to move their heads and have the field of view move. I decided that was a challenge I couldn't resist, so I decided to build a movement controlled mouse using an arduino and a gyroscope chip.


A-Star 32U4 Micro - a tiny Arduino Leonardo clone

LSM9DS0 Breakout board - a combined gyroscope, accelerometer and magnetometer

A 3.3V to 5V logic level converter

10k resistor

push button switch

strip board

I started off prototyping with an Arduino Uno, and but it doesn't have the ability to be a HID controller at the same time as being able to load the firmware via USB. I tried reading the sensors via the serial port, but that's just not the same as a genuine mouse because you always need a client piece of software running, which isn't elegant, nor is it always convenient. However, the Arduino Leonardo does have the ability to act as a mouse or a keyboard, so I decided to use one of those. In fact, what i decided to use was a clone of that. There is a fantastic clone board called the A-Star 32U4 Micro, which is tiny - just 1" x 0.6", and it's half the price, so it's a winner all round for this project,

For the gyroscope, I chose the LSM9DS0 chip which is a combined gyroscope, accelerometer and magnetometer, giving me the choice of being a bit more sophisticated about detecting movement. I don't have the facility to make my own circuit boards or to surface mount chips, so I bought it on a breakout board.

The LSM9DS0 runs with 3.3V outputs, but the processor needs 5V inputs, so a logic level converter for the SCL and SDA lines is required too.

Finally, it's a good idea to be able to turn the mouse operation of the device on and off without unplugging it - that way if you make a mistake, you can re-program it without the mouse feature running wild.

Step 1: The Circuit

Picture of The Circuit

The easiest way to run the LSM9DS0 is on the I2C interface. That allows the microprocessor to talk to it over a simple serial interface, which has standard libraries. To do that, we wire the SDA and SCL pins to the SDA and SCL pins on the 32U4 board, via the logic level converter to change the signals from 3.3V to 5V.

You can periodically poll the LSM9DS0 for data, but to optimally know when there is data, there are three interupt outputs - one for each sensor. They also run at 3.3V, but that is high enough for the 32U4 to treat as a high signal, so there is no need to run those through the logic level converter.

Sparkfun have a fantastic writeup of all of this here;

The sketch shows the circuit, along with a push switch going to pin 11, with a 10k pull up resistor connected to 5V to stop the pin from floating.

I prototyped the solution on a breadboard first, as shown in the photo.

Step 2: The Code

The sparkfun guys have put together some sample code for using the LSM9DS0, as well as libraries for using the board;

After much pain, I found that there's a quirk in the LSM9DS0 which means that it doesn't always return all of the data that you expect it to, so use the attached libraries instead, where the issue is worked round. Without this, you can find the system hanging.

I used the sparkfun example code to get the gyroscope to move the mouse. I combine that with the readings from the accelerometer to detect what way the device is oriented, and translate that in to x and y movements for the mouse. You can find that code in the attached file.

The code expects the device to be on the right hand side of your head. If you want to have it on the left, invert the Y axis calculation, otherwise it will move the mouse down when your head moves up.

The LSM9DS0 doesn't start as fast as the processor, so the code pauses for 1s when it first starts to allow the sensors to come on line. Then I throw away the first 10 readings because the first readings seem to be less accurate.

The accelerometer seems to not say zero when it is stationary (movement of the earth perhaps?), so the code takes an average of readings 10 through 40 when you turn it on, and subtracts those from subsequent readings to make it stable. Make sure the mouse is stable when you plug it in for that reason.

The button is used to pause the mouse interaction, and when it starts again the stationary readings are taken again, so be sure to keep the device steady when starting it up - e.g. put it on the table.

To use the code, create a folder called SFE_LSM9DS0 underneath {install directory}/Adruino/libraries, and put SFE_LSM9DS0.cpp and SFE_LSM9DS0.h in that folder. Then you can open headMouse2.ino and load it to your Arduino.

Step 3: The Build

Picture of The Build

Next step is to solder it all up on a strip board. It's not as elegant as a custom built PCB, but I love strip board because it's always there ready to use for whatever you want, and you can tinker with it if it doesn't work. It's not particularly elegant (nor is my soldering), but it all works great.

Step 4: Packaging

Picture of Packaging

It's no fun having a bare circuit board strapped to your head, not to mention the risk of static, so it needs to be packaged in something. I considered a altoids tin, but metal isn't the best thing to put this in, plus it's large and uncomfortable. Fortunately, walking too far in new shoes resulted in me to emptying a plastic blister plaster box which was a perfect size for the circuit board (well, after I trimmed down the board with a dremel it was anyway). Plus, it was nice and smooth, and comfortable to have strapped to your head. I cut holes for the USB connector and the button, fixed the circuit board in to place with some sugru, and used a bit of leftover green sugru to make a matching green button top for the case.

I cut a couple of lines in the case and threaded a child's elastic belt through it as an ideal size for a head band, so the device can be comfortably worn on the head.

Step 5: Minecraft

Picture of Minecraft

So here it is in action. Crank up minecraft with a first person view, and as you look up and down, Steve looks up and down in the game. Look left and right, and Steve looks left and right. It's uncannily accurate, and brilliant fun to have your real life movements reflected in the game. If you look off the side of the screen, it re-centers when you move back to the middle, so to face a new direction, just move your head left or right past the edge of the screen and then back again.

Yes, you still need to use the mouse buttons to dig and build. Does that defeat the point of the head mouse? No, not at all. It's not about completely ditching the mouse - it's about a more immersive gaming experience.

Step 6: Disability Assistance

The other obvious use for a head mouse is for people with physical disabilities which prevent them from using a mouse. For people with limited mobility, this can be held or attached to any part of your body - move your head, your foot, your arm, anything. The sensitivity of movement can be adjusted in the code to suit any user too, and movements can be averaged to smooth out any body jitters.

The other essential addition for people with physical disabilities (as opposed to immersive gaming) is the need to click the mouse. The solution to that depends on the level of mobility of the user. For example, it's easy to add a foot controlled button that is connected to the Arduino, and call when that is pressed. When that is not an option, you can rely on "dwell" - i.e. when the mouse pointer has been in a particular area for a period of time, call The attached Arduino file does just that - it will look to see the total movement over the past second. If it has moved less than 20 pixels, it will click. If movement is over 20 pixels, it resets the timer. You can edit the file to change the radius that counts as stationary and the dwell time to suit the user.

Step 7: Conclusion

Adding a gyroscope to an Arduino Leonardo gives a huge number of options for controlling your computer. I had a load of fun building it (which, like with many instructables, was mostly the point). But if you think of any other good projects for this sensor, let me know in the comments.


MattiasBlomfeldt (author)2017-09-17

Hi. This is just what i need :) ( sorry for bad english im swedish ) . I work i n a kinderarden and have kids that need something like this. Is there eny chans to have 2 made for us? We kan pay for it. My email is

Hi Mattias,

I'm sorry, it was a one off for me. Perhaps there is a local Makers group who would like to help you build one?


DUMB009 (author)2016-12-16


I like your project besides i dont understand nothing about programming but im going to learn, to make one for me for sure :)

I have some questions because the button, when you talk that need for the project a push button switch, is a push button that when we only need to close one time the circuit to change, or it need to be closed with an button on/off switch to change?

And the button change from mouse to what?I dont understand the difference. Beside it work like the left mouse button when we stop the head and it press automatic to open, the reading of the movements to a computer of the axis are different? Or work different the head mouse in the movement of the head for the example you show in minecraft or in windows?

Best Regards

millmore (author)DUMB0092016-12-17

It's a push to make button - i.e. on when you press it, off when you let go. It allows you to enable and disable the mouse, and to re-center it when required.

Good luck with the build!


DUMB009 (author)millmore2017-08-10

I finish my building :)

But i already have a problem and i need Help because i unsderstand almost nothing about codes :)

When im trying to send the code into arduino clone it pops up an error in Line and cant send the code:

Mouse.move((averageX-dof.calcGyro(dof.gx))*dof.calcAccel( +(averageY-dof.calcGyro(*dof.calcAccel(dof.ay), averageZ-dof.calcGyro(dof.gz));

and said in the error:

´Mouse´ not find. Your Draft include the line´#include <Mouse.h>´?

C:\Users\OFICINA\AppData\Local\Temp\arduino_modified_sketch_913103\headMouse2.ino: In function ' void Setup() ':

headMouse2:177: error: ' Mouse ' is not found. The your draft includes the line ' <Mouse.h> ' #include?

Mouse. begin ();


C:\Users\OFICINA\AppData\Local\Temp\arduino_modified_sketch_913103\headMouse2.ino: In function ' void mouseMoveGyro () ':

headMouse2:277: error: ' Mouse ' is not found. The your draft includes the line ' <Mouse.h> ' #include?

Mouse move ((averageX-dof. calcGyro (dof. gx)) * dof. calcAccel (dof. ax) + (averageY-dof. calcGyro ( * dof. calcAccel (dof. ay), averageZ-dof. calcGyro (dof.gz));


Multiple libraries were found to «SFE_LSM9DS0. h»

Used: C:\Users\OFICINA\Documents\Arduino\libraries\SFE_LSM9DS0

Not used: C:\Program Files (x 86) \Arduino\libraries\SFE_LSM9DS0

exit status 1

' Mouse ' is not found. The your draft includes the line ' <Mouse.h> ' #include?

Whats happens with th mouse.

Can you Help me?

Best Regards

DUMB009 (author)DUMB0092017-08-18

I already solve the problem :)

And now its alive!

Great Project

YoyOA2 (author)2017-05-29

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

ParthT12 (author)2017-01-22

I cant found the same LSM9DS0 ic which you have used in your project what to do? please help

r-a-h-u-l (author)2017-01-17

hello sir,

its amazing work but I have problem how we find the value of gx,gy,gz,ax,ay,az as well as vx, vy, vz

SamuelL87 (author)2017-01-06

Nice work m8!

lagesamuel (author)SamuelL872017-01-11

Nice work m8

nourdiri (author)2016-12-18

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

NiqmatR (author)2016-10-16

Sketch uses 10,966 bytes (38%) of program storage space. Maximum is 28,672 bytes.

Global variables use 471 bytes (18%) of dynamic memory, leaving 2,089 bytes for local variables. Maximum is 2,560 bytes.

An error occurred while uploading the sketch

Got any solution??

ErwinE4 (author)2016-08-19

Excellent project Hello , I have a question estre microcontroller when connecting to a device android recognize it as HID ??

millmore (author)ErwinE42016-08-19

Yes, Android recognises it as a HID.It works as a mouse on your phone (requires a OTG USB cable)

ErwinE4 (author)millmore2016-08-24

I have managed to do this project with one and with transmission arduino bluetooth for pc, what I want is to use bluetooth android but also , any idea that can help me ?? thanks greetings.

SaedD (author)2016-04-24

Thank you very much for this helpful project!
but i wanna ask you something can i replace the LSMD9S0 with MPU-6050?

SaedD (author)SaedD2016-04-24

and if i can use the mpu6050 what should i do to replace the LSMd9s0 code?

belenofonte (author)2016-03-31

At first congratulations for the project its a great DIY project, i hope to make it in some days but maybe its posible to try attach with VR glasses to combine mouse head movement with the visual play screen. Its very cool for simulator games DCS, etc...

Could you see posible to include new movement, like zoom moving the head (back to front for example).

Thanks for your project!.

das1233444 (author)2016-03-03


can it be controlled wirelessly by bluetooth or xbee?

DaniloB1 (author)2015-10-31

amazing project!!!!

millmore (author)DaniloB12015-11-01


willus8888 (author)2015-10-05

G'Day Millmore fantastic project, i just have a few questions.

1. When turning the Head Mouse on it sometimes loads up with a 'drift' where it will just start slowly moving to one side of the screen until i reset it, is this a known cause?

2. The mouse seems try center itself on the screen every 10secs but actually just ends up jittering leaving myself unable to maintain a position on the screen. i suspect this is from the 'averageCount= 100;' line of code?

millmore (author)willus88882015-10-07

Hi. Yes, drift can be an issue with any gyroscope. It can happen if the device is not 100% stationary when you calibrate it, and it can happen over time.

The averageCount line is about removing jitter - if every measured movement was translated in to a mouse movement, it would move all over the place, so the averaging stops that. It shouldn't jump to the center of the screen though.

if your gyroscope is particularly jittery, you could increase the averaging.

millmore (author)millmore2015-10-08

I didn't use the magnetometer, because it wasn't as precise at measuring small movements as the gyroscope. You might find that you can get better results though - give it a go.

Yes, you can move the mouse to the other side - there are comments in the code for how to do that, in the mouseMoveGyro method. Basically change averageZ-dof.calcGyro(dof.gz) to dof.calcGyro(dof.gz)-averageZ

willus8888 (author)millmore2015-10-07

Cheers Millmore, I set this up on an 32u4 5v Pro Micro and Adafruit LSM9DS0 gyro. Another few questions (Sorry!);

1. Looking upon your code you don't use your Magnetometer to help get a more accurate reading any reason for this?

2. Is there anyway to alter the code so instead of having the device on the left or right side your head you can have it on the top of your head?

3. So the jittering tends to happen in the 1st 10 seconds of plugging it in, cursor is center of the screen and it'll jump about 1inch to the top left or bottom right corner, then again a few seconds after that and then again a few seconds after that and then it will stop. maybe it is my gyro but i will have to do more testing.

AshfakA (author)2015-08-08

Sir, i have bought a gy-521 with MPU-6050 in order to make this project.can it be done or i need to change the sensor???please help.

soapdude (author)2014-07-18

Awesome and simple project for the electronics beginner!
Do you have any tips or suggestions as how to reduce drag of the mouse? I often find myself having to move the mouse to the side or the top of the screen to readjust the location of the mouse with respect to my head! Thanks in advance!

millmore (author)soapdude2014-07-21

Yea, I know what you mean - it's the same as moving your mouse too far left or right - you need to pick the mouse up and move it back again. Not so easy to do with your head. One thing I did experiment with earlier on was having the direction of the mouse output as a serial stream from the arduino, and have a simple PC app to listen to that and turn it in to a mouse location on screen. It worked well and is immune to over pointing, but it needs the client side app to work, which I didn't like so much.

soapdude (author)millmore2015-08-05

So suuuuper late reply here, but could you possibly send me your code for this, or just a little more information on what you actually did?

Agatosh (author)2015-07-29

For everywhere else in the world who are using UNO and MEGA this is the alternative millmore was talking about:

This is not easy! It's better to invest in a A-Star 32U4 Micro

millmore (author)Agatosh2015-07-29

Very cool. Thanks for sharing.

aqibisl786 (author)2015-07-24

Anyone can please help me in connection part.

i have arduino Leonardo, MPU-9150 and logic level converter.

Thank you.!

aqibisl786 (author)2015-06-20

Awesome project. i wish to do same. soon i will start to build it your instruction as mentioned.

afenrir made it! (author)2015-06-15

First I tried it on Leonardo but it becomes too bulky that's Y I used micro made some changes in the code works like a charm

downeysyndrome (author)2015-05-27

Has anyone done this project, or something similar, using the MPU6050? I have been fiddling with it, but have not had too much success as of yet, and would appreciate some assistance.

ca6 (author)2015-04-05

i am using a sunfounder push button with three pins: gnd, +5v and signal, how would i set up the button?

ca6 (author)2015-03-26

what do i do with the headmouse2.ino code/file, i cant see it in this instructable

millmore (author)ca62015-03-27

That's the code that you need to load in to the Arduino. Download the arduino IDE from and install it, then create the directories I mention in Step 2 for the c++ code. Then open headMouse2.ino in the arduino IDE and connect your arduino to your computer using the usb cable, and in the IDE you can send the code to the arduino.

ca6 (author)millmore2015-03-27

so do i just copy and paste the code?

millmore (author)ca62015-03-29

Yes, that would work.

returner (author)2015-02-15

Sir i have a question, can i use an arduino mega for this project? will it still work?

millmore (author)returner2015-02-15

It's not quite as simple with a Mega because it can't act as a HID device without some fancy bootloader, whereas the Leonardo based devices can do natively. I believe it's technically possible, but I have never tried it.

sufiyan.muhammad.9 (author)2014-12-20

Dear Sir:

Its an excellent project. I am also working on a similar project called "Wireless inertial pointer". Its similar to a wireless mouse like the one you showed in your video but in my device I will be adding buttons for right and left click.

I am using arduino UNO and MPU 9150. I have combined the gyro data and accelerometer data using complimentary filter. Everything is working very well and I am also able to move the cursor on the screen but however it is not smooth enough and therefore doesn't acts like a pointer. I want my cursor(pointer) on screen to directly go to the point where I am projecting the device instead of going through the x and y axis values.

I hope my question is clear to you I will be very grateful if you can help me out. Following is my code that makes use of mouse.move method.

if(compAngleX > 90)

compAngleX = 90;

if(compAngleX <-90)

compAngleX = -90;

if(compAngleY > 95)

compAngleY = 95;

if(compAngleY <-95)

compAngleY = -95;

int x = map(compAngleY, -90, 90, -10, 10);

int y = map(compAngleX, -90, 90, -10, 10);


Thanks and Regards:


If you look at my code for running as a mouse with auto clicking (Step 6), you will see that I average over the last 100 readings. That's specifically to smooth out the movement. You should probably do the same.


Also Sir, I am facing problems with the yaw angle that I am getting using the magnetometer, even after removing the soft iron and hard iron errors. The yaw angle is not stable and changes significantly when the roll is changed (rotation along the x-axis). Can you please suggest what I can do about it. Would really appreciate your help. Thanks a lot!

To make the readings smooth and avoid jitters I have used complimentary filter. Which Sensor Fusion algorithm you have used ?


LeoB3 (author)2015-01-20

Great Tutorial, thanks!

I want to do the same thing, with my EDtracker (Sparkfun Micro Pro-with the GY-521 MPU6050 (no magnetometer)

Trying to make a 360 degree sensor for FPV games for use on my DIY Rift.

EDtracker comes with a sketch that emulates joysticks up to 180degree (90left, 90right etc..) I would like to make it 360 obviously, but should I just flash new sketches to turn it into an air mouse, like yours? Is that even possible? I'm completely new to Arduino and I have no coding experience.

Im assuming your code won't work with mine. Any suggestions?

millmore (author)LeoB32015-01-22

From what you say, I imagine that you'd be better off editing their code - it's designed specifically for that hardware. I really recommend learning to code - it's such a useful life skill, and there are some brilliant sites out there for beginners.

Anyway, I took a look at their code, and if you look at line 460-462, you will see the constraints they have added to limit it to 180 degrees;

I suspect that all you need to do is change those lines. But also, learn to code - it's easy, doesn't cost anything and opens up loads of new projects.

LeoB3 (author)millmore2015-01-22

Thanks very much for the response. I will try to learn to code, but it looks so alien to me. I wouldn't know where to begin. But yes, I would love to be able to.

About This Instructable




More by millmore:Slate House NumberHead Mouse - Game controller or disability aidRecover Shoe Polish
Add instructable to: