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)?

The major downfall to each is …

IR can have issues w/ colors and some surfaces and sonar can have problems with narrow objects. One book I have read commented that a robot’s senses should degrade gracefully. Given a chance depending on your environment using both types along with touch and possibly even sensing motor stalls would be preferred over 'putting all your eggs in one basket.'

just my $.02

Sonar sensors do have one

Sonar sensors do have one problem that I noticed.  

When you try to measure the the distant to an object that it at an angle, the sound waves do not come back to the sonar, as in the robot reads it as an infinite distance even though the object is only 30cm in front. Other than that I’ve been quite happy with my sonar. A bump switch at the front of the bot will fix this problem. 

Not sure if the Ir ones have this problem.  

Generalizations are always wrong, but…

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.

one more from the last few minutes…

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.

Cone shapes?

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):

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

And thanks for answers so far

For most practical uses,

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.

Forgot to say what the charts mean

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



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.



I just tested a couple of digital Sharp range finders ( ) 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?

Yes. I would look at

Yes. I would look at these:

what I am testing is a knock off of the middle one.

I remembered seeing a hack for the Sharp digital IR sensors

That link isn’t the exact page I remember seeing, but, it will suffice and show you something you may not have known otherwise.


BTW, I hate that they call those “range finders”. I think they are proximity (is something nearby) sensors, as opposed to distance (how far away) sensors. And to pick a nit, there are some digital distance sensors, though I suspect all they are doing is reading the analog signal and transmitting the value on a serial line.