Encoder Front Page
SRS Home | Front Page | Monthly Issue | Index
Google
Search WWW Search seattlerobotics.org


Mousebot

(How to Extract Quadrature Encoders from Computer Mice)

 

Theodore Johnson

 

I have found that the most difficult part of implementing PID control of robot movement is to construct a reliable and inexpensive encoder that has reasonable accuracy (e.g., this was my primary failing in a previous article).  I came across some articles, e.g. by David Anderson, Larry Barello, and Giuseppe Marullo on homebrew quadrature encoders.  However, each of these involves exploiting a feature that might not be available.  Another approach is to purchase a commercial shaft encoder.  But even “inexpensive” encoders seem to be quite expensive when purchased new.  A final option is to try your luck in the surplus market, or to remove encoders from junk equipment – a rather hit-or-miss proposition.

 

It occurred to me that there must be a pair of quadrature encoders in every computer mouse (other than the new optical mice).  Since every new computer ships with a mouse, there are lots of old but working mice lying around.  In fact, I had several in a drawer; some had been there for many years.  Even failing that, there are lots of old mice on the surplus market.  Since one mouse will give a matched pair of encoders, it seems like a good source

 

I augmented my collection of mice with donations from junk of some friends, and eagerly began to crack open the mice to explore their mechanisms.  I found four different mechanisms.  The most unusual is a mechanical encoder extracted from a very old mouse, shown in Figure 1.  Inside the case is a wheel with 24 metal strips, connected to one of the terminals.  These make contact with two brushes that are connected to the other two terminals.  I didn’t use this one because of the low resolution and because of concerns about reliability.

 

Figure 1  Mechanical encoder.

A second type of encoder uses an encoder wheel and shutters.  An example is shown in Figure 2.  The shutter has a couple of slits (hard to see in the photo, look closely), which are positioned 90 degrees out of phase with respect to the encoder wheel.  The detector circuit uses a conventional IR LED / IR detector set, one on each side.  While the wheel has a respectable 34 tines (68 ticks/revolution), I could not figure out a good way to mount it.  You might have better luck.

 

Figure 2 An encoder that uses a shutter.

 

 

The newer mice generally have a single IR LED and detector, configured as is shown in Figure 3.    The clear component behind the wheel is the IR LED, while the black component in front of the wheel is the detector.  After opening a few mice of this type, I noticed that some of the detectors have three wires, while some have four.  In Figure 3, you will notice that part of the PCB has been broken off.  I did this to extract the detector that was located there.  I had a hard time desoldering them and managed to ruin one, so I took the alternative approach of clipping off the PCB until each lead could be extracted individually.

 

 

 

 

Figure 3  Interruptor wheel mouse.

 

By tracing the leads on the mouse circuit boards and running some experiments with extracted components, I was able to determine the pinouts of the detectors, shown in Figure 4.  These diagrams are drawn from the top looking down.  The three-pin detector consists of two photodiodes arranged vertically.  The outputs must be pulled to ground by, e.g. a 10K Ohm resistor.  The four-pin detector is a more complex device.  For one, its outputs do not need external pull-up or pull-down resistors; they can be attached directly to the microprocessor input.  For another, the outputs do not respond directly to light – they will not go high (low) in the presence (absence) of light.  Instead, they react to changes in light, e.g. the moving pattern of light and shadow made by the encoder wheel.  I first thought that the detector was defective until by accident a wire cast a shadow on the detector and made the output flicker.  The detector surface is the flat surface; the bump indicates orientation.  I ground off this bump for easier mounting.

 

Figure 4  IR detector pinouts.

 

Attaching the encoders to motors

 

A local surplus store was selling old autofocus video cameras for a very low price.  These cameras have two small (1.125” long, .5” diameter) gearhead motors.  I picked up a few to extract these motors; they seemed perfect for a tabletop robot.  Since each camera had two motors of two different types, I took the opportunity to experiment with attaching and interfacing both the 3-wire and 4-wire detectors.  The first step is to attach long leads to the detectors, as shown in Figure 5. 

 

Figure 5  Wiring up the detectors.

 

The next step is to attach the encoder wheels to the motor output shafts.  This task entailed drilling a hole through the center of the encoder disk.  Since this requires more precision than I thought my power drill could provide, I used a hand drill.  These hand drills are inexpensive and can be purchased from hardware stores or from on-line tool catalogs.  I created a first hole with the smallest diameter bit, then enlarged the hole until it pressed onto the motor shaft snugly.

 

 

Figure 6  Hand drill

 

I filed the backs of the detectors to ensure a flat mounting surface, and covered the bare leads with heat shrink tubing.  I put the encoder wheel on the motor shaft and ran the motor in front of an IR LED to find a place to put the detector that would give a reliable quadrature signal.  After I found these spots, I superglued the detectors to the motor, as shown in Figure 7.  The motor on the left has a 3-wire detector and a 36 tine (72 tick/rev.) encoder wheel.  The 3-wire detectors usually come with low-resolution wheels, often with just 24 tines.  The motor on the right uses a 4-pin detector.  These usually come with higher resolution.  This wheel has 56 tines (112 tick/rev.), while another that I found has 64 tines.

 

Figure 7 The detectors mounted on the motors.

 

The last step is to mount the IR LEDS.  The 3-wire detector is mounted high on the motor, so I built a platform to hold the LED, as shown in Figure 8 (upside down).  This detector is sensitive to the position of the LED, so I had to play around with the positioning of the perfboard until I had a reliable signal. 

 

Figure 8  LED mount for the 3-wire detector.

 

The LED mount for the 4-wire detector is shown in Figure 9.  This detector is not sensitive to the positioning of the LED, making this task much easier.

 

Figure 9  LED mount for the 4-wire detector.

 

The pair of assembled robots is shown in Figure 10. 

 

Figure 10  Assembled robots.

 

 

 

Conclusion

 

Now that I had precisely controlled tabletop robots, I had to figure out what to make them do.  I opted to make them find the center of the table.  The algorithm is to have the robot wander about until it finds the edge of the table (you can see the edge sensors in Figure 10), and make note of the position (using a dead reckoning algorithm similar to that presented by G. W. Lucas).  After doing this for five times, compute the mean position and head there. 

 

The best encoders are definitely the ones with the four-pin detector.  They do not require pull-down resistors, they come with high resolution encoder wheels, and are relatively insensitive to the positioning on the IR LED.  The output signals seem to be very close to ninety degrees out of phase (by eyeball, I did not make precise measurements), so one should be able to double their resolution by counting on every transition of both outputs.  However, many modern mice still use the three-pin detector, the four-pin detector seems to be used on “high resolution” mice.  An advantage of the three-pin detector is that their encoder wheel is usually larger, making it easier to fit on a large diameter shaft.

 

The motors I used have small diameter output shafts, which made drilling the doles in the encoder wheels fairly easy.  However, the technique of using a hand drill to successively enlarge the mounting hole should work well for larger diameter shafts also.