Non-contact measurements like this are probably best made with a laser parallax device like a Keyence.
Ultrasound at hobbyist prices is always going to be tricky, if not impossible.
Wavelength in air at 40kHz is around 8 or 9 mm, so measuring smaller displacements will rely on fiddly phase comparisions, which the standard hobby devices are simply not capable of.