If you need to measure small distances, a simple way to do so is with “LVDT”. This abbreviation stands for Linear Variable Differential Transformer, and is just a set of 3 coils, with one coil allowed to move relative to the other two.
To measure the distance one applies a varying voltage to one pair of contacts, and reads the response from the other pair. Voila ! A distance measurement.
LVDTs are fairly easy to make - just arrange the coils in a pattern shown on right. In some LVDTs the coil L3 moves relative to L1 and L2. In others, all the coils are fixed and the magnetically permeable core F moves changing the coupling. With some care one can make sensors that measure nanometers - but this a topic for another time. Here you can find how to read LVDTs with your phone or a Raspberry Pi.
LVDTs are made in different shapes and sizes. When picking LVDT, it is important to consider travel distance - with a smaller distance you might get increased precision, but you give up being able to measure parts of different sizes.
In theory, all one needs to read an LVDT with a phone is play a tone into excitation coils of the LVDT, and record audio from the readout coil. However, the modern phones are a little too clever to make things simple.
The 3.5mm jack does not only play and record audio, but it also senses which kind of microphone is attached by measuring its resistance. There is also a provision to respond to buttons on the headset, which also works by measuring resistance.
Thus the need for a phone adapter shown on the right. It is purely passive, to avoid signal distortion. The resistors should be metal film, as carbon composition resistors may introduce noise.
The capacitors are less critical. For my own adapter I used high quality WIMA 0.1uF capacitors rated to 400V. The phone will never reach this voltage, but it is important because the capacitors were designed with low internal dissipation to be used in a switching power supply. And low internal dissipation correlates with having low noise.
Here is an assembled adapter. The LVDTs come with different connectors and sometimes with bare wires only. This adapter has a 5-pin DIN jack compatible with common industrial LVDTs. Mahr Federal LVDTs can be connected to a 6-pin DIN socket - the middle contact is unused.
You would need to measure resistance between different pins of your LVDT to identify the pairs of contacts corresponding to different coils. The measurements can be made by exciting either coil. In theory, one coil should be preferred for excitation as it provides lower noise - but I have not seen this effect.
What does matter, however is coil resistance - you do not want to drive too much current into the coil and heat it up. This distorts measurements and in extreme cases can damage the LVDT.
In my LVDTs the coil resistances are around few hundred Ohms, so this is not an issue. I usually pick the lowest resistance coil to connect to the audio output, as it provides a stronger output signal.
Once assembled, you can plug the adapter into your phone if its has a 3.5mm jack. If not, use a 32-bit USB adapter. In fact, this adapter is a good idea even if your phone has its own 3.5mm jack - I found that on some phones the builtin audio is rather noisy.
You can find example source code to read LVDTs with Raspberry Pi here.
There is also an Android arLVDT app, which comes with a small fee. It is not open source, because most of the code is not about reading LVDT, but to comply with various Android bureaucratic requirements.
A short video showing LVDTs in action.
When you read LVDT, the value you actually get is a ratio indicating how the position of the coils differs from perfectly symmetric. The actual distance depends on how big the coils are, and is obtained from the ratio by multiplying by a calibration constant.
The constant can be found by measuring an object of known length. One can compare two stacks of gauge blocks, as shown on the picture at the top of the page. However, if you use LVDT to check whether some object is flat or not even a 10% calibration is good enough, and you can use a few washers (or anything else reasonably stiff) measured with a caliper or micrometer.
Comments or questions are welcome at qDaltumrete.com