Go Down

Topic: IR Sensor Algorithm and suggestions (Read 1 time) previous topic - next topic


Hello again.

Now I have the IR sensors working I am starting to work toward my application.  Like I said previously I have the emitter/detector combo from sparkfun (the individual pair, not the packaged ones).  I am going to use them just like the packaged ones for detection if reflection occurs.  The problem is that it will be transmitting through plexiglass to a reflective material when it is in the correct location.  So technically there will always be a signal.  I was wondering, will the signal even be different if it hits the object past the plexiglass or not?  I guess i don't know how the wave acts through glass and back again. 

If it does increase I could do something along the lines of this.
Code: [Select]

int irpin = A0;
int firstIR = 0;
void setup(){
// setup analog input
// wait
// use this signal as intial value for calibration
firstIR = analogRead(irpin);

void loop(){
  // if the value is greater then the value without the object then the object is there
  if(analogRead(irpin) > firstIR){
      // object detected

The only is what happens if what happens when you start the object is there.  Then that wouldn't work.  The code could be modified though to detect a higher or lower change with a buffer value.  So say if the analoginput is < firstIR - 10.  But this is just an idea.  An ideas of this or what will work for this. 


If it is a fixed setup with controlled lighting conditions (i.e. no change in ambient IR intensity) you can hardcode a threshold value into the program.
This way you will always know if the object is there or not without a need for initial calibration.

If the lighting conditions cannot be controlled, you will have to calibrate the program when starting it and also take into account possibly changing conditions over time.
If you know the object will always only be there for a short time (to trigger something for example) you could use an average reading as a dynamic threshold.

If you give us some more details on the application we might be able to help with more direct suggestions.

Good luck.

Go Up