Resman says hi.

Optical Mouse Cam

OK, so I finally decided to get my hands on the Arduino platform and see what all the buzz is really about. And I must say, I'm impressed. This is by far the most developer-friendly development platform I've ever seen. It's main advantages :

So, a while ago I came across this great optical mouse hack by Sprite. I decided it would be great to do as my first Arduino project (beyond the "Blinky LED" example, that is.)

First step, dissection of a wireless mouse from a cheap Typhoon wireless mouse / keyboard combo.

Mouse

Unscrew it. Look for screws under the pads and stickers on the bottom.

Mouse open

My model came with two PCBs which are coupled using a 14 pins, two rows header :

first PCB removed

The unusual looking chip in the middle is an ADNS-2051 optical sensor. This chip holds a 16x16, 64 levels of gray image sensor and a DSP which computes movements from the optical flow of the captured images :

PCB top PCB bottom

Underneath the second PCB is the optical bloc with lens and LED collimator :

Optical bloc

Better view of the optics. It was manufactured by Agilent technologies or its spinoff Avago technologies :

Optical bloc

Agilent/Avago provides the optical block, motion sensor and LED assembly of most optical mice. Here's how everything stacks up :

Exploded view

OK, so going this far was not really necessary, I just like to see how things are made and to take macro shots of it :-) Going back to the ADNS-2051 chip and the Arduino, you need to make the following connections :

ADNS-2051 pinout
ADNS-2051 pinArduino pin
1 SCLKDigital 2
16 SDIODigital 3
15 PDDigital 4
13 VDD+5V
12 GNDGND

All the other pins should have the required circuitry already on board, so they need not be touched. In my case however I had to wire the LED, too, since it was not directly wired to VCC but switched on by the controller. This is because it was a wireless mouse build with a chip intended for a corded design, so they had to diverge a bit from the reference design. I was lucky, the sensor board had a female header which I could use to wire everything, so I did not have to solder anything. But you probably will.

Setup
Ignore the prototype board on top of the Arduino, you can wire everything directly to the Arduino headers.

You can download the Arduino script and the PC program below. The program is in java and requires the RXTX library to be installed. You need to get the "RXTX 2.1 for use withOUT Sun's CommAPI (namespace gnu.io)" version. No, as of 2008 java still does not natively support the serial port. It should work with Linux, Mac OS X and Windows, but I only tested it under Windows.

[Addendum: RXTX seems to have been discontinued and the website is now a blank page. I suggest using PureJavaComm instead, it works great and does not require to be installed directly in the JRE. The project may need to be modified a bit to adapt it to this library.]

Once RXTX has been installed you can run the jar file simply by double-clicking on it or in the command line like this :

java -jar mousecam.jar

The window will show up. Simply select the serial port your Arduino board is connected to and click Connect. The sensor data will be drawn on screen in real time. You can increase or lower the number of lines to read from the sensor in each run. The frame dump routines are a bit slow so if you dump a full frame you'll get only about 5 fps. If you're moving the mouse at the same time, there will be severe shearing artifacts and the scan will not look pretty. In this case, reduce the capture window to 2 or 3 lines.

Application window

If you move the mouse while the application runs you can "scan" the surface below it. As you can see the quality is unmatched. You need to keep the mouse orientation exactly the same while scanning since there is no way to detect rotations, and this distorts the capture even more.

Here's how a white sheet of paper, the fabric from my pants and the small print on a 20 euro bill are seen by the sensor :

White paper Fabric 20 Euro bill

Alright, what else can we do with this very nice sensor ? Looking at the datasheet something struck my eye : the sensor is sensitive in a wide range of wavelenghts, from ultraviolet to infrared. So why not replace the standard red LED by an RGB LED ? :-)

Sensor sensitivity RGB LED RGB LED installed

I skip all the gory details, here's the not so impressive result :

RGB application

I was attempting to scan a detail of a 20 euro bill. I've had several issues with the sensor when switching between diferent colors. The sensor would be nearly saturated or very dark on the border of the frames. I solved the problem by adding a 100ms delay after each color change so that the sensor could adapt. Another issue is that the sensor seems to use some kind of automatic aperture control, which makes it impossible to balance the colors. Below is what the same detail looks like with a "real" camera. We can kinda recognize the blue lines :-)

Actual detail

If you wish to reproduce this amazing result (who wouldn't ?), you need to do the following :

Further information :

OK, enough time wasted on this already ! :-)


Share this article :

Comments

Comment left by Sinan on 2014-07-24 08:18:18 :
I'm trying to do this project using PAW3305DK. However I have some problems about communicating with it. When I checked the datasheet I couldn't find anything can help. Do you have any suggestion?
Reply from the author :
From a quick glance at the datasheet it looks like this chip uses an open drain SPI interface, make sure to connect a pull-up resistor between the SDIO line and Vcc. I don't see any command to read the image data, however.
Comment left by Someone on 2014-05-19 21:59:18 :
Update links because i cant find the files for it. And give an example on how to install the RXTX x64 please.
Comment left by SOMANSHU MEHTA on 2014-05-09 20:08:09 :
Cannot download RXTX library.I have the latest java version.Do you have any mirrors for that.
Reply from the author :
The RXTX website seems to have been replaced by some kind of generic parking crap. Try using PureJavaComm instead.
Comment left by shtface on 2013-11-29 13:39:24 :
the fact that you can actualy take photos is amazing
Comment left by boo on 2013-07-06 11:42:05 :
hi we are using zippys mouse suddenly what happen means the cable get separated from mouse so in that cable is having 4 wires one is (1)red (2)green (3)black and (4)white so which colour wire have to connect to which wire .in that mother board their is (1)gnd (2)v dd (3) data (4)clock so please how to connect the wires tell me as soon as possible kindly do a mail to my id is bozluangkhot@gmail.com
Comment left by Andre on 2013-05-30 08:46:02 :
Nice idea using RGB LEDs.

This would make a very nice microscope for imaging cells, you could use multiple LEDs such as infrared red orange yellow green blue violet and then make a composite hyperspectral image.
Comment left by inspiritus on 2013-03-20 11:51:35 :
hmm Can't download RXTX library? have Java 7 update17. mousecam.jar doesn't work > what is wrong :(
Comment left by Marvin Gascon on 2013-02-16 11:24:31 :
my mouse don't have a PD pin ? it haS the following pins---> 1=Vss, 2=Z1, 3=Z2, 4=L, 5=M, 6=R, 7=OPT, 8=LED, 9=D-/DATA, 10=D+/CLK, 11=AVDD, 12=VDD5V,,, the ic number is A2636....can you help me??
Comment left by rand3289 on 2013-02-15 16:11:47 :
This project is very interesting from the following perspective: Imagine a bunch of optical fibers running from an LED to sensors. Sensors dim the light using cheap mechanical components. This is similar to optical encoders. Dimmed light from sensors is tunneled using same type of optical fiber into a regular web cam. One of the problems with this idea is that 30fps web cams might not give you the sensor update frequency desired. As an alternative, there are optical mouse sensors. For example ADNS-3080 has a 30x30 image sensor with 2000-6469 frames/second rate!
Comment left by Jon Froehlich on 2012-11-21 20:32:14 :
Thanks for posting this. A student used this idea to help build a rope measurement hardware prototype for climbers: http://cmsc838f-f12.wikispaces.com/Assignment3_Darren_Cheng_Rope_Measure
Comment left by jon on 2012-11-13 14:28:58 :
kaya Likha Samaj MA nahi aya ra bal Thik Sa lik na ra sal;a
Comment left by Mikael Danielsson on 2012-09-28 19:29:25 :
Where did you get the pinout for the chip?
Comment left by Mikael on 2012-08-23 17:32:27 :
For all of those wondering wether you may use the H2000-chip (HDNS-2000), I must tell you that this chip have no sophisticated output as the one mentioned in this article. The HDNS-2000 have only PS/2 and quadrature output, thus handling all the image data internall. Sadly. This chip is very common, I've opened up many mice in hope of obtaining one to use for this purpose, but most of times found this chip.
Comment left by ashirviskas on 2012-08-01 14:25:32 :
can i use h2000 sensor?
Comment left by Issac on 2012-03-23 09:38:31 :
i dnt have a PD opition in A2610 Sensor what can i do ...to start of with java i have no clue i am a beginner need help.
Comment left by daianhtai2007@gmail.com on 2011-11-27 08:59:53 :
Can you give me code of Arduino about get coordinate x,y by usb mouse ,such as:
http://www.martijnthe.nl/2009/07/interfacing-an-optical-mouse-sensor-to-your-arduino/

But i only have PAN3204 can you write for me this ic library.
Thanks a lot.
Comment left by Sylfranc on 2011-07-28 13:28:58 :
Thank you very much for this page.

For additional information:
The code works perfectly with a sensor with S2099 mark recovered from an old logitech optical mouse.
The only differences are the supply of 3.3V and the identification code returned 03 instead of 02.

A picture with comments
http://cjoint.com/11ju/AGCnufkqMFp_OPTS2099.jpg
Sylvain
Comment left by Ed Xavier on 2011-04-29 08:56:13 :
Incredibly useful information. What started as a question regarding how the optical sensor worked has turned into a desire to incorporate a hacked mouse into various projects for members of my group. Your work is genuinely appreciated.
Comment left by BioCleaner on 2011-03-01 20:37:29 :
Hello! Your article helped a lot but i only have a mouse with a N1165 sensor and I can't find the datasheet. Have you ever hear of this kind of sensor? Should I try soldering it the same way as the ADNS2051?
Thanks!
Comment left by Mamad Agig on 2011-02-08 12:10:47 :
Hi,thanks for your great article
I have question:if i want to do this project with another mouse what changes should i apply?email me please
mamadagig@hotmail.com
Comment left by sikkuno on 2010-11-24 15:17:45 :
@^ you can't do this with your mouse's usb wires. You have to wire direct to the chip outputs on the board because the external cable is the usb interface. The red black green and red wires are USB power D- D+ and ground.

Very cool post by the way! I did not realize that an optical mouse takes screenshots and moves based on the difference. I would be interested in learning more about the algorithm to know the direction of movement.
Comment left by sikku on 2010-10-07 09:34:05 :
hi we are using zippys mouse suddenly what happen means the cable get separated from mouse so in that cable is having 4 wires one is (1)red (2)green (3)black and (4)white so which colour wire have to connect to which wire .in that mother board their is (1)gnd (2)v dd (3) data (4)clock so please how to connect the wires tell me as soon as possible kindly do a mail to my id is : honey4530@yahoo.com
Add a new comment :
Name :
Comment :

Answer the following question : Which is the smallest, two or seven ?