Complex projects inevitably throw up obstacles in the form of bugs. As these arise, you can congratulate yourself for choosing such a challenging project and bear in mind the satisfaction you will feel when all the problems have been overcome. Here is some software that should help you find and fix problems you may encounter.
Visualizing data from the sensors in real time can be tremendous help in understanding what is actually happening in your sketch. Figure C-1 shows the screen from a Processing sketch that enables you to easily view Arduino values.
Figure C-1. Arduino Data Displayed in Processing
Figure C-1 depicts the analogRead values from left, center and right and sensors used in line detection. The grey numbers in parentheses on the right indicate the possible range of values, the following number is the numeric value sent from Arduino.
The figure shows the values when the robot is straying slightly to the right of a dark line it is trying to follow (the values increase when the sensor is over the line). The Position value goes positive when straying right and negative when left. The Position value is used in the line following sketch to adjust the robot direction so it stays on the line. The Distance value is in inches and is obtained from the ping distance sensor.