Minimizing IR Detection Interference
This is actually something I have been meaning to try but never got around to it.
My idea is to drive the LED with PWM with a 50% duty cycle. The frequency isn't really that critical, but you don't want it too high for the next part.
Now you sample the receiver at a fixed frequency that is at least 2x the frequency of the PWM into a buffer.
Then you perform FFT on that buffer.
The bucket that contains the frequency of the PWM should have a power value that is proportional to the distance.
Other light sources will be unlikely to affect the same bucket as the PWM frequency - most will only affect the lowest (0Hz+) bucket.
Or that's the theory that I came up with. I have yet to try it in practice.