This is the HC-SRO4 Ultrasonic Distance Sensor. It's a common choice for measuring distance in all sorts of electronics projects.
On a basic level, this sensor operates much like a sonar on a submarine. It emits pulse of ultrasonic sound (at 40 kHz) and measures the amount of time it takes for that sound to bounce off an object and return to the sensor. Since both time and velocity are known, the distance from the sensor to the object can be easily calculated.
This particular model has a range of 2-500 cm and a maximum resolution of 0.3 cm. It measures outwards in a cone with 15° spread.
That spread angle is important to understand. 20cm from the sensor, the sensing area is a ~10cm wide circle. But 200cm from the sensor, the sensing area is a ~106cm wide circle. The sensor does not measure along a single laser-like ray; small objects will not be detected reliably.