Pages: [1]   Go Down
Author Topic: IR receiver based distance sensor  (Read 2344 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 6
Posts: 229
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I used both IR receivers, IR LEDs and the library to send and receive - so I am kind of familiar with the concept... The thing is that I am trying to convert them into proximity sensors

The idea is simple - you flash the IR LED and if the beam bounces back it is picked up by the IR receiver (tsop1738).

I generate the required frequency using delayMicroseconds and I vary the power using PWM - the idea is that the IR LED continually loops from 0 power to full power and thx to that I can tell how far the object is.

The problem is that I am experiencing a strange phenomena - the receiver almost constantly picks up the beam - I wrapped the IR LED with a couple of layers of sticky tap - that didn't help much. it only works properly at the lowest possible setting (PWM value set at as low as 5) but then the range is as low as 50 cm or so

Does the IR really propagate that well? Even through a couple of layers of sticky tape ? Or maybe sending the impulses interferes somehow with the receiver ?
ohh and before you ask I do know that the receiver output is normally HIGH - and the indicator LED (the one on arduino board) isn't always on - it flashes (check the code)
Code:
const int IR = 4;     // the number of the IR receiver pin
const int ledPin =  13;      // the number of the LED pin (blinks when object detected)

// variables will change:
int IRstate = 0;         // variable for reading the IR status


void setup() {Serial.begin(9600);
  // initialize the LED and IR LED pin as an output:
  pinMode(ledPin, OUTPUT); 
pinMode(6, OUTPUT);   
  // initialize the IR receiver pin as an input:
  pinMode(IR, INPUT);

}

void loop(){
  // read the state of the pushbutton value:
    for (int i=0; i <= 5; i++){
    delayMicroseconds (26);analogWrite(6,i);
    delayMicroseconds (26);analogWrite(6,0);
   
   

 

 
  if (digitalRead(IR) == LOW) {     
    // turn LED on:   
    digitalWrite(ledPin, HIGH);delayMicroseconds (3);break;
 
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}}
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8854
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your problem might be that a IR remote control receiver is designed to be very sensitive and to work over a very wide range of intensity.

You might have better luck with a IR photodiode or phototransistor.  This will give a more analog response.  You should compare the signal with your transmitter ON and OFF to separate the reflected signal from the background.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Full Member
***
Karma: 6
Posts: 229
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Turns out a couple of turns of sticky tape isn't enough to block IR beam. Replaced with something more substantial and it kind of works  smiley-roll-sweat

I say kind of as it senses objects but not very consistently. I am sure it's not only because some objects reflect IR better than others - it's more complex...


When object is sensed let's say 60 cm from the sensor the sensor keeps sensing it even when I move it 100 cm away from it. But if I move any further and the sensor stop receiving the beam I have to move the object back to 60cm distance from the sensor for it to start sensing it again

It seems the IR receiver circuitry kind of adapts or something... I guess that's caused by the circuitry inside the IR receiver. The code I use doesn't work properly - don't know why... 38khz frequency suggests 26us period, right ? Well I thought I had it wrong (since it was 26us ON and 26us OFF) that but I changed it to 13us ON and 13us OFF and the result is the same.

If I use the IRlibrary to generate 38khz frequency on the LED the range drops to like 30 cm max but it is consistent

What's even better - I get about 3-4 meter sensing range if I use a remote control as the IR source

So uhmm now I am kind of lost  smiley
« Last Edit: February 28, 2013, 06:25:17 pm by kerimil » Logged

Lost Wages
Offline Offline
Full Member
***
Karma: 11
Posts: 103
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe I am way off, but measuring proximity of materials that have varying IR reflectivity will be difficult -- even with a recalibration of each new material.  To my mind, detecting proximity is best done by sending out a burst of energy and then timing how long (rather than how strong) it takes for the signal to return -- like radar.  Radar uses radio-frequency energy and this works well at long distance. At short distances the energy, moving near the speed of light, creates timing problems.

Thus, I would opt for a slower-moving energy and use sound.  There are any number of Tx / Rx ultrasonic modules that you could adapt for your project.

Just a thought...
Logged

0
Offline Offline
Full Member
***
Karma: 6
Posts: 229
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thx but I already have an HC-SR4. I know there are IR based proximity sensors but they have limited range and are very expensive. I have experimented with IR before and I know the range is much greater - it would be cool if I could come up with a cheap IR sensor.
« Last Edit: March 01, 2013, 08:36:00 am by kerimil » Logged

Dubuque, Iowa, USA
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2514
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It seems the IR receiver circuitry kind of adapts or something... I guess that's caused by the circuitry inside the IR receiver.

Yes, IR receivers automatically adjust their sensitivity. If you look at your datasheet it will refer to this as "automatic gain control" or "AGC" in the block diagram. You can compare this to Vishay part TSSP4038 which does not adjust its sensitivity (it's "fixed gain").

TSSP4P38 is what you're looking for if you want to do distance detection. http://www.vishay.com/docs/82474/tssp4p38.pdf. This is $.95 at Digikey.

See also http://www.vishay.com/ir-receiver-modules/ for a nice matrix list of different IR receiver types.
Logged

0
Offline Offline
Full Member
***
Karma: 6
Posts: 229
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thx that was really helpful
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 626
Posts: 34159
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

thx but I already have an HC-SR4. I know there are IR based proximity sensors but they have limited range and are very expensive. I have experimented with IR before and I know the range is much greater - it would be cool if I could come up with a cheap IR sensor.

That is because they do not use signal strength to determin the distance but they have several sensors and measure in effect the return angle to get the distance.
Logged

Pages: [1]   Go Up
Jump to: