Bob,
Are you thinking in terms of something like an ultrasonic sensor (HC-SR04)? If so, you may want to review this post: https://ogrforum.ogaugerr.com/...ock-detection?page=7
Personally, I've only experimented with one briefly but it looks like it could be very useful and will most likely find a place on my layout.
bd