from: http://www.martijnthe.nl/
In this tutorial I'll describe how you can connect the optical sensor inside a cheap mouse to your Arduino and have it read out the x- and y-movements. This will enable your Arduino to handle mouse input, detect surface movements, measure surface speed, etc.
This is what you need:
The optical sensor and LED were covered with the black protective cap. Take it off carefully.
Check out the datasheet of the sensor you're dealing with (Google).We only need to connect 4 pins of the sensor to the Arduino, of which two are used for data and two for the power supply. The sensor uses bi-directional serial communcation over one data line (SDIO, pin 3). The second data pin (SCLK, pin 4) is used to time the bits. In case of a different type of sensor, the pin numbers might be different.
To make sure the mouse's own controller does not interfere with the Arduino, I had cut the SDIO and SCLK wires running to the chip in the mouse. I'm not sure whether this is really necessary, so you might try first without cutting them.
Solder wires to the four legs of the sensor that I indicated above. The +5V should go to the 5V Power pin on the Arduino, the GND should go to the GND Power pin on the Arduino. Pretty straightforward. Connect the SCLK to Arduino digital pin 2 and SDIO to Arduino digital pin 3. (You are free to use other pins as well, but in this tutorial I'm using pin 2 and 3.)
Download this .zip package with the library and example sketches. Expand the archive and move it into:
arduino-0010/hardware/libraries/
Restart the Arduino IDE. The examples should appear in File > Sketchbook > Examples > Library-OptiMouse. Open the Coordinates example and upload it to your Arduino board. Start Arduino's serial monitor (38400 baud) to see the coordinates of your mouse coming in... Done!
2008-11-18 : Added some support for the ADNS-2083
2009-01-30 : Fixed compatibility issue with Arduino 0012 (Thanks Mark for notifying me.)
This tutorial is based on Benoît Rousseau's example on the Arduino Forum. I just wrapped his functions inside a library. If you have suggestions for improvements of this tutorial or the library, feel free to mail me: post [at] martijnthe [dot] nl.