Choosing between optical and ultrasonic sensors
Before we start to use distance sensors, let's find out what these sensors actually are, how they work, and some of the different types available.
The most common ways in which to sense distance are to use ultrasound or light. The principle of both of these mechanisms is to fire off a pulse and then sense its reflected return, using either its timing or angle to measure a distance, as can be seen in the following diagram:
We focus on the sensors that measure the response time, otherwise known as the time of flight. Figure 8.1 shows how these sensors use reflection time.
With this basic understanding of how sensors work, we'll now take a closer look at optical sensors and ultrasonic sensors.
Optical sensors
Light-based sensors, like the one in Figure 8.2, use infrared laser light that we cannot see. These devices can be tiny; however...