When you build a robot, it’s nice to have layers of sensors. You can think of the layers either top down (maybe starting with a 3D laser scanner), or from the bottom up (are my motors stalled?). Proximity sensing sits on one of the lower layers, and generally is used as “Hey, there’s something near me, and it might be in general direction X”.
Using infrared LEDs and detectors is an inexpensive and common approach to basic proximity sensing.
I did a presentation on this topic for the Nashua Robot Builders. You can find the slides and demo code at https://github.com/robojay/IrProximityDemo