Now imagine the cantilever moving across the sample surface:
When the cantilever runs up over a bump, it bends upward. This shifts the reflected laser to the upper quadrants of the photodetector. The electronics then increase the voltage to the piezoelectric tube causing it to shrink. The cantilever is then allowed to straighten back out. This continues until the laser is again centered on the photodetector.
In this manner, the SPM converts the height of the sample surface to a proportional voltage signal.