The sensor continuously sends out infrared light and measures how much of that light is reflected. When a reflective object is within its set detection range, it returns a low signal. The Arduino ...
Simple Arduino sketch that measures distance using an HC-SR04 ultrasonic sensor and prints the value to the serial monitor at 9600 baud.