The detector (5) of AFM measures the deflection (displacement with respect to the equilibrium position) of the cantilever and converts it into an electrical signal. The intensity of this signal will be proportional to the displacement of the cantilever.
Various methods of detection can be used, e.g. interferometry, optical levers, the piezoelectric method, and STM-based detectors (see section "AFM cantilever deflection measurement").