Infrared Sensors~Code to make them work?

You're going to want to buy a Sharp IR range sensor to do this. It's not a trivial matter to use discrete IR phototransistors and emitters to build an equivalent.

Interfacing these devices is simple; the sensor has connections for power, ground, and one connection goes to an analog pin on the Arduino. An analogRead() of that pin then returns a value between 0 to 1024 which is relative to the distance from the sensor to an object in front of it.