Distance Sensor - out of range detection

Hey guys,

I am looking for a little help/guidance on this project. Its basically just a distance detector that detects people walking up to a monitor and as they get closer a set of LEDs change color and eventually it triggers a video.

The distance detector I am using is very accurate within its operating ranges (5-150 inches), but when there is nothing to detect its all over the place. I would like to make a function that will return a true or false if there is something within its operating range. My first thought is to have it check 5 or so readings and compare them to see if there is a difference of more than maybe 5+ inches between each read, if so return false. For example, if I place something 150 inches from the sensor it will read somewhere within 148-152 consistently, but if there is nothing in front of it it bounces around in the 30-60 range with zero consistency, usually being more that 5+ inch difference each read.

Anyone have any ideas or examples I could use? Thanks for your time.

What exact distance sensor? We can't read minds...

sorry I didnt think that mattered because I am just trying to figure out the math/logic

The sensor is a VL53LX.

I don't have any experience of that sensor, but it would seem like a significant design fault if the sensor continuously returns readings within the valid range when there is nothing physically in range. I'm not sure that a software fix would be a good option and shouldn't be necessary.

Probably a dumb question, but you have removed any protective tab covering the sensor, right?

Maybe someone else with practical experience of the device can add more suggestions.

Post a link to the exact sensor that you have. There are a couple of them named VL53xxx.

usually being more that 5+ inch difference each read

It is easy to detect such variations. Read the sensor 2 or 3 times and compare readings.

I'd recommend switching to a cheap HC-SR04 ultrasonic range finder. It's good out to a few meters and if there is nothing in range the pulseIn() used to read the distance will time out and return 0. You can get them for under $2 each, like this $8.99 10-pack from Amazon:
https://www.amazon.com/WYPH-Ultrasonic-HC-SR04-Distance-Measuring/dp/B00P5W1JLM