Adding distance sensors
If your robot is to appear intelligent, gathering information about the world around it will be crucial. So, let's add some sensors that can provide you information about the distance and location of barriers.
There are basically two kinds of distance sensors, IR and sonar sensors. Both send out a signal and then measure a response to calculate the distance of the object from themselves. You can use either sensor, so you'll learn how to add both to your project. Let's cover sonar sensors first.
Sonar sensors
A sonar sensor uses ultrasonic sound to calculate the distance of an object. The sound wave travels out from the sensor, as illustrated here:
The device sends out a sound wave 10 times a second. If an object is in the path of these waves, then the waves reflect off the object, sending waves that return to the sensor, as shown here:
The sensor then measures return of waves, if any. It then uses the time difference between when the sound wave was sent...