In this design, hc-sr04 ultrasonic module is selected, which can easily achieve the function of measuring distance. And in a certain area, the operation time is short and fast. In this module, it can transmit signal, receive signal and control the related circuit of the system. Its basic working principle:(1) By using the trug port to transmit more than 10us high level, the ranging function of the module can be realized.(2) Through this module, we can send out square wave of specific frequency and detect whether there is return on the signal.(3) When the signal returns, output a high level from the echo port. When the ultrasonic module receives the return signal, output a high level signal from the echo port. The duration here is the total time period.(4) When trig is from 0 to 1, the main control board is activated. When the timeout is 10ms, ech0 does not display 150us signal, indicating that there is no obstacle.This module not only has stable performance, but also has accurate distance estimation. Its main features are as follows:1. Typical working voltage: 5V.2. Working current at static state: under 2mA.3. Sensing angle: 15 degrees or less.4. Detection distance: 2cm-400cm5. High precision: 0.3cm maximum.6. The blind spot (2cm) is very close.The shape and primary interface arrangement of c-sr04 are shown in Figure 2-5.There are four main interfaces in this module: VCC interface, trig interface, echo interface and GND interface(1) VCC supplies 5V power;(2) Echo echo echo signal output;(3) Trig trigger control signal input;(4) GND is the ground connection.When using this module, the time of ultrasonic pulse from sensor to receiver is t, and the velocity of ultrasonic propagation in air is C from sensor to target object. The distance s can be obtained as follows: S = CT / 2. And there are only four pins: power supply, grounding, and the rest of reading and writing. At present, there are various ultrasonic ranging methods, such as round-trip time detection, phase detection and acoustic amplitude detection. The principle of ultrasonic distance measurement is to send out a certain frequency signal through the ultrasonic sensor on the single chip microcomputer we use. Through in the air spread to contact with obstacles, after the calculation of the system, and then displayed on the digital tube. And the method used in this paper: from the start of transmitting ultrasonic wave, from the ultrasonic instrument transmitting ultrasonic signal to the receiving of the echo from the instrument, we can calculate the time difference T from one to one, and then find the distance S = VT / 2, where V in the equation is the speed of the ultrasonic wave. As ultrasound is also a kind of sound wave, the speed of C is related to the temperature, so in practice, if the temperature changes little, it can be considered that the speed of sound is basically unaffected. CD4060 is the core device of ultrasonic sensor designed by Maxim company abroad. CD4060 integrates ultrasonic emission control and ultrasonic receiving control, so it is very convenient. The power supply of the chip is also 5V, which is very consistent with the design of the single-chip microcomputer. As shown in the figure, one pin is connected to 5V power supply, and four pins are connected to power supply. It has low power consumption, and only needs a single + 5V power supply with a power supply current of 5mA. Two RS-232C drivers are integrated inside. The ranging can be realized through two interfaces, and trig of IO port is used to trigger the ranging to give at least 10us high-level signal. The module automatically sends 8 square waves of 40KHz, and automatically detects whether there is signal return; if there is signal return, it outputs a high level through the IO port echo, and the duration of high level is the time from transmission to return of ultrasonic. Test distance = (high level time * sound speed (340m / s)) / 2. When a control port sends a high level of more than 10us, it can wait for the high level output at the receiving port. As soon as the output is available, the timer can be turned on for timing. When the port becomes low power, the value of the timer can be read. At this time, it is the time of this ranging, and then the distance can be calculated. Such continuous periodic measurement can reach the value of your mobile measurement. Trig is the transmitting signal end, ultrasonic emission is connected with p3.2 of MCU, echo is the output response signal, and p3.4 of MCU. By controlling the interface of trig and echo, ultrasonic distance detection can be realized.