# IR v. Sonar

I've been making plan for an obstacle-avoiding robot, and was originally planning to use a Sharp IR range finder for it (10 - 80cm), but after seeing other sonar range finders, and other people's projects (the majority of the ones I see seem to use sonar), I was wondering:

Which is better: IR or sonar?

'Cos IR recievers can be affected by ambient IR light, and the best i;ve seen goes up to 150cm, whereas I;ve seen sonar ones up to 7.4m, roundabout, and they can't be affected by ambient sound (I think).

So, which would be better? Is that mainly just determined by budget and distance?

Also, do they work the same, in that a greater distance returns a lower analog value, and a lesser distance returns a greater analog value (or something along those lines)?

## Comment viewing options

The best system will use both IR and Ultrasound together as they both have different strengths and weaknesses.
Both of them have difficulty with objects that are at an angle as both the sound and the light are reflected off to one side rather than directly back at the sensor.

Most of my designs use IR LEDs and phototransistors simply because they are very cheap. Ambient light is easily removed from the equation by taking two readings. One with LEDs on and again with LEDs off. The difference is the amount of IR from the LEDs that reflects back from an object.

IR sensor do not work in bright sunlight because the large amount of IR in sunlight blinds them.

I have yet to hear of anyone taking their robot to a nightclub to see if loud noise deafens them although Frits did have a robot at a party.

Just to get this straight, with your IR LEDs, you take one reading, with LEDs on, and lets say it returns an analog value (after the ADC) of 560. Then you turn the emitter LEDs off, and read the receiver inputs again, and then subtract that value from the first. Doesn't that mean that if there is more sunlight than usual an object will appear closer/further away than it actually is?

Or does that second reading genrally return 0, or a very small number?

And I noticed on the 'faces'  of your bipedal soccer robots they have a ring of black LEDs (IR recievers, I presume), with clear ones in the centre (the emitters, then). Does an array such as this help with detecting objects at a slight angle?

Simple IR sensors such as I use cannot measure distance with any accuracy since the amount of reflected IR depends on the size, colour and shape of the object as well as distance. The Sharp IR sensors use a Cmos sensor array to measure the angle of the reflected light to judge distance.

By taking two readings you can eliminate the ambient light with reasonable accuracy. Excessive ambient IR will reduce the sensitivity or blind the sensor all together.

Using the compound eye with my hand about 5cm (2") in front of it as an example, The reading with the 4 IR LEDs on might be about 750. With the LEDs off I might get a reading of about 280. the reading of 280 would be due to IR from the lights or sunlight coming through a window.

The actual amount of reflected light from the LEDs will give a reading of 750 - 280 = 470. If I then move my hand further away the ambient light reading won't change but the amount of IR reflected from my hand will drop so that at 10cm (4") I might get a reading of 420 with the LEDs on and 280 with the LEDs off for a reflected reading of 140.

The array of phototransistors (look like black LEDs) might help a bit with detecting objects at a slight angle as you are taking measurements over a larger area.

What exactly do you mean by cone shapes? Is that referring to the beam width?

'Cos when I was looking up sonar sensors earilier, and when I looked up IR ones, I cam across charts like this (comparison chart of sonar sensors): http://www.pololu.com/picture/view/0J1969

What do these charts mean? I've never really understood them

And thanks for answers so far

Those are the cones for different models in the first 2 columns. It tells you how wide the detection area is at different distances. The 3rd column is showing you how many false readings you get.

Getting a cheap sensor and hooking it up to an Arduino (or other uC) and having it spit out readings to a serial port will teach you far more about them than i can tell you in a forum. The "ping" sample for Arduino works great with the ultrasound and I found an IR one in a forum post at arduino.cc.

Ok, thanks for that. So for example at distance x, the beam has a width of y, and would reflect back (in theory) from an object in that width.

I will test a couple of sensors with that, I just wanted a bit of advice as I do not actually have a sonar sensor or an analog sensor yet.

For most practical uses, light has a bean width that is fixed for the whole range while ultrasound spreads out as it gets further away, causing a cone shape instead of a beam. I am not sure I have this right, but I think they narrow the ultrasound cone by putting the receptor in a fixture that has to be hit almost dead on to receive. I am testing narrow beam ones with a decent range (HC-SR04) and I am still concerned about avoiding things that aren't in the way but are in the cone.

I will offer some up anyway.

IR seems to be preferred at small distances while the sweet spot for ultrasound is a little further out.

Ultrasound has various cone shapes available (wide versus narrow) and IR pretty much needs to be a beam to be practical in a low power system.

I am sitting here playing with both, just by chance, and the next statement may be more about what I specifically have - ultrasound seems to have more wrong but reasonable readings that IR. What I mean is that they both occasionally give a reading that is wrong, but the IR usually seems to get it right or so far wrong you know to ignore it. the ultrasound will give some wrong readings that are within its normal range. It will not be too hard to filter them out.

Both have a hard time with fabric, but I think IR has an edge. Neither is failing totally on my blue cotton shirt, but I am getting a lot of false readings from both.

I just tested a couple of digital Sharp range finders ( http://www.littlebirdelectronics.com/products/Sharp-GP2Y0D805Z0F-Digital-Distance-Sensor-5cm.html ) and while in the site description it says they will return a logical 0 if an object is from 5cm to 0.5cm away, and if not return a logical 1.

I have noticed a few slight issues these things have:

1. They only work if the object is perfectly parallel to the diode face, and thus perpendicular to the beam

2. With shiny, reflective objects (eg. a CD) they work well (assuming issue 1 is satisfied), returning a 0 if object is in specified range

However, 3. if the object is not that shiny (eg. a book) it will only return a 0 if the object is at exactly  5cm away, and no other distance. Or it just simply won't work at all.

Can I assume analog ones work better than this?