Let's see how the transmitter (TX) and receiver (RX) work together to measure distance. The basic operating principle of an ultrasonic sensor is illustrated in the following figure:
Figure 11.5 – Ultrasonic distance sensor operation
Here is what happens:
- First, the sensor sends out an ultrasonic pulse from the transmitter (TX).
- If there is an object in front of the sensor, this pulse is bounced off the object and returns to the sensor, and is detected by the receiver (RX).
- By measuring the time between transmitting a pulse and receiving it back, we can calculate the distance between the sensor and the object.
With this high-level understanding of how the sensor works, next, we will go deeper and discuss how to use the TRIG and ECHO terminals on the HC-SR04 together in a process to estimate distance.