IR sensor and ambient light

Hey guys,
I am trying to make an IR obstancle detector - I compare values read from my IR phototransistor when the IR led is off and when it is on. But I have a problem it only works during some settings of light in my room. For example when I turn my lamp on the sensitivity rapidly decreases... So is there any way to filter other sources of normal light? If no, I will probably have to use ultrasonic detection...

Thanks for help.

using ultrasonic would be better idea because many things would effect IR sensor's sensitivity; any remote controller, sun light, brightness of the environment (your case), even color of the obstacle (white is more reflective than black)

even color of the obstacle (white is more reflective than black)

Almost the same is true for an ultrasonic sensor with different materials. If you have an obstacle made of soft materials you might get no response at all (as with deep black and infrared).

You can make an infrared distance sensor more immune against ambient light by making it oscillating (turn it on and off in a fast repetition and putting a filter on the reception side. Of course you loose resolution with this modification.

You get best results if you use both sensors together.

This may or may not help you, but this is how I overcame ambient light for my lap timer project -

EDIT: Pulished the first part of the build along today -

Duane B

rcarduino.blogspot.com

I explain how to do something like this in my free online course: http://www.udemy.com/nanomouse

I had the same issue, and one solution I found was to shield the IR detectors and transmitters. I wrote a whole blog post about it here:

Here is an image of the shielded TX/RX components.