optical encoders

Hi All,

I’m trying to find an optical linear reflective encoder to measure direction and speed of a moving surface, but not having much luck.

Does anyone have any useful tips?


If the surface is relatively smooth you can use the guts of an optical mouse. You can find the mouse interface code in the playground, and a tutorial here: http://www.martijnthe.nl/optimouse/arduino-optical-mouse.html

It won't work with all usb mice but most that are PS2 compatible should be ok.

I have used Bourns optical shaft encoders.. you can get them at Digikey. About 50 bucks, but guaranteed to work out of the box.

Bourns ENA1J-B28-L00064L-ND



Hi mem

Thanks for the links.

I've bought a mouse from maplin and tried to get it working without success. I doesn't seem to have serial pins.

Here is the datasheet: http://www.pixart.com.tw/upload/PAW3502DL_SPEC_V11_20080418172013.pdf

And an image:

By process of elimination, I think the data pins must be either 4 & 7 or 8 & 9.

Do you have any thoughts?

I connected the 5v and grnd to the arduino, and the light on the mouse flickers on and off at a constant rate. It seems to be missing something to regulate the power to the led by just using 5v & grnd.

hmm, there is no mention in the datasheet for support for legacy PS2 mode and the sample code I linked to needs that. Your chip looks like it uses the more complex HID USB protocol and I don't know if anyone has implemented that for the Arduino.

Did the mouse come with an adapter that allows it to plug into the mini din type round mouse connector? Does it say anything about use on a PS2 mouse port? If not, it may be easier to find another USB mouse that does work on legacy PS2 ports than the try and get yours going. Maplin should exchange it or give you your money back if its still in as new condition.

Yes, I just picked up a £6 usb mouse thinking it would be ok. Didn't realise I need an optical ps2 mouse. Darn. Will have to get one another day.

Not new anymore, I've cut the guts and cable up :)


Well if its already cut up you might as well have a play with it and see if you can get it to work. It looks like the data is on 8 & 9. You will need pull-up resistors to make access the data, I don't know if the test code enables pull-ups (you write a high value to an arduino port set as an input) but its worth checking the code to see if pull-ups are enabled.

I have this green adaptor with USB female and PS2 male... it is supposed to make a USB mouse working in a PS2 plug... does this could help to have a USB mouse be interfaced with Arduino ??

hi Olivar, if the adapter came with the mouse then it's a good chance that mouse will work with the arduino PS2 mouse code. The adapter just converts the physical connections, it does not have any USB logic, so the mouse itself needs to be able to work in legacy PS2 to function with the Arduino PS2 mouse code.

I am making a project of Optical Position Encoder with Arduino but I am having a doubt that how to encode the arduino and how to install the libraries also how to do coding of attached LCD with it?