IR distance sensors are one of the most used distance sensors. They fall in 3 categories:
(Short range. Not more than 2 - 3cm)
This type uses an IR-LED and IR-diode (or phototransistor). When an object is close to the sensor it reflects the light emitted by the LED to the IR-diode. Using modulated IR-light (A) and filtering (B) the input signal of the IR-diode leads to better results as this blocks (much of) other IR-light. There are ICs that contain both a modulator, IR-diode and filter-circuit.
(Larger range. Around 10 - 30cm) e.g. Sharp has a family of sensors that use this principle for measuring distance. They consist of an IR-LED and an IR-sensitive LDR strip. Combined with built-in optical lenses, the reflected beam's position on the LDR depends on how far the object is.
line detecting sensor
Similar setup as the reflection IR-sensor, but aimed downwards to detect lines on the ground. This sensor makes use of the difference in reflection between a white background and a black line.
More advanced robots use multiple line detection sensors to follow a line more cleanly.
Ultrasonic distance sensors use sound to measure distance. These sensors emit an ultrasonic pulse train and then measure the time until the pulse is reflected. Since the speed of sound is (more or less; excluding temperature and wind) constant in air (approx. 344m/s) it is easy to calculate the distance to the reflecting object. These are used for distance ranging from several centimeters up to a few meters.
Laser based distance sensors use the same principle as ultrasonic distance sensors, but use light instead of sound. These sensors are only useful for longer distances. (At least several meters.)