Line following is a very common competition category. Here's how you can get started with it!

To access the full video please subscribe to FLLCasts.com
- #2316
- 31 Jul 2024
- LEGO Education SPIKE Prime
- Line follow, Line following, LEGO Education SPIKE App Word Blocks, Scratch
snimka
Line following may seem simple at first glance. You think you just have to program the robot to go forward when it's on the line and to turn towards the line when it's not on the line. The problem is that the second part is impossible to program as you can't know which side of the line the robot is. Should it turn left towards the line? Should it turn right?
That's why most line-following algorithms follow the edge of the line instead of the entire line. By following the left edge, for example, the robot always knows it can turn right towards the line.
snimka
The basic algorithm looks something like this:
- If the robot is on the black line, turn towards the edge.
- If the robot is outside of the line, turn towards the line.
So, if we choose to follow the right edge, the robot should turn right until it detects white and then turn left until it detects black. When placed in a forever loop, the robot should successfully follow the black line! This algorithm can be implemented with both wait until blocks and if/then blocks.
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons

Level B2 - Introduction to Robotics Competitions - Robotics with LEGO SPIKE Prime
This is the fourth level of the LEGO Robotics Curriculum for students in second, third, or fourth grades.
Competitive Introduction Level: Each lesson has a theme related to various LEGO robotics competitions. Students learn about FIRST LEGO League, Line Following, and Sumo Wrestling. A new color sensor is introduced, and students use forever loops, wait until commands, and if/else statements in new ways.
- 21
- 1:03
- 60

Lesson 5 - Line Following Part 1
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.
- 4
- 4
- 8
- 3d_rotation 2