Step 1: Theory
Another problem that takes affect with light based rangefinders is how it can be affected by ambient light. I fix this in my rangefinder by modulating the emitting LED. Without this modulation, a simple light bulb connected to the mains can affect the result by superimposing 50Hz onto the actual signal.
My rangefinder works through having a modulated IR source at an ultrasonic frequency, being detected by a IR receiver (IR photodiode) which is then fed into a high pass filter, amplified and peak detected.