Let's Make Robots!

Make your own IR obstacle detection sensor

OddBot's picture
Detects objects at close range. Can be used for object tracking.
Cost to build: 
$4
AttachmentSize
OBJECT_TRACKER_.BAS1.24 KB
OBJECT_TRACKER_V1.7.BAS1.89 KB
MPSA13.pdf154.35 KB
MPSA14.pdf43.7 KB

Now with video of the sensor being used as a Mintvelt inspired object tracker! This sensor is a short range obstacle detector with no dead zone. It has a reasonably narrow detection area which can be increased using the dual version. Range can also be increased by increasing the power to the IR LEDs or adding more IR LEDs

The photo below shows my test setup with some IR LED's (dark blue) as a light source and two phototransistors in parallel for the reciever. You could use one of each but I wanted to spread them out to cover a wider area. This setup works like a FritsLDR but with IR. It has a range of about 10-15cm (4-6 inches) with my hand as the object being detected.

I'm only running my LEDs about 20mA. My LEDs are capable of 50mA continuous and some LEDs are capable of 100mA (see "Getting the most from a LED").

I'm using this setup on Junior as a general purpose object advoidance sensor to prevent him backing into anything. I'm getting a good response with less than a volt when my hand is up close and reflecting the IR and over 4.5V with no IR.

IR_amp_closeup.jpg

To get this to work well with an A/D input it needs to have a much lower impedance (needs to let more current through). You can do this with an op-amp but most op-amps like more than 5V and are usually more expensive than my one transistor and three resistors. This is a simple one transistor amplifier that gives my ADC good resolution. Click on the schematic for a larger picture.

IR_sensor_Schematic__small_.jpg

Starting from the left you can see my two IR LEDs with a resistor and transistor in series. The transistor allows the processor to turn the LEDs on or off. This is necessary to tell the difference between the ambiant IR from daylight and indor lighting and the reflected light from the LEDs that indicates the presence of an object.

Next are my two phototransistors in parallel with a 1M resistor in series. You could use only one but I wanted to cover a wider area so my transistors will point in slightly different directions. If either one detects IR it will allow more current to flow. Since volts=current x resistance, even a small increase in current will create a reasonable increase in voltage across the 1M resistor. Unfortunately the low input impedance of many AD converters will act like a small resistor in parallel with the 1M resistor and dramatically reduce the output to the processor. This is where our BC549 transistor comes in to save the day. In conjunction with the 1K and 10K resistors it amplifies the signal so that the analog input on your processor gets a nice strong signal.  The BC549 is not too critical, just about any general purpose signal transistor should do. My transistor had a hfe of 490 when measured with a multimeter. You should probably have a hfe of at least 200-300.

IR_sensor__small_.jpg

As you can see my sensor is made from liberal amounts of hotglue. Click image for a bigger picture. This has the advantage that you can flex the leds and transistors outward to cover a larger area. This is Juniors reversing sensor to prevent him reversing into anything and as such will cover a wide area. I will make single Led/Phototransistor sensors for front left and front right. This will allow him to avoid crashing into obstacles when his rangefinder/object tracker is looking elsewhere.

Note that the phototransistors are slightly forward of the blue LEDs. This helps stop stray light from the LEDs being detected.

 

 

 

 

 

 

Below is the sensor hooked up to Juniors mainboard which has three of my amplifiers built in.

IR_Sensor___Mainboard.jpg

 Using a simple test program that turns on the IR LEDs, stores the value of the ADC, turns off the LEDs, reads the ADC again and then subtracts the stored value from the recent value I was getting readings from 6 to 940. This was with the curtains closed and the lights off. When the reading was 6, my hand was about 300mm (1ft) away. With the lights on the values ranged from about 60 to 940 with a value of 60 being with my hand only about 150mm (6inches) away. Considering the max possible resolution with a 10bit ADC is 0 to 1023, I thought 60-960 with the lights on was a very good result.

After a comment about using sleeves I repeated these test with heatshrink sleeves on the LEDs and phototransistors. The sleeves actually had a negative effect and reduced the range. After I removed the sleeves I did not get the same reduction in range with the lights on. I don't know if it is because during the first test it was daylight outside and the curtains didn't block it all or if it was the way I held the sensor but the second set of test gave an almost identical range of approximately 300mm (12 inches) reguardless of the lights being on or off. I'll have to try again tomorrow when it is daylight again. It seems my initial test was at fault, maybe the way I held the sensor?

IR_Sensor_Single__small_.jpgThis is the single version of the sensor and will cost about half. In the photo you can see the current limiting resistor for the LED. Ignore the value as I had different requirements for Junior. Use the values shown in the schematic.

I've joined the positives together so there is only three wires going back to the mainboard.

Note that the phototransistor is slightly in front of the LED to prevent stray light from the LED being detected.

 

IR_Sensor_Single_2__small_.jpgOnce again I've used hotglue and heatshrink to make it solid and well insulated.

 

 

 

 

 

 

 

 

 

 

 

This is the schematic for the single version. Click on it and the photos for larger images.

IR_single_sensor_Schematic__small_.jpg

Because this sensor only has a single phototransistor it isn't quite as sensitive. To compensate I've increased the current to the LED to almost 50mA which is the maximum continuous current allowed. Because the LED is pulsed on and off this is quite safe and could have been increased to 100mA. The problem with pushing a LED to its limits when controlled by a proccesor is that if a fault occurs in the software then the LED could be destroyed.

When tested, The readings from the ADC of the picaxe ranged from about 100 - 910 reguardless of background lighting. Despite the slightly reduced resolution due to a single phototransistor the range was about 400mm (16inches). This increased range was due to the increased power to the LED.

Make certain your LED and phototransister are parallel to each other for good range.

It was asked how wide is the detection area. Using my hand as the object at a distance of aproximately 300mm (12 inches) from the single sensor the detection area was about 150mm (6 inches) wide. The double sensor can detect a wider area if the phototransistors are spread out at different angles.

Using my hand sideon to the single sensor the detection area was only about 60-70mm (2-3 inches). This is reasonably narrow due to the lenses in the LEDs and the phototransistors.

It should be noted that this is not a linear sensor because the intensity of light from the LEDs is 1 divided by distance squared. In other words, when the object is twice the distance away, the IR from the LEDs is 1/4. As a result, the closer the object, the better the resolution.

This would be a useful sensor to fill in for the dead zone of other IR sensors such as the SHARP GP2D12. To prevent interferance, one should be disabled when using the other.

 


 

As mentioned at the start, I've also experimented with using two of these sensors for a simple object tracker inspired by Mintvelt's "four eyes". This version can't tell the size or distance of an object but can track an object well enough for a robot to recognise a moving object and give chase. Wish I still had a cat, imagine a robot with a waterpistol chasing a cat around the house :

I've attached the code used in the video as well as an improved version (V1.7) that eliminated the servo jitter.

 Object_tracker2__small_.jpg

 

 Good luck and enjoy :)

 


Sunday 4-1-2009

 

This is the latest version of my object tracker as used in SplatBot. I've used 20 IR leds to increase the range. They are limited to 50mA at the moment so that they can't be damaged by faulty code. If I was to push them to their limit then the range could be increased further but they could then be damaged by something like an interupt routine occuring when the LEDs are on.

IR_sensor_array__small_.jpg

This is the schematic.

IR_sensor_array_Schematic__small_.jpg

Click on it for a larger picture. I found with all The LEDs on that the sensors were swamped by reflected IR from my hand even at a distance of about 400mm. The circuit works fine and I definitely get a lot more range but I'm going to have to remove the sensors from the board and mount them seperately so that I can adjust their distance relative to each other to optimise tracking and so I can better shield them from ambiant IR.

This is a work in progress.

 


Updated: 19-1-2009

I've experimented with improving and simplifying the detection circuit. This will give you better range.

IR_obstacle_detector_3_Schematic.jpg

The MPSA13 is a high gain darlington transistor with a hfe of over 5000. If you get the MPSA14 it has about twice the gain. By adjusting the 500 ohm trimpot you should get much better range than the old circuit.

 

 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
unigamer's picture

just want to say thanks! Works very well. For anyone in the UK who wants to get rupped off at Maplin, I am using the following two things and they work

 

Phototransistor

http://www.maplin.co.uk/module.aspx?moduleno=17936

 

 

Ir Emittor

http://www.maplin.co.uk/module.aspx?moduleno=2262

 

 

And thanks again :)

BruuD's picture

Hey OddBot,

Very cool object tracker, i will definatly try to make this too.
One question about your code tho.
I see you read 2 analog inputs, one for each phototransistor, but the schema shows the transistors in paralel with only one analog output.

I'm very new to this so maybe i misunderstood, but it looks to me like that schematic and code don't match.
I should probably setup the phototransistors as shown in the schematic of 4-1-2009 ?

/BruuD 

TeleFox's picture

Each analog input has two phototransistors in parallel to increase the sensitivity - basically each phototrainsistor pair acts like one big phototransistor.

The 19/1/2009 diagram replaces the double phototransistor config with a single phototransistor and an amplifying transistor, which according to OddBot's testing gave the best overall results. Note that the diagram only show 1 channel, you'll need to make 2 copies of the circuit for 2 channels, 4 for 4 channels, etc.

OddBot's picture
It seems that the transistors only improved things because of the phototransistors I was using. The current "Compound Eye" is the best design. These were early prototypes.
BruuD's picture

That makes sense.
Thanks! 

FrankNeon's picture

Hi there,

I've been reading through this thread and am currently working through a thru hole version of this great sensor board, but I am having trouble seeing what resistor values are used on the printed surface mount pictures.  From what I can tell, a 1K, 100ohm, 47ohm are used.  From your schematics I can see that a 1M and 2K might be the two other values?

Thanks, I love this site and should have a robot to present soon enough!

 

OddBot's picture
This is my early work leading up to the compound eye. Many people had trouble re-creating this possibly due to using different phototransistors. We now sell the eye as a kit for $5 USD.

I've noticed you're quite the expert on IR rangefinders, I have a few questions. I've decided to create a robot for my senior project, it's a design is based off of the xkcd comic, "new pet" as seen here: http://imgs.xkcd.com/comics/new_pet.png
I'm making a few changes to the original design (laptop replaced with microcontroller, webcam replaced with rangefinder, and a few more). Now, I've reached a problem that involves the rangefinder. The magnets might affect the servos (i'm not sure, i've never tried it out), and if they do I won't be able to mount it on top of the ball without possible malfunctioning. So I plan to mount the rangefinders (I'll mount two inside for more accuracy) inside of the glass/plastic ball. This will be more aesthetic as well as less hazardous.

My main question is, are the rangefinders going to be affected by the glass/plastic?

If they are, they would detect the ball and imagine it to be very far away from what I've read on the acroname website. If this occurs then the rangefinder would follow the ball indefinitely, right? Would it detect other objects if it detects the ball? If so, I believe it would follow those since it would detect them to be closer, is this true?

Admin_edit(rik): I made that xkdc link clickable. All links to xkdc should be clickable!

OddBot's picture
Ir reflects off of some transparent surfaces but I have not attempted anything like you describe. I'm afaraid you will have to experiment for yourself. I know my IR sensors detects glass.
I was asking cause I thought that a strong magnet would affect the performance of a servo, but i've been told otherwise. Now, one question remains, would a strong magnet affect the performance of an IR rangefinder?
jklug80's picture
Only if the magnet was strong enough to pull the pins on the IR LED together. Light isn't magnetic ;)
OddBot's picture

:D

 

OddBot's picture

it is all a matter of experimentation. Start with a ball hanging on a thread and see if it will detect it. If it does not then sensitivity can be increased by adding more LEDs, increasing the amplification or adding more sensors. The problem with increasing amplification is that it increases noise so I would try for a stronger signal by adding more LEDs and sensors if necessary.

I have built a test sensor now.

And connected it to pa0 on my atmega1280 to detect logical 1/0

But the led on my board connected to PB7 will not turn off when i put the sensor in darkness. my multimeter shows 3.5-4.1V when it is dark. What is wrong? my atmega1280 or something else?

DDRA = 0;
DDRB |=(1<<DDB7);
uint8_t temp;
   
PORTB=255;
for(;;)
{
        temp=PORTA;
        if(temp>0)
        {
            PORTB=0;
        }
        if(temp ==0)
        {
        //    PORTB=255;
        }
       
}

I Have now modified it so that it works with ADC removed all the resistors exept the 10k pullup resistor. now it works with the ADC

but it does still not pull te digital io to 0 when it detects something.

This is strange

OddBot's picture
This is an analog sensor and it's output will depend on ambiant IR. The circuits I've shown are only a guide line and may need different resistor values depending on the sensor you use. Your software must look for a sudden change in the output, not absolute values.

I'm trying to build a paintball chronograph. that will detect paintballs and calculating their feet per second.
Placing the reciver and dedector to create a break beam would this be fast enough to trip the IO line on a microcontroller?

A paintball is .689inch (the time a paintball would take to travel past the sensor is .689/12/300=190µs) the sircuit would have to trip the io to a 0 or a 1 in max 50µs to be in a safe range(it's a ball so it would not fully break the beam all the time it travels past it.).

I'm planing on using the S2829 phototransistor
https://www1.elfa.se/data1/wwwroot/webroot/Z_DATA/07522337.pdf

and a standard 3mm ir led

would this work or should I use some other transistor/modification?

OddBot's picture
The sensor you are thinking of using has a total rise/fall time of 5uS so it will be fast enough. your problem will be getting the paintball to pass within range of the sensor.

i'm going to place it in a 2.5cm diameter pvc pipe.

a 5mw led would be stong enough for that distance i hope.

OddBot's picture
You can always increase the sensitivity by wiring 2 sensors in parallel if necessary. More light also helps so depending on the component prices it may be cheaper to have more LEDs. Remember that your IR sensor is most sensitive to IR at 850nm so make sure you use 850nm IR LEDs.

those where out of stock so i got an other one.
https://www1.elfa.se/data1/wwwroot/webroot/Z_DATA/07522451.pdfit's 15µs but that should work.

I also got BC517 Darl-transistor NPN 30V 1A TO92 with hfe 30000 Is that to much or should I use that transistor instead of the BC549C in the schematic?

 

emuller's picture

Firstly, since this was developed by oddbot, who is australian, this system only works in m/s, or even km/hr. It won't work in ft/sec.

Off-the shelf phototransistors have a response time of about 10us, the Pt you have there have a rise time of 2-3 us.  which is a lot smaller than the ~100us passage of the pellet, so it should be ok right?. I'd think thatthe standard PTs would be fine too.

 - this is assuming that the pellet diametre is a significant fraction of the size of the beam.

You can always gang up some LEDS to get more light output, and use opamps or darlington trannies to increase sensitivity?


 

 

the paintball is 1.5cm in diameter.
im from sweden so we use mm and kg here.
converting between mesurements is no worries. (it's just that you are supposed to measure in FPS when it comes to paintball so i'l just place 2 of these sensor with a spacing off 3*2.54cm (that is 0.25inch wich would be asy to calculate the time between breaking the two beams to the velocity of the ball))

but as long as this circuit will be fast enough to trip the digital inout to my atmega it will do just fine.

I want it to be logic 0 when there is no ball breaking the beam and 1 when it breaks the beam.
Have I understood correctly when I beleve that is what this sircuit does? gives you less voltage for the ADC when an object reflects more light? If that is the case i'm going to buy the parts tomorrow. And build my chrono :)

emuller's picture
I was kidding about it not working in ft/sec.....
but still i gave you the reply that it does not mater :)
possible to do this with my sensor and a bs2? (tracking) http://letsmakerobots.com/node/8136
anyway to do this with my sensor and a bs2??? (tracking) http://letsmakerobots.com/node/8136
OddBot's picture

I am lost as to precisely what you are trying to do. What are you trying to detect, how far away are you trying to detect it. What sensor are you using? Have you got a link to the data sheet?

Vague questions get vague answers. 

hii;

I'm using BPW41 IR Detector(Photo diode) with the simplified schematic with MPS13 and collector R=560 ohm only.....

 But the distance are so so so small it's only 15 cm .....I tested it again and again and when i remove the transistor and connect only the Photo diode directly it gives me a distance of about 10 cm .....

 I amazing about the range ,i need about 50 to 100 cm at least ..............Any advice to increase the distance ...

PLZ Help..........

OddBot's picture

I am surprised that you are not getting more range. Here are some things to try:

Are you sure you have the transistor connected correctly? If you have swapped the collector and emmiter then the circuit can still work but not very well.

Reduce your resistor value on the collector. I had the pot there for a reason. In my circuit I got peak range when this resistance was about 270 ohms but this can vary depending on the transistor.

Increase power to your IR LED and make sure that it is a 940nm LED since that is the range of peak sensitivity for the BPW41.  Most IR LEDs can handle 50mA continuously, check your datasheet. What is the viewing angle of your LED? A wide viewing angle will disperse the light over a larger area and decrease the intensisty of the light.

Increase the number of LEDs, more LEDs will increase the range.
Connect two or more photodiodes in parallel to increase the circuits sensitivity to light.

My circuit could detect my hand from over a meter away at night. Daylight contains a lot of IR and will swamp the readings. Your lights in the house also generate IR and can reduce the range.

 

iCon's picture
I was going through the parts list and i had no luck finding half the parts there. For one they dont sell the little "R" resistors. I did pick up two radioshack NPN general purpose transistors, RS parts# 276-2016. Is there a site where i could order all of the resistors? Im trying to get the exact values as shown in the first schematic. i know little about electronics.
rik's picture

The R indicates the Ω for "Ohm". So 82R means 82 Ohm. That is a low value indeed. But not too uncommon.

We do not recognize Radio Shack partnumbers. They are only relevant to that shop. What does it read on the part itself? Something like BC123 or 2N1234? Never mind those either. "General purpose" will do, unless the description tells you otherwise.

iCon's picture
Ah i realized that after googling and looking at a comparison chart, mine say 2N3904 for general purpose saturated switching and amplification. I still think ill have to order the 150R but ill check other places for the 1k and 1m resistors. Thanks rik.
voodoobot's picture
try to buy the transistors in packs as it's cheaper. the 2n3904(npn) is a great general purpose transistor, it's compliment is the 3906(pnp). I've used these in most of my projects where a gp transistor is needed. The mps2222a also works and  is usually sold at good ole RS. RS also started stocking low(22,33,47,100, and maybe 82?) value resistors at most of their stores, you should be able to grab em there.
iCon's picture
Thanks for the advice, both odd and voodoo. The photo transistor im using came in a package with an IR LED (from radioshack). As for the transistors, ill be sure to order them next time i place an order online.
OddBot's picture

I have often had people say to me that they can't get the exact parts. It shouldn't matter too much. The 82 ohm resistor is a standard value chosen to get close to 50mA flowing through the LED. You need to check your IR LED datasheet to determine what it's forward voltage is and how much current it can handle continuously to claculate your own resistor value.

The phototransistor could be any that you can find as long as it come in the same package as a 5mm round LED.

Depending on what parts you end up with, some experimentation will be required. the resistor values show are what I used and a good starting point. Breadboard your circuit first until you have it working how you want.

emuller's picture

Okay, so I currently have two IR "eyes" on my faux-robot. I'm using a circuit similar to that posted by oddbot (i.e. read "identical").

I'm not using them to track an object as such, but just as obstical avoidance - as a poor-mans ping.

Something I'm currently wrestling with is the necessity for the "eyes" to be PERFECTLY perpendicular to the reflecting surface - it seems as though the signal MUST come through exactly the front. I have only partly shielded the phototransistors, so they are not affected by the transmitter.... 

At present, I am only using one IR LED transmitter, and one IR photodiode. I will boost this to two of each, and see if this makes any difference. In the mean time, are there any other suggestions as to how to improve the apparently limited field of view?

 

OddBot's picture
I did not use a shield, just had the LED slightly forward. The other problem is the lenses of your LED and phototransistor. Different part numbers have a different angle of sensitivity.
emuller's picture

This thread has been an invaluable read - but I'd like to see what people think of my problems -

I'm trying to make just a wandering robot that won't run into walls, etc. Aside from geometric problems arising from the detectors being far apart, and the robot wandering into narrow chair legs. I'm not happy with the results.

 As for oddbot's system, I'm using an 18X picaxe to pulse a pair of LEDs, however mine are just bright white LEDs. During the on pulse (about 10 ms) the LDRs are read from the a ADC pins, then the LEDs are turned off, and the LDRs read again. The values are differenced and any positive excess indicates an obstacle.

Now, this won't work very well. It's temperamental, inconsistent (except that it ALWAYS runs into the fridge, but ALWAYS avoids the wall...).

So - what is wrong with using the LDRs? is there some quirk of something somewhere that I'm not taking into account? how might I improve the gain of the LDRs?

 I was considering switching to IR LEDs and using the same IR detectors as used by mintvelt, but I really don't know how to configure it all to my 18X picaxe.

Anyhow, thanks for your posts, and thread. It's very helpful stuff.

OddBot's picture

10ms is far too short a period of time for LDR's. Try 100ms before reading the LDR and then turn off the LED.

The Tracking system is really a line follower except it follows IR reflecting off of a close object, turning to balance left/right inputs and up/down inputs.

It can easily be implemented with visible spectrum LEDs and LDRs. Remember though that LDRs are very slow to respond compared to photo diodes and phototransistors. Allow plenty of time for the LDR's to adjust

The type/colour of light used depends on what you want to track.. IR is supposed to work reguardless of the colour of an object although white definitely reflects better than black.

emuller's picture

Thanks for the heads-up, I'll try 100ms.

 

Great to get advice from a fellow aussie!

 

OddBot's picture
If your fridge has a shiny finish then it may be working like a mirror in which case your robot would have to be coming directly at it to pick up the refection. Try 3 LDR's wired in parallel. One facing directly ahead. The others facing slightly left and right.
emuller's picture

Yeah, I have three, but in series - I wasnt sure it would make such a difference series/paralell?

In any case, having them in series isn't too useful - maybe I should try putting them in parallell.

 

Grr. Last night I managed to wipe my picaxe 18X.....!!!!!

 

TotoroYamada's picture

Maybe for white objects like your fridge you could try with a second LED but with a color (like bright blue)? Either both at the same time, or one after the other?

(that's just a guess, maybe it won't work at all!)

BiohazardRoboIndustries's picture
I grew up with LEGO too, mainly Technic and electric... But I'm still new to robotics. The emitters are turned on during the reading of the left and the right photodiodes or them are drived by a pulse?
OddBot's picture

Ok, I think your a bit confused by a circuit I drew to help someone with photodiodes. Google "photodiode" for an indepth explanation but basically they need to be reverse bias to work. (put in back the front).

A phototransistor is basically a photodiode and a transistor combined. The advantage is that the transistor amplifies the output of the photodiode. Once again Google is your friend. The subject is too complicated for me to explain here.

When I first put the LEDs and phototransistors side by side, I did experiment with heatshrink around the IR LEDs and phototransistors but found it was unnecessary. The design of both the LEDs and the phototransistors ensure that IR does not go sideways from the LED to the phototransistor.

 

It is important that you read and understand the datasheets for the components you are using. If unsure, plug some components in a breadboard and experiment first as I did.

 

Chris the Carpenter's picture

Hey Oddbot,

Did you ever get around to trying your set-up with an opamp? I just grabbed a LM324 out of curiosity and to play with. Just wondering if you have done any tests or have come up with any circuits? I did a little data sheet reading and there is about 400 different circuits you can build with this thing, many of which seem would work for this -do any stick out at you as working better than others? 

OddBot's picture
Cwignell has given you the answer in your forum.
OddBot's picture
Yes you can use an op-amp. No fancy circuitry needed. I'll post a circuit this afternoon when I get back from work. I just used the transistors because they were cheaper.
merser's picture

So much to read here. Firstly I am amazed at your laser finder. That is no mean feat to build one.

In regards to Ir detectors. I am wondering at your choice of phototransistor. Have you used the device mintvelt pictures in one of his posts.

The 3 terminal device in black casing with bubble lens(don't know correct name sorry)

Was it price that decided what you used? They are a little rich at $6-50 from jaycar or dick smiths.

That's all I've experimented with so far but it's been "fun" working out the intracacies of using them.

I can't say the range is that good with them, up to about 40cm. Maybe I'm doing something wrong.

Not that I need anymore range than that.