DIY IR proximity detector

Hey!

I am not sure where to post this, so admins: feel free to move the post if you must!

I am looking at building something like this: http://www.k2.t.u-tokyo.ac.jp/perception/HapticRadar/index-e.html

Problem (challenge :wink: ) is, I don't want to pay $10-15 for a halfway decent IR-range sensor! So I got to thinking... What if I hook up a source of infrared light (IR-LEDs) to a digital output on the Arduino, and a photoresistor with a visible-light-shield (so it only picks up IR) to one of the analogue inputs?

Psuedo-code (my Arduino is still in the mail, so I can't test this idea nor the code yet) for the sensor readings would look something like:


int val = 0;

void setup()
{
pinMode(1, OUTPUT); // sets the digital pin as output
}

void loop()
{
digitalWrite(1, LOW); // turns the IR-LEDs off
val = analogRead(1); // reads amount if infrared light hitting the sensor with the IR-LEDs off
digitalWrite(1, HIGH); // turns the IR-LEDs on
val = analogRead(1) - val; // reads amount if infrared light hitting the sensor with the IR-LEDs on, and subtracts reading of ambient IR-light
// val should now represent the amount of IR-light reflected off of a surface close to emitter and IR-sensor
}


I would greately appreciate any feedback from you guys and gals in here, as I do not by any stretch of imagination equal your experience pr knowledge with regards to electronics.

My first post, an noone replies despite me trying my best to spell and write decently good english. :cry: snivels Oh well, guess who won't be too inclined to share when he gets some extra sensory input! :wink:

In principal they work pretty simply a fixed quantity of light is emited and the amount reflected indicates distance.

There are a number of gotcha's

The material doing the reflecting greatly affects the quantity of light returned (mirror/black body).
Ambient IR WILL affect a simple (non-pulsed) light source/receiver combination.
Electrical noise crossover between transmitter and receiver.

If I were you I'd look at experimenting with homemade ultrasonic sensors first. It is very unlikely you could produce a homemade IR sensor that approached the functionality of one of the commercial units for anything approaching the cost of a commercial IR sensor ($12 is very CHEAP for what you get).

If you still want to pursue, one Idea I would consider is to eliminate the measured range component and work on a discrete number of ranges (ie 2 or 3). This could be accomplished with 2 or 3 sensor circuits set to different levels of sensitivity. My gut tells me this might prove easier to get working (op-amp circuits are easy) and could also implement filtering. If you get this working you could increase the number of ranges by simply reproducing the circuit as many times as needed.

You could even use multiplexers to feed multiple sensor points into the single set of circuits to allow the op-amps to sense from multiple directions (one at a time)

In principal they work pretty simply a fixed quantity of light is emited and the amount reflected indicates distance.

There are a number of gotcha's

The material doing the reflecting greatly affects the quantity of light returned (mirror/black body).
Ambient IR WILL affect a simple (non-pulsed) light source/receiver combination.
Electrical noise crossover between transmitter and receiver.

If I were you I'd look at experimenting with homemade ultrasonic sensors first. It is very unlikely you could produce a homemade IR sensor that approached the functionality of one of the commercial units for anything approaching the cost of a commercial IR sensor ($12 is very CHEAP for what you get).

If you still want to pursue, one Idea I would consider is to eliminate the measured range component and work on a discrete number of ranges (ie 2 or 3). This could be accomplished with 2 or 3 sensor circuits set to different levels of sensitivity. My gut tells me this might prove easier to get working (op-amp circuits are easy) and could also implement filtering. If you get this working you could increase the number of ranges by simply reproducing the circuit as many times as needed.

You could even use multiplexers to feed multiple sensor points into the single set of circuits to allow the op-amps to sense from multiple directions (one at a time)

Thanks for your reply! Still have a couple questions I need to put to rest if you don't mind. =)

I know the material doing the reflecting will greatly affect an IR-sensor but that is not very important to me, as I am just doing this to see how good I can make it compared to something that costs 10x more. Besides, wouldn't an ultrasound-sensor have at least a semblance of the same issues? Some materials are extremely reflective to sound, some mostly let it pass through and some are "dead", as in they absorb sound-vibrations..

And as to ambient light/IR affecting my sensor-readings.. won't I have a fair shot at negating this by, like I proposed, taking one reading with the sensors IR-source OFF (to get an ambient IR-light reading), then taking one with the sensors IR-light ON and subtracting the two? With Arduino, I am guessing I can do this quite a few times per second (and if needed average a few readings at a time), though nowhere near the KHz frequencys that commercial IR-proxys are modulated at.

As to your idea on how I could do it.. I want it to be as small, compact and cheap as possible while still beeing usable. Know the KISS-rule? Usually try my best to enforce it in my programming, and experimenting in general. Keep It Simple, Stupid! :wink:

I will post my results once I get my Arduino (perhaps today =D ) and get into the fiddeling and gadgetéering. Until then, I appreciate your comments and thoughts on this. I mean, I probably have a lot to learn from the people here, even if I do have to fail misserably myself before I actually learn. :wink:

I know the material doing the reflecting will greatly affect an IR-sensor but that is not very important to me, as I am just doing this to see how good I can make it compared to something that costs 10x more. Besides, wouldn't an ultrasound-sensor have at least a semblance of the same issues? Some materials are extremely reflective to sound, some mostly let it pass through and some are "dead", as in they absorb sound-vibrations..

Yeah but the Sun doesnt produce sound. :slight_smile:
Ultrasonic would have similar issues but they would be far less problematic than IR.

And as to ambient light/IR affecting my sensor-readings.. won't I have a fair shot at negating this by, like I proposed, taking one reading with the sensors IR-source OFF (to get an ambient IR-light reading), then taking one with the sensors IR-light ON and subtracting the two? With Arduino, I am guessing I can do this quite a few times per second (and if needed average a few readings at a time), though nowhere near the KHz frequencys that commercial IR-proxys are modulated at.

You could easily hit Khz frequencies.

Unlike normal computers, the chip in the Arduino does one instruction per cycle.
It runs at 16Mhz so if you take 32 instructions to do a check, which is probably around how long it'll take, you could hit 512Khz.

Yeah but the Sun doesnt produce sound. :slight_smile:
Ultrasonic would have similar issues but they would be far less problematic than IR.

Which is why I would take an ambient light reading. Am I waaay of here? Is there some obvious thing I am missing? =P

  1. Read amount of IR-light from the Sun.
  2. Read IR-light from the Sun + IR from strong emitter on sensor
  3. Subtract first reading from second reading. Sun - (Sun+light from sensor) = light from sensor.

It all makes sense in my head. Is my head not functioning the way it should? Heh.. =P

Which is why I would take an ambient light reading. Am I waaay of here? Is there some obvious thing I am missing? =P

Three main problems:

  1. If its moving, then it becomes tricky since the IR can vary.
  2. Shiny stuff like metal, mirrors, etc...
  3. If its in a environment with lots of IR like in sunlight then the difference between the control sample and the IR sample will be very small.

I was looking at IR emitter/detectors for use in ranging while researching balancing robots. This is the type of sensing that was used the LegWay robot. What they seem to be doing is to try to use two detectors and only trust their relative differences (rather than trying to use them to get an exact range). Of course, the problem still exists that if the two sensors are over two different materials (like transitioning across floor types or whatever), the readings would be way off.

This is a great project- dirty and cheap. DId it work?
R

  1. Read amount of IR-light from the Sun.
  2. Read IR-light from the Sun + IR from strong emitter on sensor
  3. Subtract first reading from second reading. Sun - (Sun+light from sensor) = light from sensor.

The problem is that the sensor saturates when exposed to the sun (it is so bright) so that sun + light from sensor = just sun.

I think this is not the way people build distance sensors. The idea of measuring intensity of reflected light is wrong because white surfaces reflect like 10 times more than black ones. Please correct me if I am wrong but to measure distance you send an impulse (or periodic impulses) and measure the time it takes to travel to the object and back. For that you cannot use a microcontroller because in 1 mks light travels by 300 meters. So I believe you need to switch LED on and off very fast, measure reflected light by photodiode, pass the signal through some frequency filter and compare phases of emitted and received signals by some clever curcuit with transistors and diodes.

I think this is not the way people build distance sensors

No you are wrong, many commercial distance sensors use the principal of reflected IR light. Yes you will get the problems you outline but in IR things with what looks to us to have a different colour are very much the same. The further into the IR you go the more true this is.

The method you suggested will not work either because the phase information in the reflected light is of the same sort of magnitude as the light travel time but this only applies to movement (doppler shift).

There are ways of using IR that reduces the effects of sunlight.
IR light at a wavelength of above about 900nm is not that common in sunlight because of absorption in the atmosphere, and illuminators and filtered cameras working at these wavelengths are typically used in ANPR systems for this reason.
A Wratten 87C filter is almost opaque at visible wavelengths, but at 940nm has 80 to 90% transmission.

No you are wrong, many commercial distance sensors use the principal of reflected IR light.

Oh, I see. Then it might be easier to build than I thought.

well i used ir emmitter and receiver pair i didnt have any problems with the sun but i donno i used it only to detect obstacles