With standard off-the-shelf type IR components, this isn't incredibly precise, but here's
one way to do it: http://www.rentron.com/PicBasic/infr..._detection.htm

If you want something pre-manufactured, and a bit more accurate, then do a Google search
for Sharp GP2D12. I've never used on myself, but I hear they're fairly accurate.

Laser range-finders are a great deal more complex + expensive, but still an option if you have
the budget. Here's an intro http://www.repairfaq.org/sam/lr/

You can find a LOT more with a quick search at Google.