As long as robots have been made ,and as long as obstacle detection has been used, there has existed a dilemna for which sensor to use for ranging and noncontact obstacle avoidance. In this brief tutorial I will explain to you the pros and cons of each sensor.
I . Infrared Sensors
The two types of IR sensors. There are IR sensors with built in circuits which provide a binary output , and there are those which provide an analog output or a multiple bit output.
The sensors with a binary output are only good for detecting the proximity of an obstacle , and not the range. By that I mean that the sensor can only tell you when an obstacle is within a certain distance ( we will call it the threshold distance) . This is fine for most robots which only need to know when an obstacle is right in front of it . This is the cheapest sensor which I will be explaining here.
The other IR sensors, which are ranging sensors , output the actual distance of an obstacle from the sensor. This output can either be analog or a digital byte.
Building an IR sensor , whether ranging or binary , is incredibly simple . Admin talks about how to build your own IR sensor here . Those sensors can be made cheaply but they are not so accurate . If you want accuracy get these Sharp IR sensors. They are the kings of infrared ranging , they are the most accurate IR sensors, and they provide an easy to use analog output. They usually cost between $10-$20 . However, be aware that there are many different types of Sharp IR sensor which have different minimum and maximum ranges , so search around for the one that suits you.
Now that I have explained the different types of IR sensors , I will tell you why IR is NOT the best out there. Infrared sensors , emit infrared light ,and therefore the sensors cannot work accurately outside or even inside , if there is direct or indirect sunlight( but this is not entirely true for Sharp IR sensors , since they will work pretty accurately in ambient light.) So no infrared ranging sensors on your outdoor robot. Also, the way the infrared sensor works is as follows
"The Sharp IR Range Finder works by the process of triangulation.
A pulse of light (wavelength range of 850nm +/-70nm)
is emitted and then reflected back (or not reflected at all).
When the light returns it comes back at an angle that is dependent on
the distance of the reflecting object. Triangulation works by detecting
this reflected beam angle - by knowing the angle, distance can
then be determined.
Now since light does not reflect the same way off every surface, the infrared sensor reading will be different for different surfaces , different colors, and different shades EVEN if the range is the same. Most of the time this reading is not too off, so the robot can still function.
CONCLUSION FOR IR SENSORS: Use infrared ranging sensors if:
II. Ultrasonic Sensors
If you would like a background on ultrasonic sensors read Admin's tutorial here
Ultrasonic sensors use sound instead of light for ranging , so ultrasonic sensors ( some people call it sonar) can be used outside in bright sunlight. These sensors are amazingly accurate ,though they may be thrown off by a sound absorbing obstacle , like a sponge. The only real issue that arises is the "ghost echo" issue. As you can see below , the walls bounce off in a strange pattern causing a ghost effect. Also, the sensor does not come with a connecting wire sometimes , only the connector part ,so buy a cable like this
CONCLUSION FOR ULTRASONIC SENSORS:Use ultrasonic sensors if:
1. You need accurate distances of obstacles, no matter what color they are
2. The robot will not encounter sound absorbing materials as obstacles
3. You will be using the ultrasonic sensor inside or outside
4. You are willing to pay over $25 for each ranging sensor
III. MY PERSONAL RECCOMENDATIONS FOR SENSORS:
After reading this tutorial and assesing whether to get IR sensors of ultrasonic sensors , you are faced with a lot of choices for each type of sensor.
For ultrasonic ranging( the best type of ranging) , I prefer the Parallax PING ultrasonic sensor , since it can detect obstacles that are 2cm away and obstacles that are up to 1 m away. Also, it uses only one I/O pin on the microcontroller since you can trigger the sonar and take a reading on the same pin. Read more about the PING sensor here . It usually costs between $20 - $30, so look around for good prices.
For infrared ranging I like to use the Sharp GP2D120 infrared sensor. Read more about it here . It has a range of 4 - 30 cm . The cost is usually between $10 - $20 , so browse around .Also, the sensor does not come with a connecting wire, only the connector ,so buy this
FINAL STATEMENT :
Infrared is cheap( $10 -$20), small beam, not good measuring distance to dark objects.
Ultrasonic is expensive( $20+ ) and more accurate , not good with absorbent objects ( like sponges) , and wide beam.
Hope this tutorial cleared up some stuff for you!