PDA

View Full Version : Using the optical sensor from a ball mouse



lsteele
- 5th September 2007, 09:14
Hello,

I'm trying to use the optical encoder from a ball mouse to make a cheap quadrature encoder for an electric motor.

I've removed the part of the PCB with the LED and sensor, and wired them up the same way as the mouse. The sensor has three pins - +5V and two outputs. I've connected the outputs to ground via a 20K resistor and hooked up the 5V pin to my power supply. If I then measure the output from one of the sensor pins with a voltmeter I can see the voltage swing between about 1V and 4.5V as I block and unblock the sensor. But if then attach the output to an input on my PIC the PIC doesn't see any change, and the voltage on the pin only reaches a fraction of 1V.

One of the websites I've seen on this topic uses a hex inverter, so I've tried this to see if it improves things. With this set up I get a very clean 0V or 5V when connected only to the voltmeter, but similar results as soon as I connect it to the PIC.

I'm sure I'm doing something wrong that'll be obvious to more experienced readers. Any help is greatly appreciated.

Thanks,

Luke

mackrackit
- 5th September 2007, 10:19
Check this thread out. http://www.picbasic.co.uk/forum/showthread.php?t=6826

The current is very low from the photo diode in these parts.. Try pulling the PIC pin low through ( I use 10 meg ) or something close.

The big thing will be ambient light. I use these for linear encoders for hydraulic rams and conveyor belts, how the covers are built is critical.

lsteele
- 5th September 2007, 10:58
Ok,

I've tried replacing the 20k resistor with 1M (largest I have to hand), and the results are much the same - a clear voltage swing when just connected to my voltmeter, but almost none when also connected to the pic.

Have I understood your suggestion correctly? I've attached a (crude) diagram of my setup.

Incidentally, I tried shielding the sensor from ambient light, but there was a negligible difference in readings.

Thanks again!

mackrackit
- 5th September 2007, 12:37
Found the drawing of the two ways I have used these. The one on the left will take the PIC high, one on the right will take the PIC low.

The part in the drawing is SHARP GP1S52VJ000F.
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1960&stc=1&d=1188991759">

Jerson
- 5th September 2007, 15:14
Luke

I suspect that you've forgotten to make the PIC pins as inputs using the TRIS registers.

lsteele
- 5th September 2007, 16:45
Hi Jerson,

You're absolutely right - that was the problem. What an incredibly stupid mistake! For anyone who's interested it now works fine with a 10k pull-down as in the diagram I posted earlier, or as in mackrackit's schematic.

Thanks very much,

Luke