The working principle of AFM involves a cantilever with a sharp tip that scans the surface of a sample. When the tip comes close to the surface, interatomic forces between the tip and the sample cause deflections of the cantilever. These deflections are measured using a laser beam reflected off the top surface of the cantilever into a photodetector.