Attaching and reading an ultrasonic sensor
First, we should wire in and secure these sensors to the robot. We then write some simple test code that we can use to base our behavior code on in the next section. After completing this section, the robot block diagram should look like Figure 8.7:
This diagram builds on the block diagram in Figure 6.33 from Chapter 6, Building Robot Basics – Wheels, Power, and Wiring by adding left and right ultrasonic sensors. Both have bi-directional arrows to the Raspberry Pi, since, being an active sensor, the Raspberry Pi triggers a sensor measurement and then reads back the result. Let's attach the sensors to the robot chassis.
Securing the sensors to the robot
In the Technical requirements section, I added an HC-SR04 bracket. Although it is possible to make a custom bracket with CAD and other part making skills, it is more sensible to use one...