Lesson 4: Coding a Line-Following Robot

In this lesson, we will be coding a line-following robot. The goal is to use sensors to guide your robot’s movements and make it follow a path automatically.

Table of contents

  1. Video
  2. Quiz

Video

Quiz

A robot's color sensor is pointed at a black line on a white floor. How does the sensor's input directly help the robot stay on the line? It tells the robot's motor to turn only when it's on the line. It measures the distance to the line to keep the robot centered. It sends a signal that the program uses to decide whether to correct its direction. It tells the robot to move forward at a constant speed. What would happen if you forgot to put your if-then-else block inside a forever loop? The robot would only follow the line for a short time and then stop. The robot would check for the line only one time at the start of the program. The robot would drive in a circle instead of a straight line. The robot's motors would not be able to turn on. A robot's program has an if-then-else statement: if the sensor sees the black line, it moves straight. What is the most likely command in the else block to help the robot follow the line? A command to stop all movement. A command to make the robot turn in the opposite direction from the line. A command to make the robot adjust its steering to the side where the line is. A command to play a sound. Your robot is following a line but keeps turning sharply and going off the path. What is the most likely reason for this behavior? The motors are not connected to the correct ports. The speed of the motors is set too high, causing it to overcorrect. The line is not dark enough for the color sensor to detect. The forever loop is running too fast. What would be the best way to change the code so the robot follows a blue line instead of a black one? Change the set movement speed block. Change the motor ports. Change the color in the sensor is color block to blue. Remove the forever loop.