An ultrasonic sensor is used to measure the distance between an obstacle or an object. An ultrasonic sensor consists of a transmitting transducer and a receiving transducer. The transmitting transducer (the trigger) emits ultrasonic pulses (also referred to as ultrasonic sound), which collide with nearby obstacles and are received by the receiving transducer (the echo). The sensor determines the distance between a target by measuring the time difference between the sending and the receiving of ultrasonic waves. The following diagram illustrates this process:
The ultrasonic sensor we will use for this project is called an HC-SR04 ultrasonic sensor, which is one of the most widely-used ultrasonic sensors. It can measure distances in the range of 0–180 cm, with a resolution of about 0.3 cm. It has a frequency of around 40 KHz. The HC-SR04 sensor...