This is the Sharp GP2D12 IR Sensor. It's a popular sensor, and it is used in many robotics applications, so you can find lots of information about it on the Web. It is one in a family of very similar Sharp IR rangefinding sensors, all of which work the same way. See also the "components" page for more information about this sensor. Its range is 10cm to 80cm, so it won't work for things closer or farther away than that.