So far we have looked at an algorithm for line following that we will refer to as duck walking. Let us take a look at it and think about how many states it has.

To access the full video please subscribe to FLLCasts.com
- #885
- 30 Mar 2018
The line following program implementing the duck walking algorithm looks as follows:
and consists of two states:
- If the color read is black - the robot turns to one side;
- If the color read is white - the robot turns to the other side.
As you may imagine this is not very effective. The robot is constantly turning left or right and never going forward, even if the line is straight. This makes the algorithm slow and ineffective. Again, for the purposes of this example, we imagine that the robot is following the right edge of the line.
So, let us think about how we could add a state where the robot goes straight forward. The idea is to have three states:
- turning left - when the robot is outside of the line:
- turning right - when the robot is over the line:
- going forward - when the robot is over the edge:
To achieve that, however, we cannot use the color mode of the color sensor, but instead, we need to use the reflected light mode. Let us say that we have measured the values the sensor reads on black, white and on the edge of the line and the values are as follows:
- over the line -> 9
- over the edge -> 32
- outside of the line -> 55
The robot going straight forward only when the sensor reads 32 is pointless. That is why we will program the robot to go forward when the value read by the sensor is close to 32. Let us choose the acceptable error to be +/-5. So, when the value is between 27 and 37, the robot will go straight.
When the value is less than 27, the robot will turn right and when the value is greater than 37, it will turn left. So, having these thresholds, we can develop the following algorithm:
- If the sensor reads a value less than 27, the robot is over the black line and needs to turn right;
- If the sensor reads a value greater than 27, the robot is either over the edge or over white. To determine that, we need to make another evaluation by comparing the value to 37. If the value read is greater than 27 and less than 37, then the robot is over the edge and goes forward;
- If the sensor reads a value greater than 37, the robot is over the white zone, so it needs to turn left;
Measure the values your robot reads over the three zones and try to implement the above algorithm. Try to split the task into simpler, smaller tasks.
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons

Instructors Remote Training
If you are working with students and you want to introduce Robotics to your class or you want to mentor a FLL team, but you are insecure about your technical knowledge in the Robotics field, then this is the right place for you. Having in mind teachers' busy schedule, we have design two different schedules and added an option to design one just for you. FLLCasts's Mindstorms EV3 Robotics Online Training is the perfect match for any teacher.
After the completion of each task the participant has to upload his solution for verification.
- 183
- 280:11
- 156

Competition programming
In this episode, we introduce a LEGO Mindstorms EV3 version of competition robot construction. It is a modular construction, with medium motor for additional attachments and two light or colour sensors for orientating on the field.
- 7
- 0
- 8
- 3d_rotation 1

Robotics with LEGO - Level 2.0 - Robots in Factories
The third level of the Robotics with LEGO curriculum for students from fifth to twelfth grades.
Robots in this level use two or three sensors at a time and students create more complex programs for them. The work of the differential and its usage in vehicles with one drive motor is explored. Robots interact with each other and transfer information or material between themselves. Students learn in depth how to create smoother line-following programs. In the end of the workday, robots leave the conveyor belt and relax with a recreational game of volleyball.
- 44
- 15:01
- 129

Additional tasks for the warehouse robots
It appears we have more time to work on improvements
- 2
- 1
- 3
- 3d_rotation 0

Level C1. "Transportation". Robotics with LEGO
This is the fifth level in the Robotics with LEGO curriculum for students in third or fourth grade.
For the first time robots with steering wheels are built in this level. Those robots use one or two drive motors. The work of the differential and its usage in vehicles is explored. Students learn in-depth the working of the light sensor to create better line-following programs. The first two-wheeled motorcycle-robot is built.
- 33
- 1:03
- 110

Lesson 5 - Boat for line following with 3 states
Remember to provide feedback to students regularly. It's important to give structured feedback in the form of a grade. Today, you'll need to grade your students following this article.
- 5
- 3
- 8
- 3d_rotation 1

Robotics with LEGO - Level 2.0 - Robots in Factories
The third level of the Robotics with LEGO curriculum for students from fifth to twelfth grades.
Robots in this level use two or three sensors at a time and students create more complex programs for them. The work of the differential and its usage in vehicles with one drive motor is explored. Robots interact with each other and transfer information or material between themselves. Students learn in depth how to create smoother line-following programs. In the end of the workday, robots leave the conveyor belt and relax with a recreational game of volleyball.
- 44
- 15:01
- 129

Lesson 5 - Robo Car
Remember to provide feedback to students regularly. It's important to give structured feedback in the form of a grade. Today, you'll need to grade your students following this article.
- 6
- 4
- 11
- 3d_rotation 1

Stay @ Home SPIKE Prime Course
An introduction to the SPIKE Prime set! In this course you will have access to 7 3D instructions for SPIKE Prime robots, exploring the possibilities of the base set. After you build them, you can give them life using our cool programs that do various things, from just moving the robot forward, to finding the closest object to it.
After that, if you are up to the challenge, we have prepared some hard additional tasks. They aim to make you research solutions for modifications to the program and the robot. Of course, you can always make your own additions to the robots and have fun with it!
- 4
- 0:33
- 27