Build a Self Driving Car With the GoPiGo3

6. Safety: Add the Distance Sensor

No self driving car would be safe to put on the streets if it ran into things. While we can program it to move around the neighborhood, we also need it to stop for pedestrians and for other cars.

We will use the distance sensor to measure any obstacles in front of our car at each intersection. If the robot sees something within a certain range, we won't go forward; rather, we'll stop, and wait for the object to pass.

We have added a distance sensor read into our code. Now, at each interesection the GoPiGo3 will read what is ahead, and if it is closer than 30 cm (the minimum distance to the next intersection) the self-driving car will wait until the intersection is clear.