The gyro sensor indicates the angle of the turn the robot made. We certainly can use this to create a robot that could perfectly follow a direction, right? Now we'll show you the easiest way to do it.

To access the full video please subscribe to FLLCasts.com
- #1279
- 08 May 2019
- LEGO MINDSTORMS, LEGO MINDSTORMS EV3
- EV3-G, Classes with students, Programming, EV3, Sensors, Gyro Sensor
This program is exactly the same as following a line with one color sensor. The idea is to move straight, when we're in the right direction (the gyro sensor shows 0 degrees), and to turn, when the gyro is not showing 0 in order to get back to the right direction.
However, this would be complicated. In general the program represents a series of constant turns, also known as "duck walking". The back line from the line following task will be replaced by the imaginary line that we want to follow. The target value will be 0, but we can modify it for the angle needed. The algorithm is as follows:
- If the gyro sensor shows less than 0 degrees, we turn towards 0 degrees - in this case we turn right.
- If the gyro sensor shows more than 0 degrees, we turn towards 0 degrees again. In this case we turn left.
And we're ready! We have a program with which our robot will always follow the same direction, even if we try to push it away from its path.
Like in line following, this program could be done with both switch and wait blocks.
This is the simplest algorithm for following a direction, but it's not the smoothest. Fortunately, line following is exactly the same task as direction following. Therefore, you could check the tutorials for line following with 3 or more states or proportional line following. The logic is exactly the same.
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons

Level D2. "Seafaring". Robotics with LEGO
The eighth level of the Robotics with LEGO curriculum for students in third or fourth grade.
In this level, students learn to use the fourth sensor in the robotics set - the gyro sensor. The robots are modeled after boats, yachts, and ships. With the help of the gyro sensor, students can set a course for their robots to a given angle and can detect deviations from the course. In open seas, there may be sea-monsters and the robots are being programmed to detect a sudden change in acceleration with the help of the said sensor.
- 24
- 2:49
- 107

Lesson 5 - Following a direction
Returning feedback to students is important. We try to return feedback constantly in the classes. You should also try to return feedback in a structured way - in a form of a digit. Today you will have to grade your students following this article.
- 5
- 3
- 8
- 3d_rotation 0

Robotics with LEGO - Level 2.5 - Maritime Journey
The fourth level of the Robotics with LEGO curriculum for students from fifth to twelfth grades.
In this level students focus on the rotational sensor that is part of every motor in the robotics set. Students also learn to use the fourth sensor in the robotics set - the gyro sensor.
First few robot constructions imitate sea-animals and their behavior. Students create programs that check whether the robot's claws or pecks have successfully caught an object. That sensor in the motors allows the robots to go back in their lairs even after the use of unlimited movement. The rest of the robots are modeled after boats, yachts, and ships. With the help of the gyro sensor, students can set a course for their robots to a given angle and can detect deviations from the course. In open seas, there may be sea-monsters and the robots are being programmed to detect a sudden change in acceleration with the help of the said sensor.
- 42
- 3:52
- 133

Lesson 5 - Personal Yacht
Returning feedback to students is important. We try to return feedback constantly in the classes. You should also try to return feedback in a structured way - in a form of a digit. Today you will have to grade your students following this article.
- 7
- 3
- 10
- 3d_rotation 0