Precise touch-less distance measurement

I’m trying to get an actual distance readout for when I’m leveling my 3d printer bed. I figured I could just make a quick Arduino setup but all I have are ultrasonic sensors but they do not do the precision I need.

I want to get readouts in the +/- 0.1mm range to be satisfied but all I’m finding are advertising +/- 1mm semi-reliable reads.

I know touch sensors CAN do better but I’m using this for a 3d printer and don’t want to mount/unmount the thing between prints. Can anyone recommend a good sensor that’s under ~$20 that’ll do what I want or have a better idea?


Hello there!

I have experience with the APDS-9960 sensor and it may provide what you need. It can be used as a general IR proximity sensor, a directional IR sensor, and a color sensor at the same time. I don't know how precise it can get, but maybe combining all three sensors at once can help with that.

Good suggestion. Skimming the datasheet, it looks like the proximity really just measures the strength of light reflected. It's intended for seeing if your phone is near your ear so it's obviously optimised to detect distance to skin. If your 3D printer is significantly more or less reflective than skin, it may not work well. If the printer has different reflectivity in different areas, it will think the bright areas are closer than the dark ones.

If I needed to do this, I'd use a microswitch attached to the print head - just lower the print head to measure the height of that part of the bed. I think the Taz5 and Taz6 printers do it electrically - the print head touches metal pads that complete a circuit through the metal head.

Capacitance distance sensors might be another approach, especially if your bed is effectively a grounded
metal plane. I don't know if there's a chip for this application, or whether it would be a project in its own

Great suggestions! I did some research on the APDS 9960 and decided to go with the one from Adafruit and will try to remember to post with how that works out. Also, think I may tinker with that sensor for other projects since it does so much!

I see what your saying MorganS, I'll try the APDS sensor and if it doesn't work I'll try a microswitch. I'm just using PEI as a print surface but if I put some painters tape down that might help with reflectivity if it becomes an issue.

The main reason I didn't want a physical sensor is that it would need to be protruding past the print head (unless I removed it) and I'm worried it'll interfere with printing. With a touchless I can just compensate for the distance it's above the nozzle (or so goes my scheme). I think printers that have this feature must retract the sensor or something after leveling, just my guess though and that would be a little more than I wanted to do (unless I find a sensor that has retraction built in).

Again, thanks to all of you!

Sharp has a series of analog IR distance sensors. They may do the job for you. The GP2Y0A51SK0F I think is the one with the shortest range, which is what you need.

Use a spirit level !!! or an inclinometer with some sort of output ( or even you phone)
I would have thought the levelling process a one off - something you don’t do every few minutes- hardly worth making something, which in turn needs something to level it in at least three places so it can measure accurately , and maybe subject to drift and so on .


@hammy Read up on 3D printer bed levelling. A spirit level is the wrong thing. The purpose is to level the bed relative to the X and Y travel rails. Accuracy of better than 0.1mm is required over the whole print area.

Some printers map the bed with a mesh of points so what appears to you and me as a flat sheet of glass is a big potato chip to the printer. 4 points is the absolute minimum for most printers.

If you get a part stuck to the bed and are forced to use more than the usual level of swearing to remove it then the alignment can be damaged. So it gets checked after every few prints.