Skip to content


Accelerometer Based Mouse

100 0562Bernard shows us how to use an use an accelerometer as a mouse. This project uses a MEMS X/Y accelerometer, a PIC microcontroller and a old mouse. He also describes a trick for powering the new mouse with the unused RS232 serial control lines.

This article was submitted by Bernard Klinc as part of the “Hobby parts for articles” program. Bernard did not need the Arduino kit so we sent him an 2×16 LCD display for this great article.

Update: Bernard has done a video showing the mouse in operation. Check it out after the jump.

100 0142This project demonstrates the use of a accelerometer as a computer mouse, but first what is an accelerometer? Its a device that can measure acceleration and the pull of gravity. There are multiple ways of doing this, the particular one I’m using works with the capacitive method. Inside the chip is a capacitor with an extra plate in the middle that can move. As you know the closer the objects are together the bigger the capacitance, the circuit inside the chip measures the capacitance difference between the two plates and the middle one. Finally the circuit coverts this in to a analog signal between 0V and 3.3V. All of this is small enough to fit in to a small SMD chip.

The accelerometer used in this project is MMA6270 manufactured by Freescale Semiconductor. It has two sensors inside the chip, each facing at 90° to each other providing the X and Y axis. This is perfect for a mouse. In this case we are using it to detect the angle of the mouse. When the mouse is completely horizontal bough X and Y have 0G applied to them, but when we tilt the mouse the gravitational pull starts to cause force on the axis. But we wanted to move the mouse cursor using this. So we put on a PIC microcontroller, connect all the outputs to the ADCs and send the data over to the PC.

100 0157To mount this part I soldered short leads to each of the necessary pints. These short wires then could be soldered into my final project or an adaptor as seen on the breadboard below.

100 0075

Testing started on the breadboard, It has proven to work pretty good. Later on I tried to make it wireless but the 433 MHz modules I had were not fast or reliable enough. It did work, but not very good, so I decided to go back to a cable. I used a Visual Basic program on the PC as the driver for the mouse because I was too lazy to make it compatible with a standard COM port mouse. Making it work as a normal mouse could be done easily.

scheme

The next problem is power, How to power the circuit since the com port doesn’t have a power supply line. The solution are the flow control lines on the COM port. Several control outputs are available as they are used by old COM port mice and keyboards. Windows puts these lines to high during the boot up, if the mouse doesn’t properly respond in a few seconds it puts those lines back to low. About 10mA of current can be pulled from these pins. But still it’s not solved yet the voltages on the com port are around 8V to 13V and are current limited. My solution was to tie several of the unused control lines directly to a blue LED witch clips it to about 3,4V. This is perfect since we need 3.3V for our accelerometer and the PIC has no problem running on 3.3V. I had doubts in the MAX232 but it turned out to work fine.

mikrobasic1

With the PIC and a small program we can sense the angle using the accelerometer to detect gravity and send the measurements to the PC. I used an old mouse and wired directly to the mouse button to get the click signal. I had to cut the traces on these buttons as the original mouse chip was interfering.

100 0564Here is my finished accelerometer based mouse! Check out the video of it in operation below.

Posted in Microcontroller, Projects.


26 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Kevin says

    Hi berni,
    I noticed that the picture and the schematic do not match at all. Is yours just a different version of the circuitry on the schematic? do both work fine?

  2. Hessam says

    Hello i was just wondering if the accelerometer has any connection to the mouse and if possible can you send me a picture of the back.

  3. andershen says

    hi, berni, can your pointer mouse use as a normal desktop mouse?

    Thanks.

  4. Mahavir says

    Hey berni,

    i made it wireless with range of 50 meters using CYWM 6935 module & made it to work like real mouse with some additional filtering & noise removal…

    check it out on coepetc.blogspot.com

  5. lukas Pl says

    Very nice work. Greetings from Poland…

  6. Berni says

    put it flat on the table when you start the program

  7. Lies says

    Hi !
    How do you do to remove the drifting in the position do to the gravity ?

  8. Bhaskar says

    Hey,
    Ive done the above circuit. But what should i do next? does the above circuit only work for 1 specific game? or only games in general?

    does it work as a normal desktop mouse? berni pls explain the procedure to be followed after the circuit is ready, asap

    pls reply asap

  9. t1000x says

    hello Berni,

    i saw a project from a website;www.weavefuture.com. I studied all the details, pictures, informations and already downloaded all the softwares needed from the site. I started to gather the materials to test the project, but its only a local parts I got. A PC, a coin selector HI-06cs, a timer circuit using ATMEL 89C51 which is really different from WEAVE FUTURE cos it doesnt have an RS232 connector terminal. I just assumed that pin 10 (RXD) and pin 11(TXD) of 89C51 were directly connected to pin2 and pin3 of RS232 terminal. So i got an old SERIAL MOUSE (RS232), cut its wire, and configure the color wirings according to its pin # connection. then i connect it to pin 10 and 11 of 89C51 in accordance to pin terminal of RS232. I followed the instruction in WEAVEFUTURE on how to install the software, but when i test my project, i was upset The software was not responding, but my timer counts. I assumed that my idea in this project was missing something like additional circuits or programs.

  10. Nikki says

    Berni, I was wondering if you could help me simulate the conversion from the accelerometer signal to mouse cursor movement in Labview. I am trying to take the accelerometer signal have it emulate that original mouse movement. Thanks.

  11. Berni says

    By tweaking the code you can make windows detect it as a real mouse at boot up. You do this by sending the right response when one of the flow control lines goes high.Also if you used a PIC18F2550 you could even make it USB.

    Well the above circuit worked for me.

  12. bhaskar says

    hey can someone tell me if the above circuit is 100%correct? we are about to start the hardware part of this circuit.. pls do reply asap

  13. dfowler says

    Nikki,

    Seems like you could talk Bernard’s design and use it for a head controlled mouse. I think making it act like a real mouse is a good idea. Maybe you could use a real mouse and fake the ball position encoders with the uC. They way you only need to simulate the signals from the optical sensors which detect the mouse ball motion. The old mouse guts would not know the diff and act like a mouse, taking care of the PC mouse interfacing.

  14. Nikki says

    Hi, i was wondering if you could help me understand something. I am trying to build a hands free mouse using head tracking. I want to do this using an accelerometer. The one I have is an ADXL202 produced by analog devices. I want to use a regular mouse controller in order to read the X and Y movements from the accelerometer, however I don’t really have to much time for program. From you knowledge is there another way to get the outputs of the accelerometer to mimic that of a regular mouse for x and y. Thanks.

  15. vineeth adolph says

    how did u soldered ur accelerometer ic, isn’t it very small

  16. jj says

    well work done…..
    but i want to use a mouse for the coordinate measurement…. is it possible.???
    if any one have any idea kindly reply me….
    thanx…

  17. Berni says

    Its not accurate enough for that

  18. XE says

    Ger8 work dude! why dont u use accelerometers to get position (x,y not tilt), and use it as a regular mice on a surface?

    i’m working on Three-Dimensional Position Detection System Based On MEMS Accelerometers,..but i’m some how stuck!

  19. ashish says

    it seems to be a great project

  20. Berni says

    Yes it is completely possible. But finding a way to read the sensor may prove hard, especially from Java.

  21. Sebastian says

    I don’t know if it is possible, but what about using the source code to make it into a program for my nokia n95 (that has an accelerometer chip embedded inside it). People have been LONG asking for something like this and the developer would gain some popularity! Please email me back if it is possible

  22. Berni says

    It is sent

  23. AlexB says

    @Berni
    Thanks!

  24. Berni says

    Well i can compile it for you and send it to your by mail

  25. AlexB says

    Awesome!
    I Would like to try to build a mouse but i don’t have the visual basic to compile the test program…
    Where I can find a compiled version !?
    thanks in advance!

  26. 2f1c says

    great work

    i had the same problem when trying to use a similair MEMS from freescale (the xyz acc) regarding soldering, i thought for a while that is impossible without having appropriate tools to do that

    thanks for the tips, i will give it a try (again)

    cheers (: