To measure the distance of an object using an HC-SR04 ultrasonic sensor and display the measured distance on the Serial Monitor.
The HC-SR04 ultrasonic sensor works by transmitting ultrasonic sound waves and measuring the time taken for the echo to return after striking an object. Using this time, the Arduino calculates the distance between the sensor and the object.
The Serial Monitor continuously displays the distance between the sensor and the object in centimeters.
Example:
Distance = 50 cm
Distance = 32 cm
Distance = 18 cm
Distance = 10 cm