http://makeprojects.com/Project/Laser-Harp/690/1
Anyone who has played with a touchless D-Beam control on a Roland synthesizer will recognize these sensors immediately. The GP2D12/GP2D120 range sensors fire a pulse of IR light and measure distance by triangulating on the reflection.
For musical applications, Iāve found that the output from these sensors can be noisy, due to the constantly flashing IR drawing a lot of current every 40ms. You can smooth the output by connecting a capacitor between voltage (pin 3) and ground (pin 2); I used some 300μF tantalum caps.
You can also filter the signal with a dedicated filter circuit (see schematic online), or in the software, by averaging consecutive readings and using the average value.
Before connecting the range sensors, I removed them from their plastic housings. They connect in parallel to +5V power, ground, and the Arduinoās analog input pins 0ā5.
The output from the range sensors is nonlinear, so the software converts output voltage into centimeters of distance using a simple equation, courtesy of Acroname Robotics (acroname.com).
For the GP2D12 sensor: Range [cm] = (6787 / (Voltage ā 3)) ā 4
And for the GP2D120: R = (2914 / (V + 5)) ā 1