# Line Following 101 ProPreview

When you hear the task "program the robot to follow a black line", most probably you will imagine a program operating as follows:

• if the color sensor reads black (hence the robot is over the line), the robot goes forward;
• if the color sensor reads some other color (hence the robot is not over the line), the robot turns towards it.

### To access the full video please subscribe to FLLCasts.com

• #852
• 30 Mar 2018

This program seems logical and will probably work. However, the second task is quite hard, if not impossible. The part where the sensor reads black and goes forward is easy:

However, the part where the sensor is outside of the line is impossible. Let us say that the robot is on the right side of the line:

Then it has to turn left to return to the line. Now, if the sensor is on the left side of the line:

It has to turn right to return to the line. That is great but the values the sensor reads on both sides of the line are close if not the same. Hence the robot will not know if it has to turn left or right.

That is why, when we say that we program the robot to follow a line, we usually lie. The truth is that the robot is not following the line but one of its edges.

The edge is an imaginary line which separates the line from the other part of the field (the red dotted lines on the image above). So the line has two edges - one on its left side and one on its right side.

When we are following the edge of the line, the robot, which uses only one color sensor, knows if it is on the left or on the right side of the edge it follows. For clarity, let us assume that the robot is following the right edge of the line. So, if the sensor reads black, this means the robot is on the left side of the edge and should turn right:

If the sensor reads white, it is on the right side of the edge and should turn left:

Having said that, the program for following a black line should look like this - if the sensor reads black, it turns right, otherwise it turns left. Of course, this check is repeated in a loop. Go through the next few exercises and then try and see if the robot follows the line successfully.

## Courses and lessons with this Tutorial

This Tutorial is used in the following courses and lessons

• 136
• 280:11
• 156
• 7
• 0
• 7
• 3d_rotation 1
• 56
• 12:47
• 135
• 2
• 4
• 5
• 3d_rotation 1
• 136
• 280:11
• 156
• 7
• 0
• 8
• 3d_rotation 1
• 37
• 6:37
• 111
• 3
• 0
• 6
• 3d_rotation 0
• 37
• 6:37
• 111
• 5
• 3
• 9
• 3d_rotation 1
• 4
• 0:33
• 27
• 3
• 0
• 2
• 3d_rotation 0