Height measurement and location by a laser sensor is a key technology to ensure accurate and stable operation of a dispensing robot. In addition, alternation of dynamic and static working modes of a robot, as well as variation of surface and height of a workpiece put forward strict requirements for both repeatability and respond speed of the location system. On the basis of the principle of laser triangulation, a displacement sensor applied to a dispensing robot was developed, and a fast laser adjustment algorithm was proposed according to the characteristics of static and dynamic actual laser imaging waveforms on different objects. First, the relationship between the centroid position of static waveform and peak intensity for different measured objects was fitted by least square method, and the intersection point of each curve was solved to confirm the ideal peak intensity, and therefore reduce the interference of different measured objects. Secondly, according to the dynamic centroid difference threshold of two adjacent imaging waveforms, the static and dynamic working modes of the sensor were distinguished, and the peak intensity was adjusted to different intervals by linear iteration. Finally, a Z direction reciprocating test, color adaptability test, and step response test were carried out on the dispensing robot platform; the experiments showed that the repeatability accuracy of the sensor was 2.7 um and the dynamic step response delay was 0.5 ms.