This video outlines both how the ultrasonic sensor works, and how to control one using the Raspberry Pi.
Check out Matt Hawkins' Raspberry Pi Spy website at:
http://www.raspberrypi-spy.co.uk
Learn more about programming, electronics, and the Raspberry Pi at:
http://cutequbit.zapto.org