Instructables

Head Mouse - Game controller or disability aid

FeaturedContest Winner
Picture of Head Mouse - Game controller or disability aid
IMAG0196.jpg

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.

Components

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.

 
Remove these adsRemove these ads by Signing Up
1-40 of 120Next »

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);

Mouse.move(x,y,0);

Thanks and Regards:

sufiyan.

millmore (author)  sufiyan.muhammad.921 hours ago
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.

Martin
aca705 days ago

Hello, I still cant get the code to work and been reading all the comments. Is there any way you can do a quick video on the code?

millmore (author)  aca703 days ago
What doesn't work about it for you?
tmalau26 days ago

Cool, i have made this one with LSM9D40 and A-Star 32U4 Pro Micro sparkfun 3,3V/8MHz and it's works. thanks

Now, i'm gonna going for mouseclick

IMG_4789.JPG
millmore (author)  tmalau26 days ago
Great. Well done!
tmalau27 days ago

finally i got this problem:

headMouse2.ino.ino: In function 'void setup()':

headMouse2.ino.ino:163: error: 'Mouse' was not declared in this scope

headMouse2.ino.ino: In function 'void mouseMoveGyro()':

headMouse2.ino.ino:263: error: 'Mouse' was not declared in this scope

i hope u can reply my comment thanks. I use a star with 3,3 v/8Mhz

millmore (author)  tmalau27 days ago

Not all aruinos support Mouse - only the Leonardo and ones based on that (such as the A-Star 32U4 Micro). If you pick the wrong device in the arduino IDE, it won't compile as it won't find that library. Make sure you install your hardware drivers and pick the right device in Tools->Board.

tmalau millmore27 days ago

thanks for reply, i found solution of my problem.

https://learn.sparkfun.com/tutorials/pro-micro--fi...

I use pro micro 32U4, sparkfun board. I think i can use 2 board ( A-star 32U4 pro micro and LSM9DS0) to make it, with out converter. I hope your kindness can help me. Wish me luck

tmalau millmore27 days ago

thanks for reply, i found solution of my problem.

https://learn.sparkfun.com/tutorials/pro-micro--fi...

I use pro micro 32U4, sparkfun board. I think i can use 2 board ( A-star 32U4 pro micro and LSM9DS0) to make it, with out converter. I hope your kindness can help me. Wish me luck

Eureka! Thank you so much!
IMG_20141123_043222_849.jpg
millmore (author)  kelin.wheeler28 days ago

Brilliant, glad you got it working!

Hey, excellent project. I've built the circuit but an having an issue with the sketch. I'm admittedly better with soldering than software, so any help would be appreciated. the error i'm getting seems to be all about the LSM9DSO constructor, it reads:

LSM9DSO:83: error: 'LSM9DS0' does not name a type

LSM9DSO.ino: In function 'void setup()':

LSM9DSO:130: error: 'dof' was not declared in this scope

LSM9DSO.ino: In function 'void mouseMoveGyro()':

LSM9DSO:258: error: 'dof' was not declared in this scope

LSM9DSO.ino: In function 'void recordAverageGyro()':

LSM9DSO:270: error: 'dof' was not declared in this scope

any guess as to what i've done wrong?

millmore (author)  kelin.wheeler1 month ago
Did you include the library files SFE_LSM9DS0.cpp and SFE_LSM9DS0.h? See the end of step 2 for the instructions to do that.

thanks for replying, I'm sure this is a simple fix. I have, they are under Mydocuments>Arduino>Libraries>SFE_LSM9DSO

and under that is my headmouse2 folder, containing headmouse2.ino

millmore (author)  kelin.wheeler29 days ago

When you go to Sketch -> Import Library in the Arduino software, you should see SFE_LSM9DSO. If you don't, you haven't installed it right. headmouse2 doesn't need to be below the library folder - in fact it would be unusual for it to be.

EddieLearner2 months ago

Hi! Great project!

I'm trying to make this project with an added feature, making it wireless. Any suggestions and recommendations?
Also A-Star is not available in our country. Can I use Fio v3 or Pro Micro?

millmore (author)  EddieLearner2 months ago

You could turn it in to a bluetooth mouse using a BlueSMiRF. I found a good tutorial for that here;

http://www.kobakant.at/DIY/?p=3310

Yes, you can undoubtedly use a different arduino compatible board. I chose the A-Star because it is small and could act as a HID, but if you are using the BlueSMiRF, it will be the HID, not the arduino, so you have more options.

tmalau millmore1 month ago

sir, i have try to make this project, it's so great. But i have questions

1. Can i change that USB cable with bluetooth module? Have u try this one?

2. How to make right click and left click mouse?

Thanks for ur tutorial, it's help to make project as a gift for disability school.

millmore (author)  tmalau1 month ago

You could turn it in to a bluetooth mouse using a BlueSMiRF. I found a good tutorial for that here;

http://www.kobakant.at/DIY/?p=3310

If you look at step 6 of the instructable it shows code for doing a click on dwell - i.e. staying still for a while. You could probably detect other motion to select between left and right click if desired, e.g. looking top left sets it to left click, and looking top right sets it to right click. Should be pretty easy to program it to do that.

Thanks for your great suggestion!

If I were to use the BlueSmirf HID, I can use any Arduino(w/ or w/o HID support). Is that right?
Also, if I were to use this item, will the code be very different? Or just some minor tweaks?

millmore (author)  EddieLearner2 months ago

I've not tried it myself, but yes, I suspect you could use any arduino.

The code that calls Mouse.move would need to be changed to make the bluetooth HID calls.

aminabazari2 months ago

HI.Thanks for your great project

I cant find

A-Star 32U4 Micro

LSM9DS0 Breakout board

then I have to use pro micro 5V/16MHz and ADXL345

ADXL345 registers is very different , what can I do for program it?

millmore (author) 3 months ago
It's certainly not the only multi-sensor out there that is arduino compatible, but I haven't found any others that work well. I did try a GY-521 Module MPU-6050, and didn't have a lot of luck - it wasn't very stable. But others might work better.

pls sir help me do this project with MPU-6050(combined gyro and accel).. im new to the aurduino world and i don't know how to write code's for aurduino..pls help me....

if any code available(it may not work better).. pls send me sir...

millmore (author)  chassisdeepak2 months ago

There's a good article on that here;

http://playground.arduino.cc/Main/MPU-6050

chassisdeepak2 months ago

pls sir help me do this project with MPU-6050(combined gyro and accel).. im new to the aurduino world and i don't know how to write code's for aurduino..pls help me....

tmalau3 months ago

great,

I have a problem with LSM9DS0, can i change with my

GY-88 Motion Sensor 10-DOF (Accellerator+Gyroscope+Barometer+Magnometer)

millmore (author)  tmalau3 months ago
I haven't tried it myself, but I imagine you could.

Just out of interest, what problem did you have?
tmalau millmore3 months ago

i cant find LSM9DS0 on my country (Indonesia). But i'm still trying to find it. Do you have an opinion what i can use to change LSM9DS0. It could be nice. Thanks for ur replay

SiddheshA3 months ago

Instead of the A-Star 32U4 clone I'd like to use the original Arduino leonardo. What changes will i need to make now?

I successfully made it with a Leonardo, and needed no changes. The pin numbers are even the same as the clone board!

Could you if possible send me the pin diagrams of your circuit? As somebody with no previous experience of Arduino or breakout boards I'm having a lot of problem making this device. Email ID: siddhu994@gmail.com

Hi SiddheshA, here's a diagram of the circuit with the Leonardo. One thing that my son and I tripped up on was forgetting to connect the 3.3v output from the Arduino to the connection running between LU on the logic board and VDD (3.3v) on the breakout board. I also has a problem initially with my solder joints on the breakout board -- I had cold solder joints (Dull, not shiny, didn't flow nicely down to the pin collar) and the board wouldn't respond to any of the test scripts. Check those solder points! Good luck!

Screen Shot 2014-09-06 at 18.44.07.jpg
millmore (author)  SiddheshA3 months ago
I don't believe you'd need to make any programming changes to make it work. The board is much bigger, so you'll need a bigger case, and you'll need to build a shield for the sensor and logic level converter to plug in to it rather than PCB mounting everything.

The reason I didn't do this is that the end result will be significantly bigger (twice as long, three times wider, twice as thick), and more expensive. Obviously if you have one lying around it makes sense, but otherwise it's not the best plan.

I'm a third year Engineering student in Mumbai and I have chosen this as my project topic. As interesting as i find this, the problem is i have absolutely zero experience with Arduino programming and using any kind of breakout board. Will it all still work if i simply follow your instructions? Or can you please provide me further details about the things i need to take care of as a newbie on using these boards? Any kind of help will be hugely appreciated :)

fox494 months ago

Excellent project!!!

For
the clicks, I don't know if it has been said before but an idea: you can
use the sound propagated through the skull of a chock between the teeth.

millmore (author)  fox494 months ago
That's a really interesting idea, You could probably distinguish between single clicks and double clicks pretty easily too if you are listening for sound.
fox49 millmore4 months ago
Any idear for the sensor?

This is for sound to ear :
http://www.noliac.com/Conduct_sound_through_bones_of_skull-8078.aspx
but i think a simillar system can be used. (in France soldiers are using a skull bones comunication device that detect vibration of the skull by the speaking soldier and make skull vibrate for the listening soldier. I think it's the same device that do both functions)
DanielH14 months ago

excellent project, has helped me a lot, do you possible this mouse communicates with a board whose system is android think?

1-40 of 120Next »