The Sharp GP2Y0A02YK0F can be powered from the 5V supply on the Raspberry Pi. The Analog output is less than 3V and so can easily work with the logic level circuit. If you buy one of these look for thecable that goes with it to save you some bother.
This project builds on two previous projects in this blog. For the Analog to Digital SPI electronics and Python code first go here: Raspberry Pi hardware SPI analog inputs using the MCP3008. For the TextStar LCD first read this: Raspberry Pi with TextStar Serial LCD Display.
In the first video below the sensor is held in a clamp at the very top left of the picture. You can just about make out the display showing the distance to my hand. At the other end of the table there’s a chair so when I lift my hand up it shows the distance to that instead – about 118 cm. The second video is a close-up of the screen while I move my hand forward and backwards in front of the sensor. Again the jumps to 118 cm are when I raise a lower my hand.
Each Friday is PiDay here at Adafruit, be sure to check out our posts, tutorials and new Raspberry Pi related products. Have you tried the new “Adafruit Raspberry Pi Educational Linux Distro” ? It’s our tweaked distribution for teaching electronics using the Raspberry Pi.