I have recently started to try and make an IR distance sensor using the following two items purchased from jaycar:
Everything seemed to work fine, I was powering the Ir Emitters and using the analogRead function to return a value between 0-1023 from the Infrared Photo-transistor.
My issue starts when the sensor is hit with ambient light. I have encased the Infrared Photo-transistor in 5mm plastic pipe though light is still able to hit the sensor and completely change the values.
I have read about Infrared modulation which sounds like it will fix the problem, I have started by using the tone function with the IR emitters to generate a frequency of 38kHz which seems to be working fine because I still receive the same readings as I did previously.
Even with the IR emitters running at a frequency of 38kHz I am still having trouble with ambient light, which I kind of expected as no adjustments have been made to the Infrared Photo-transistor.
I am wondering if have purchased the wrong type of Infrared Photo-transistor? Maybe I need a sensor that is set to a specific frequency. Or I need to apply either a hardware or software based adjustment/addition to make the Infrared Photo-transistor work with a 38kHz frequency? Or I could be completely on the wrong track.
I have tried searching for information about setting up an ir sensor with frequency modulation for Arduino though I have not found much.
I really want to get this distance sensor working correctly, I have attached an image of the circuit and the Arduino code that I’m using.
Any help would be greatly appreciated, thank you for taking the time to read my post.
code.ino (868 Bytes)
code.txt (893 Bytes)