I need to purchase a distance sensor that will be fixed in place and used to determine distance to the top of a fairly fast moving piston along the axial direction in line with the sensor. The top of the piston can be covered in whatever material works best for sensor accuracy, and the entire apparatus can operate in the dark if needed. Distance will range from 50mm to 500mm. Position measurement must have an accuracy range below 1.5mm. Update rate must be 1000hz or greater (i.e. update every 1ms or faster).

I see there are many options for me at high cost, but I'm limiting my budget to $500 and below for the next few days while I research more. This does not mean I won't spend whatever is needed however. As of now I've seen nothing acceptable for under that price, but it's hard to tell as many companies won't publish prices for these types of sensors.

I'm happy to explain more about the implementation if needed.


I wish more people were reading this post, because I have great suggestions for DIYers after researching a lot of options the past few days. Currently I'm looking at offerings from Turck.com relating to reading a magnetized strip. This would read position from the side rather than from above or below as I describe in my original question. Turck calls it their "LM-2 line" and some options look pretty affordable and quite a bit under $500. Here's a brochure they provide - it documents how they read a magnetic strip: https://www.turck.us/attachment/B1027.pdf


There is one answer here related to a different sort of solution involving a device which reads a code every 0.5mm or 1.0mm taped to a rod which is attached to the piston. Device would read in direction perpendicular to direction of motion. This would probably be my 2nd or 3rd choice if I'm unable to find an affordable sensor as described in my question.


If I had time I'd implement the following solution which I wish I had thought of a month ago: tape a 300mm strip of reflective material which varies in reflectivity along its length. shine a laser on the tape and detect amount of light which reflects. simple solution, easy to calibrate and (if I knew where to get the tape) should be low cost.

  • None of this discussion has any real bearing on the question. I'm moving it to chat.
    – Majenko
    Commented May 29, 2021 at 22:38
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Majenko
    Commented May 29, 2021 at 22:38
  • 1
    what moves the piston? ... is there any possibility to measure the motion of some other part of the device and calculate the position of the piston?
    – jsotola
    Commented May 29, 2021 at 22:47
  • magnetic fields move magnets in the piston. the piston is attached to a long rod. i'm using that for sensor to detect piston motion. yes, i'd rather measure resistance along a linear pot. however, as accuracy is key I would need to tackle issues related to variable stray capacitance as well as resistivity as it changes wrt. temperature. or i could try my best to calculate position via accelerometer input, but there are bigger unknowns there. in any case, i'm not sure why laser sensors would need to be so expensive. but they are because industry pays for them. Commented May 30, 2021 at 0:02
  • here's an idea I wish I had time to implement: at every millimeter along the rod there can be a series of 1's and 0's that represent the distance value. if I had something that could read that every 0.5 ms ... i still think it would be either slow or inaccurate though. probably too slow. Commented May 30, 2021 at 0:11

1 Answer 1


Inside an inkjet printer, I've found a clear plastic strip with photo-engraved (loose approximation) lines perpendicular to the length of the strip. This strip passes through an optical pair, one side illuminates, the other reads. The strip stretches the entire width of the printer and if I recall correctly, the reading module is on the print head carriage. Consider that many printers are described as 600 dots per inch, which would create a resolution on the strip of 1/600" / 0.04 mm.

Additionally, I've discovered circular plastic encoders on which the rings of black/clear alternated the segment counts with each expanding ring. That is to say, the first ring was half black, half clear. The next ring out was 1/4 black/white alternating, the one following was 8 segments, then 16, etc.

This required a reader for each ring, but provided an absolute reference rather than a relative reference as is the case with the linear strip. One could create a linear strip which would work in a similar manner. One level would be half black, half clear, the next layer would be 1/4 black/clear, etc.

binary scale image

The requirement for 500 mm fits into a binary 512 value, which would require 9 stripes and provide for the accuracy noted in the post.

The aspect I can't answer is the speed of the encoding, although I suspect that any design based on an optical reader could be optimized to work.

I found an article at rp-photonics.com

When light is diffracted at the traveling refractive index grating in an acousto-optic modulator, the diffracted light experiences a shift of optical frequency which is plus or minus the acoustic (or drive) frequency. That effect (which can be interpreted as a Doppler shift) is exploited in acousto-optic frequency shifters.

Drive frequencies are typically between some tens and hundreds of megahertz, rarely more than 1 GHz. The resulting change of optical wavelength is quite small. For larger frequency shifts, or for realizing very small frequency shifts (e.g. only a few MHz), one may cascade two or more devices. It is also possible to use a double pass through a single device in order to obtain twice the frequency shift.

I think from reading that excerpt that the long strip in the inkjet printer is the traveling refractive index grating. I had not considered that a low-power laser could be substituted for a simple optical pair. Doing so would provided even better resolution.

If your project allows for a strip of sufficient length to be attached to the piston, with assurance that it won't buckle under acceleration and jam in the sensor, you'd probably make it work.

But wait, there's more. I can picture the rod on the piston alternately obscuring and uncovering a digital design, which is constantly scanned by a laser. This reduces the number of parts in close contact and possibly the moving mass.

  • It's a great idea. I may try to implement along these lines, but as I've indicated in my comment above there's no reason to think this is more accurate or as fast as a TOF or triangulation solution setup in the manner I suggest at an affordable cost. The advantage is a fast binary calc can turn the scanned lines into usable measurement values. The disadvantage is uncertainty of the setup which, even if calibrated perfectly, is not guaranteed to be accurate enough for my needs. Vibration is the first issue to be considered for instance. Commented May 30, 2021 at 16:07
  • Clarifying my comment just above: I'm referring to vibration of the rod which is attached to the piston. Not vibration of the sensor/reader which would be still. Commented May 30, 2021 at 16:28
  • You can mitigate vibration by having supports at both ends of the traveling rod. I suppose if you have a piston running at 1 MHz or higher, you'll have some imbalance in the entire assembly. Horizontally opposed pistons?
    – fred_dot_u
    Commented May 30, 2021 at 18:50
  • Sorry wasn't clear : the rod is as vibration free as is possible. That doesn't mean it won't be an issue. In fact I'm certain it will be, and if I have to spend time and money lessening it even further than I've defeated the purpose and might as well stick with the original idea of a (likely) expensive position sensor. Commented May 30, 2021 at 21:23
  • An alternative could be to use a Gray code instead of the binary code.
    – tim
    Commented Jun 2, 2021 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.