Introduction: Interfacing an Arduino With a Mouse Sensor (ADNS-3050)

The ADNS-3050 Optical Mouse sensor was an entry level gaming sensor when it first released. It featured a 2000 CPI resolution and none of the "acceleration" issues found with laser based sensors. A camera first takes a picture of the surface, then a second when it senses movement. The onboard DSP calculates the change in X and Y axis based on the two pictures. In this Instructable we will learn to interface with the sensor and read the Change in X (DELTA_X) and Change in Y(DELTA_Y) values.

The sensor itself can be found here:

And the repository here:


There is a small circle of kapton tape on the sensor, don't forget to remove it otherwise you will be wondering why it isn't sensing any movement.

Step 1: Wiring

First we must wire the sensor to the arduino. Nothing is required other than the Sensor and an arduino board. In this tutorial I will focus on the ICSP header (the 6 pins all by themselves) on the leonardo but I will also post the connections for the UNO without the ICSP header also.The leonardo only has access to the necessary pins through the ICSP header while the uno can use other pins in addition to the ICSP header.

Leonardo Connections

VIN -- VCC~5v

3.3v -- Optional, connect 3.3v for power instead of 5v.

GND -- Ground




NCS -- 3 (any pin you want can be changed later, default is 3)

UNO Connections

MOSI -- 11,

MISO -- 12,

SCLK -- 13,

NCS -- 3 (any pin you want can be changed later, default is 3)

If the power is connected correctly, the LED should flash continuously and if you put the lens up to it and move around some it should get brighter. This is it's built in lift off detection algorithm at work. If the sensor believes it is no longer on a surface it will conserve power by dimming the LED. We will test all the connections in the next step.

Step 2: Testing Communication

Next we need to test and make sure the arduino can communicate with the sensor. We can do this by loading up an already made sketch named ADNS_Communication_Test and the ADNS3050.h library (make sure adns3050.h is in the same folder as the sketch).

Open it with the Arduino IDE then upload it to your arduino. Then go to Tools --> Serial Monitor. After you open the serial monitor go to the bottom right and set the baud rate to 115200.

If all went well then it should display:

Communication Successful


The 9 is the value in the product ID register of the sensor. 9 is the correct value, so a 9 here means it is working correctly. If you get something else then you need to double check the wiring.

Step 3: Getting Data

To setup a test sketch running for getting data is easy, just load up ADNS_Serial_Example along with the library. The arduino will print out the change in x and y values in the serial monitor. Higher values mean faster movement, 0 means no movement.

To use the library with your own programs just call the startup function when the arduino turns on , then call getX() and getY() consecutively to get the DeltaX and DeltaY (don't read or write anything to the sensor, storing the values in a variable is fine though).

I also included a Read() and Write() function to make customizing the sensor easy. You can change the resolution setting, LED power and many other things using those two functions. I have attached the full datasheet for the sensor which should help.

Read()- To read , just supply the address, so for example if you want to read register 0 (0x00 in hex) just use Read(0x00)

Write- To write, supply the register and the data to be written(8 bit value) for example, to write 0x02 to register 0x00 use, Write(0x00,0x02)