As a new product in the field of service robots, the sweeping robot has made some achievements, but there are still many key technical problems to be solved or improved. This paper focuses on the precise obstacle avoidance and highly sensitive execution of the sweeping robot, and designs a sweeping robot based on STM32 microcontroller. The infrared ranging and ultrasonic ranging are combined to achieve accurate data acquisition. When the measurement distance is relatively close, infrared ranging is used. Otherwise, the ultrasonic distance measurement is adopted. In addition, PID algorithm is used to speed up the response of the system, and the motion state of the sweeping robot is adjusted through prediction data to ensure the accuracy of STM32 execution. It provides reference for the development of sweeping robot industry.