This chapter describes how to use a distance sensor to enable the robot to see and avoid
obstacles as it moves around. The first sketch, named
the robot forward, and if it detects an obstacle, it stops and rotates the robot to try and
find a clear path to move forward. Another sketch, named
a servo that can rotate the sensor so the robot can look left and right without having to
twist itself around.
Connect the Ping sensor and servo the right way around; the black wires (ground) go nearest the pin marked -, the white (or lighter color) signal wire goes nearest the pin marked S (Figure 10-1).
Figure 10-1. Ping sensor and servo plug into pins on the motor shield
Uses a SONAR distance sensor (the Ping sensor) to enable the robot to see and avoid
obstacles as it wanders around.
#defines are added for front and rear
obstacles (only the front is implemented in the sketch), the look module has added
support for distance sensing. This sketch introduces a new tab, named Distance, which
contains the Ping sensor code that you originally saw in Sonar ...