How to use infrared receiver sensors for collision avoidance

Thanks! Stuff to learn about…

Hey Thanks, Ro-Bot-X

Not only a good How-To but a good Why-it-Works.  

Not to get too Spamish, but you can make 5 of these for $3 with these:

http://arduino-direct.com/sunshop/index.php?l=product_detail&p=208

http://arduino-direct.com/sunshop/index.php?l=product_detail&p=210

And LMR members get 5%plus5% to the site if you sign up and send an email to me; [email protected]

I’ll do some experiments with this… 

Great writeup job.  LMR may be collaborating in WIKI stuff and this could all end up where people can find it… For now, my How-To stuff is here: http://arduino-direct.com/sunshop/index.php?l=product_detail&p=210

Regards, Terry

 

Wow Terry, you have good

Wow Terry, you have good prices for the IR LEDs and receivers. I need to order a pack to do some tests and come up with a little board… I am already in the process of designing a board that can be mounted on a servo with a single sensor and another that can be used either separate or as a shield on Arduino, but tests must be done first.

Hey, I was just sketching on

Hey, I was just sketching on the “servo-pointed-sensor” stuff.  I would like a simple easy-to-reproduce design that uses a small servor to rotate sensors (Ultrasonic and IR) over 360 degrees. Some cool but expensive robots use a gear system or a continuous-rotation servo with limit switches.  

How about the sensor block sits atop a pencil-sized vertical shaft and the servo arms push and pull on a thin cord wrapped around the shaft and permanently attached at one pint so it doesn’t ‘creep’.

These sensors don’t have real sharp horizontal resolution and reasonable accuracy is fine.

I bet someone has done this. Pointers? Comments?

I want a design that I can show that anyone with real simple materials and a trip to the hardware store or Fa Da Te (DIY in Italian) can make. 

I bet the 38 KHz IR could be made pretty sharp resolution with a simple lens and slit, though. 

 

 

 

 

Receiver vs Phototransistor

I understand that because these receivers are only looking for IR light modulated at 38 KHz they are less susceptible to outside interference. I was wondering if there are also other advantages over a plain old IR Phototransistors like used in Mr General’s Compound Eye or a QRD1114  

The IR phototransistors work

The IR phototransistors work at short distances. The IR demodulators work as far as 8 feet. All you need to get such a great distance is a powerful IR LED. Since the LED is pulsated for short times, you can have a very low resistance in series or even none and the LED will survive and will give up lots of light. At close distances you can make the pulse bursts less than 10 miliseconds, but at long distances it’s a must. Make sure you’re using 5mm LEDs not 3mm for long distances. I was experimenting with both sizes and saw a big difference with the same 220 ohm resistor in series with both.

Thank you

Thank you

Great Post, Exactly What I Was Looking For, But…

Ro-Bot-X,

   Thanks for a great post!  This is exactly what I’ve been looking for.  I ran out and grabbed one of these sensors from the dreaded “Shack” to try it out.  I hooded my IR LED with some shrink wrap and set it forward of the sensor.  I get about 8 inches for 38 kHz at 5V.  I tried varying the duty cycle, but I didn’t see much difference in the sensitivity.  Then, I tried to change the period.  At 34 kHz and at 44 kHz, I get no reaction at 50% duty cycle.  Is it just a matter of aligning the emitter and receiver?  I was hoping to take readings at various period lengths to determine distance.  I’d love to have the sensor trigger at 4-5 cm and another sensor to trigger at 7-8 cm.  Any help appreciated.

Thanks!

EDIT:

   I may have my problem.  I see that your code includes a delay between write/reads:

void loop(){
  IR38Write();
  if (digitalRead(IRsensorPin)==LOW){
    digitalWrite(D13ledPin, HIGH);
  } else {
    digitalWrite(D13ledPin, LOW);
  }
  delay(100);
}
  How long is “delay(100)” ? 

little mistake.

In the circuit above the servo’s black wire is connected to + instead of -

IR Compound Eye updating??

Anyone have one of these and working on updating to 38KHz operation??

I have some coming from Dagu, but will take a while to get here from YourDuino.com to me in Italy.  I think they will sell for about $10 in the LMR shop. Maybe we can all figure out an easy way to upgrade these to 38KHz and longer distances… they certainly have lots of LEDs…    Here’s the schematic.  Looks like it wouldn’t be that hard to update it for 38KHz. 

We have the receivers here: http://arduino-direct.com/sunshop/index.php?l=product_detail&p=210

Wire into anything with a piece of this: http://arduino-direct.com/sunshop/index.php?l=product_detail&p=185

Anybody have time to try this out?? 

 

Regards, Terry King

...On the Mediterranean in Italy

[email protected]

 

Thanks for trying out this

Thanks for trying out this sensor. I think some sensors (different manufacturers) may be less sensitive than others. The Panasonic PNA4601M sensor definitely behaves this way. I have an old TSOP4838 that also works, but there are many TSOP sensors that work at 38kHz and are not sensitive to other frequencies. To get 35.7kHz you have to set delayMicroseconds(14) in the IR38Write function, to get 41.6kHz set delayMicroseconds(12). Sensor alignment should not matter, because the LED emits a cone of light and the receiver also has a detection cone. More importantly is  to use a light color material as the object when testing (white paper for example). 

Oh, and the delay() function in Arduino expects miliseconds as argument. 100 miliseconds is just to have a break between sensor measurements.

 

I guess you’re right, I

I guess you’re right, I moved the servo a bit and the wire moved with it and I didn’t check back. Thanks for noticing, I’ll fix it.

Does a TSOP 4838 work with the code above?

Hello Everyone!

   My question is regarding the code above. Has it been verified to work with a TSOP 4838 38KHz receiver? Or has any one tried it and was successful? If it’s verified to work with a 4838, then if anyone can please point me to the right direction… I have two IR receivers on hand; one is a 4838 and another one is a PNA4602m I salvaged from a broken toy. The 4602m works just fine with the code and circuit specified above but the 4838 doesn’t. I might be missing something… I just bought the 4838 off Ebay, Im beginning to think it’s defective since the 4602 works perfect. I tried different alterations on the code and the circuit like changing the half cycle delay lower and higher; or changing the supply voltage/resistance from the minimum to maximum based on the 4838’s datasheet. Any opinion or comment is very welcome. Thanks in advance! : )

 

It should work with

It should work with TSOP4838, I’ve tested it some time ago. There are 2 things that might not let it work. First, the length of the burst pulse, in the code I used 10ms, perhaps you can shorten it to about 2-3ms. Also, the receiver may need to be shielded from reflected IR light going out from the back of the LEDs or it will switch to low regardless if there is an object in front or not. If the receiver does not switch to low at all, it may be defective.

Thanks

Thanks for the tips. It seems that it is defective or I got the wrong part. I checked the impedance accross pins 1 and 3; I should be getting 30Kohms according to the datasheet, I’m reading close to 100K. I tried shortening the burst length to 2 and 3ms (int i = 0; i <= 115; i++) and (int i = 0; i <= 77; i++), still no response from the receiver (doesn’t go low). I’ll try to get another one and give that seller a - feedback if he doesn’t do something about it. : )

Still can’t figure it out…

Ok so I’ve got a new set of TSOP4838 receivers but I’m still getting the same results like I did with the first receiver I got (it still wouldn’t go low). And again if I switch it with the other module which I believe is a PNA4602m receiver, the proximity sensor works on about 5-6 inbches. I bought a total of 5 TSOP4838s and all of them are doing the same thing. They can’t be all bad… Plus I purchase them from a different store than the first one. After some experementations, I found out that if I use the remote for my Sharp TV, the TSOP4838 is able to pick it up; so with the code and the circuit exactly as above, it would flicker the LED. I did a little research and it seems that Sharp uses the same 38KHz carrier frequency on their remotes. I can’t think of any reason why the TSOP4838 would detect an IR signal coming from the remote and not with the generated one (as indicated above). It also seems that the 4838 requires a shorter burst time; which I also did try with several different cycles but still no effect. It just doesn’t make sense to me. I’m sure I’m missing something. So please if anyone can shed some light, I’m very grateful!

Looks like either your IR

Looks like either your IR LED is of a different light length (it has to be 940nm) or there is something fishy about the connection. Hard to say… I had limited success when using 3mm IR LEDs but it worked great with 5mm LEDs and if I lower the resistance to about 22 ohms I can detect a wall at a couple of meters away. TSOP4838 is what I’m using and it works perfectly, so if you got new sensors and still does not work, it has to be something else. 

To test the sensor even without the microcontroller, you can tie the cathode of a red or green LED to the signal (output) pin of the sensor and the anode through a 220 resistor to the Vcc pin. When the output pin goes low, the LED will light on. If the sensor works with the remote and it doesn’t with the IR LED from the microcontroller then look for the problem there. Either the LED or the code is not quite right. You don’t specify what kind of microcontroller you use, I have assumed you’re using an Arduino, but if you set the fuses yourself, perhaps there might be a problem there (for instance you have divide by 8 checked so the code does not run at the proper clock rate). Also, if you use a breadboard, there might be a bad connection in the breadboard itself, many had problems with that, including me. 

I have same problem where

I have same problem where the receiver works with the remote, but not with my IR led. On the camera I can see the IR LED flashing, but the reciiver doesnt pick it up. I checked the manual and it says “wavelenght 950nm”. You said it has to be 940. Could it be the problem? Because otherwise I dont see what Iam doing wrong.

Noise blocking.

This part:

void IR38Write() {
  for(int i = 0; i <= 384; i++) {
    digitalWrite(IRledPin, HIGH);
    delayMicroseconds(13);
    digitalWrite(IRledPin, LOW);
    delayMicroseconds(13);
  }
}

however I don’t know this programming language, I see this loop repeats 384 times, but the tsop will see this as continuous noise and bock this… Try to change that in:

void IR38Write() {
  for(int i = 0; i <= 5; i++) {
    digitalWrite(IRledPin, HIGH);
    delayMicroseconds(13);
    digitalWrite(IRledPin, LOW);
    delayMicroseconds(13);
  }
}

 

so it repeats only 5 times, what should be enough.

Should it be exactly 940 or

Should it be exactly 940 or is 950 ok too?

From the datasheet, the peak

From the datasheet, the peak sensitivity of the TSOP4838 is at 950nm, and the sensitivity at 940nm is only a few percent less.
In other words anything within about +/-50nm from 950nm and you won’t be able to tell the difference.

Since you’ve checked the IR LED is lighting up with the camera, I’d say the next thing to check is your code, specifically to make sure the frequency that you’re pulsing the LED at is correct. The TSOP4838 expects a signal modulated at 38kHz, and is pretty intolerant of other frequencies.
To give you an idea of how touchy the TSOP4838 is, consider that the sensitivity drops by more than half if your frequency is off by +/-10%. If the modulation frequency is off by +/-30%, the sensitivity is down to less than 1/5th of what it would be at 38kHz.