Door sensors detect door position (i.e., open or closed) based on the precise gap between the magnet and the reed switch.
If you need to measure a distance, it is tempting to reach for the ubiquitous ultrasonic module like an HC-SR04. These work well, and they are reasonably easy to use. However, they aren’t without ...