An early 3D printer would normally have a microswitch that would turn on when the Z axis reached zero.
Generally, there was an adjustable screw to allow you to fine-tune the layer height. But these days, sensors are what you most frequently observe. There are inductive sensors that may be used with various bed types, including metal beds. However, the “BL touch” style sensor, which measures while lowering a probe below the nozzle level, is the most widely used.
Even So, the majority of these sensors only detect a specific height over the bed to function.

The height over the bed can be read in real-time by a novel inductive probe under the name of BD sensor. The creator claims that it achieves repeatability of +/- 0.005mm and a resolution of 0.01 mm. Whether it is accurate or not is unknown, but it does open up some intriguing possibilities, such as real-time Z height modifications, as seen in the video below.
The tool does need to be calibrated.
In essence,
you only touch the nozzle to the bed, and the machine measures 7 mm while constructing a calibration curve. Recent iterations of Marlin support the probe and show the measured height in real-time on the LCD.
Although the BL Touch also requires two free I/O pins, you presumably have a port you could utilize.
When in use, you can use the real-time display to assist with manual leveling or a conventional probe to automatically level the object.
As shown in the video, you may also set up for dynamic leveling.
Although bed sensors don’t have to be expensive, something is appealing about continuously monitoring the height of the bed, a feature that seems mostly exclusive to this probe.
Source: Youtube, Hackaday