I am a novice in electronics and I need your help, if possible, in choosing a miniature distance sensor having a good accuracy (less than 1 mm) for measuring a distance that does not exceed 40 cm. It would be better if we could get the sensor data using a USB connection, wifi link, or even bluetooth link.
To measure 1mm in 400 mm distance not only has to have enough signal to satisfy the inverse square loss of a lambertian emitter/detector of any means it has to be stable within 1/400 or 0.25% which is a couple orders of magnitude less than most emitters IR, laser or otherwise unless self-monitor feedback regulates the output.
So this is an impossible task for a newbie.
The best concept I can imagine for you to try depends on your mechanical and optical skills of having a stable target reflector , assuming no diffusion from dust or vibration from object motion...
That would be using a laser diode and a fixed angle mirror deflector that is rigid in both axes except radial distance. Then a linear detector array can measure the deflection pixel position in a linear photo sensor array or CMOS sensor with optics to measure the spot deflection and compute the distance from the result.
The next possibility computes the transit time in nanoseconds which requires RF skills not in your possession yet.
Yet again laser interferometry methods are very precise, relatively cheap in volume, for cost/performance but not easy for you, so I wont detail that.
Perhaps you can "illuminate" the group on the application!