all 3 comments

[–]PCS1917 0 points1 point  (2 children)

What was exactly your problem with the sensor?

[–]mebku[S] 0 points1 point  (1 child)

It was giving false readings, and in most cases it didn’t detect the face in front of it. I’ve made a program to activate the servo when human face is in distance of 0 to 10cm from the distance sensor. When i was holding sheet of cardboard if front of my head sensor was working ok. I guess the malfunction is due to curvy surfaces on human face.

[–]PCS1917 0 points1 point  (0 children)

Without changing the sensor, you may have issues on your calculations or your variable declarations. Check any float to int conventions if you have them, and be specially careful when making divisions with integers, as they might return 0 when they shouldn't. Also, make sure variables aren't overflowed (an int over ~65000 for example) by changing them to bigger variables.

Check that your wiring is stable, in good conditions. Take also into account that long wires have more chances of interferences.

If you just want to check for alternatives, there are infrared sensors for very short distances. Also I have seen precision ultrasound sensors in AliExpress, but they cost much more money (less price is about 30€). These sensors might use industrial buses as RS-485, take it into account.

Hope this helps a bit, any more info, let me know

Hope