Linear Optical Encoder


Optical encoders are nothing new; they can be found in everything from mice to printers. They’re great for allowing DC motors to know their exact position and even current direction. If this is sounding like old hat, it’s because we’ve shown you rotational versions before.

[Chris] uses the same concept, but produced a linear optical encoder instead of rotational. His setup is much like whats used in non stepper-motor CNC and RepRap mills, allowing ordinary DC motors to know their position within a plane. It’s a quick tutorial, but we liked the detail and it reminded us we need to finish that DC motor based mill thats still a pile of parts in the closet. Check out a video of [Chris’] in action after the break.


32 thoughts on “Linear Optical Encoder

  1. Something that they’ll have to be careful of (with only one sensor) is location accuracy.

    Having more lines closer together will increase it, to an extent, but by increasing resolution.
    Imagine the above system with very thin white stripes, same resolution but higher accuracy on hitting the same place irrespective of the approach direction.

    Another way (in the absence of being able to make infinitely fine white stripes) is by off-setting another (identical) sensor (it doesn’t even need to be very close to the original one, it can be n-stripes plus the fraction away, it’ll only limit the ultimate travel). When the combination of the two sensors says “white stripe” then you know your location is within a stripe and not just over the end (as the other sensor would report “black stripe”).
    One could use the analogue nature of the sensor to see if you are only slightly over into white from black but this assumes consistent behaviour on every white/black boundary and all operating environments.

    Sorry, I went on a bit (I’m wasted on my day job when I could be hacking away on real electronics)

  2. I’ve been toying with the idea of building a huge 2*2 metre x–y plotter, and a linear optical encoder would be perfect for this. But how can I get my hands on a 2 metre long transparent plastic strip with tiny lines? Any thoughts would be very welcome.

  3. @Oddler

    Inktjet printer + overhead plastic? (not the sheets, a roll)

    most old inkjets can print on this stuff, and are able to process rolls as if it were chain-fed paper (or how do you call that old paper with holes on both sides)

  4. I have often pondered the problem of linear position measurement. I thought the best way might be to use some resistance wire and a wiper on the carriage. With using a straight length of resistance wire the impedance for a short run might be very low and so the voltage supplied across it would have to be low (so as not to melt it). It would be very cheap and absolute though, the positioning accuracy would be limited to the resolustion of your ADC.

  5. @urlax and @Oddler

    So something interesting: So the smallest pixel you can print is 1/2 the width of the lines on your encoder strip (e.g. if you had a 10 line/inch strip you could print a 20 line/inch strip). So in theory you could start with something low resolution, and make progressively higher resolution strips until you reached the limits of your printer and encoder head.

  6. While you’re salvaging the mylar codewheels and codestrips from HP inkjet printers, don’t forget to snag the optical sensors too. They’re dead simple to interface, with 4 pins for +5V, ground, and two-channel quadrature TTL output–and you’ll have a difficult time reading the encoders without them. Here’s the datasheet for the common HEDS-9700 series:

    Bear in mind that a lot of DeskJet problems result from a dirty encoder strip. These may not be appropriate for dusty home CNC environments.

  7. you could reuse the encoder strips even in a dusty environment as long as you protect the area that will determine your location with an enclosure and weatherstripping.

    I like this idea, but I’ve used precision encoders on satellite dishes (like 32K steps) and have not had failures for positioning that wasn’t due to outside influence. I’d like to take a optical encoder and have a precision encoder as a secondary on an XY table. Write the code to take slight variance into account an viola, XY with double checking.

  8. @Jim:

    “I thought the best way might be to use some resistance wire and a wiper on the carriage… It would be very cheap and absolute though”

    This is very similar to what was done back in the 60s and 70s for electronic console organs (and probably portable ones too). There was a long bus bar (with some voltage across it) that ran the length of the console, and each key was connected to a stiff wire that touched the bus bar, providing a voltage for a VCO. Tuning was accomplished by bending the wires.

  9. @Jim

    you can better use resistive wire isolated with enamel and wind it on a wooden rod. or a pvc one. that way, your resistance will be much higher, reducing the error. (the wiper will oxydate, introducing uncertainty.)

    for instance, if you want to measure an axis of Oddlers device, you’d use 2 meters of wire. (1mm² nichrome would have an resistance of 2,1 Ohm.)

    if you wound the wire around an bar with an circumference of 1cm, you would need 2000 turns, using 20 meters of wire. the resistance would become 21 Ohms, which requires less current, and gives a better resolution.

    it would look like this, but longer:

  10. @tantris

    At 120-150 lines per inch, much lower resolution than even the cheapest optical mouse. But, assuming clean optics, they yield very precise measurement. Optical mice have relatively poor accuracy: losing track of their position, skipping pixels, etc. Great for rough motion tracking, terrible for quantifying it.

  11. I remember pulling the encoders out on the XY table of an ESI Model 44 laser trimmer only to find the lines rubbed off from misalignment. So thats why the table kept slamming into the stops.

  12. Why not dispel with the encoder strip altogether and use an optical mouse encoder instead. You’ll get both X and Y position encoding down to fractions of a millimeter with a single sensor. A laser mouse encoder should do even better. The surface the encoder works against can be any surface usually encountered on a desktop (even a plain sheet of white paper). The two links below should prove helpful for the interested. Cheers.

  13. @Jim: Once upon a time I had an ‘analog mouse’ that worked this way. It plugged into the analog ins on a commodore 64 and pretended to be two paddle controllers. Worked well enough for the limited resolution on that computer. Where there would normally be an encoder disk on optical mice, there was a carbon track like the inside of a potentiometer.

  14. Or how about using an old electric guitar!
    Mount the pickup and a slider on the carriage, tension the string along the direction of travel. Electronically ‘pluck’ the string with a solenoid or by using electromagnets. Frequency would be proportional to position, absolute position, dirt wouldnt be a problem, neither would humidity.
    For temperature you could actuate the slider and every once in a while vibrate it open to calibrate.
    Get a few stepper drives in and it should sound great.

  15. Goal: “a way to know where the ‘stage’ is”

    Has fingered a potential problem.

    See, you don’t actually know where the stage is because this isn’t actually an “encoder”. It’s more like a rotopulser. Anyone with experience of a CP-80 type printer (or maybe FDD’s) will have seen a jammed carrage vibrating in place while the driving processor is blissfully unaware that the carrage is nowhere near where it thinks (until maybe it returns to zero prematurely and causes an error).

    said the magic word “Gray code”.

    One way to know exactly where the carrage is at all times is to fully encode the traverse with as many bits of Grey code as required.

    just reinvented slide-wire feedback, used in early plotters.

    now THAT I really like. Hat tip.

    Which reminds me of a metrology setup that used a fine inter-digital ladder and a matching short reader strip. In the macro this would count off the phase reversals for each ladder step (~1mm) but for the fine did a phase resolution between the ladder steps to better than 1 thou overall (retrofit gear for old mills, lathes, &c; Nixie readouts, all TTL btw).

    I’d suggest the world of PCB photography would be a good starting point for large, very fine and regular structures.

    Slidewires worked, honestly. And they were far from the most troublesome part of the recorder. Wound slides were also used, but for home construction the evenness of the winding would be critical for positioning, and the wire thickness would limit fine resolution.

    Yer. But say we combine mouse opticals with a fine printed Grey code strip, then read the mouse video directly, and in software interpolate based on the position of the code in the scan. Give all that processing power something useful to do for once. :)

    “Twang-wire” rebalance? That has to be either brilliant or crazy. You might consider what happens if you measure the twang frequency on *both* sides of the head.

  16. @reboots
    but what if one would run the mouse on an optimal mousing surface (like an encoder strip)?
    or one could use the encoder only. some mice have the optical reader separate from the chip, that does the “micing”stuff. one can read image data directly from the chip. of course, calibration would have to be done in software, but one would also get feedback on possible errors.

    some older link to someone using the mouse as a scanner (he however relies on the mouse telling him positions):
    (link to original is broken, but project is still here: )

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.