Line Avoidance
To make your bot stay in the arena, you must teach it to avoid a black line. Then you can build an arena with big white paper as the floor and black tape as the border.
Connect the Reflection Sensor
Let’s connect the reflection sensor to Arduino. Prepare the cable by cutting the end that doesn’t fit to the sensor. In our case, the small white connector fit to the sensor and we left it in place. The big black connector didn’t fit anywhere, so we cut it away. Strip the free wires for connecting to Arduino (Figure 2-6).

Figure 2-6. Stripped sensor wire
Connect free sensor wires to Arduino as shown in the circuit diagram for helloreflection.pde (Figure 2-7). Connect the red plus wire to +5V, and the black ground wire to GND. Connect the green data wire to D4. (Figure 2-8). Use the ScrewShield to keep the wires in place (Figure 2-9).

Figure 2-7. Circuit diagram for helloreflection.pde

Figure 2-8. Reflection sensor connected

Figure 2-9. Free wires connected to Arduino with ScrewShield
Hello Reflection
For line avoidance, we use a typical reflectivity sensor. We read it with Arduino’s
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access