Nib asked, and Nib — askNib's tutor — drew the answer live at a whiteboard. This is the spoken transcript; enable JavaScript to watch it drawn.
how do elevators know where to stop
The elevator never reads the floor numbers. Mostly it counts: a sensor on the motor sends a pulse for every small turn, and the controller adds them up, like an odometer.
When the shaft was set up, the elevator learned it, running end to end and remembering each floor's count. Now it knows where every floor is, in pulses.
Counting can drift, because the ropes can slip on the wheel. So every floor has a fixed marker in the shaft, and a sensor on the car reads it and fixes the count.
Meanwhile your button press is stored. The car serves stored calls in the direction it is heading, and turns around only when none are left ahead.
To stop smoothly, it must know when to begin. The count says start slowing; magnets beside the landing then show when the car is level, so the doors can open.
So the whole thing: count the motor's turns, fix the count at the markers, serve stored calls in the direction of travel, slow down, level, and open the doors.
Next time the doors slide open exactly level, remember: the car got there by counting, and then checking its work.