Is VL53L0x Sensor the right choose for my project?


Hello,
I'm trying to implement a system that measures objects from different size and material. The minum object' size is 20x6 (wxh) mm. I though that the VL53L0x sensor was a good option. The idea was to measure first a known distance from the sensor to a plane, then measure the distance from the sensor to the top of the object and finally calculate the object height by subtracting both the measurements.
I created a small setup as in the attached immage with the sensor positionated 50 mm above the plane. Using Adafruit library, arduino uno and the Adafruit's example code, I'm getting a measure of 74/75 mm instead of the 50mm, but it's a stable value so I assume I can correct the offset via software.
The problem I encountered is that depending of the color and the material of the object the measure changes a lot, so for example is the object is white and same material as the sensor's support (3D printed PLA by the way) the measure is very good. If a use a black component, for example a cellphone, (10mm thin) the measure is not even similar to the real dimension, I get about 34 mm.
If a put a black piece of paper on the plane, the default measure changes from 74/75mm to 33/36mm.
Am I doing something wrong or cannot this sensor be used to do this kind of application?
I know that an ultrasonic sensor, like the HC SR04, would be better but the problem is that it's difficult to measure small objects with it.

This is the code that I used to get the distance:

#include "Adafruit_VL53L0X.h"

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

void setup() {
  Serial.begin(115200);

  // wait until serial port opens for native USB devices
  while (! Serial) {
    delay(1);
  }
  
  Serial.println("Adafruit VL53L0X test");
  if (!lox.begin()) {
    Serial.println(F("Failed to boot VL53L0X"));
    while(1);
  }
  // power 
  Serial.println(F("VL53L0X API Simple Ranging example\n\n")); 
  
}


void loop() {
  VL53L0X_RangingMeasurementData_t measure;
    
  Serial.print("Reading a measurement... ");
  lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!

  if (measure.RangeStatus != 4) {  // phase failures have incorrect data
    Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
  } else {
    Serial.println(" out of range ");
  }
    
delay(100);
}

Thank for your help.

Minimum range of VL53L0X is about 30-40mm. You van set if further apart or use VL6180x with 1mm minimum distance.

I've also putted the sensor 70mm far from the plate but the behaviour is still the same. Do you think that the VL6180x sensor measures better different material and colors in comparison with VL53L0X?

have a look at the specification of the Pololu TOF sensors

Thank you, I'll test the VL6180x

Doesn't look very accurate, maybe +/-2.5mm under ideal conditions, provided the object covers the entire FOV

If you need accuracy, you might consider an LVDT

I had a similar problems with VL6180 too, but I don't think the problem is the color but "the shines" of the surface. That is the limitation of both ST TOF sensors I tried.

The object covers the entire FOV. +-2.5mm would be acceptable but the problem is that I'm getting arbitrary measurements depending of the object wich makes the sensor impossible to use. I've read in another topics that people are getting good measurements so how can they get that results?

So in your opinion, is the VL6180 useful as well?

I was referring to the VL6180.
I don't think the VL53L0x would work in your application.

I explained above what problems I had with VL6180. What are you measuring exactly?

I'm trying to measure cap's height of different shape, material and size

And what are the results?

For the white cap :
Actual height: 6mm
Distance 59 - 62 mm
Measured height: 12-15mm

For the other caps:
Actual height: 10mm
Distance 40 - 44
Measured height: 30-34 mm

The strangest behavior is when I flipped the caps. The other side is obviously empty

For the white cap :
Actual thickness: 1.5mm
Distance 49 - 54 mm
Measured thickness 20-25mm ???

For the other caps:
Actual thickness: 2mm
Distance 30 - 34 mm
Measured thickness: 40 - 44mm ???

I also measured an smartphone as in the picture:
Actual thickness:10mm
Distance: 40-44
Measured thickness 30 -34 mm

I wrote about that in post #7. So as you see this type of sensors cant be used for your application, if the accuracy is important. I still wonder what kind of objects you want to measure and why..

Do you know what sensors can be used for my application?
I need to measure the cap's height to check if it is face up or down with respect to the empty side, but i don't want to physically touch the cap because it can create a lot of other problems.

So do you need the measured distance or just a go-no go signal? How much do the caps vary from one to another?

I'm thinking of a background suppression photosensor.

Yes, I need a go- no go signal depending is the cap is face up or down.
Caps go from 20 to 75 mm diameter and 5 to 35 height.
How does a background suppression sensor work?

Some optical sensing techniques

From what I've understood this is a prensence sensor, so it only checks if there's or not a cap. I do not need to do that but verify the cap's orientation