[RL56] Grade 5 - Session 6

Session 6: Line Follower – Making the Robot Follow the Path


Session Architect: Muhammad Bilal
Duration: 50-60 minutes

Equipment Required:

  • M3D Robotics kit (including M3D Go, its display attachment, and the line-following sensor)
  • Laptops with Scratch pre-installed
  • Black tape and white sheet to draw lines on.
  • Paper and pencils for students to document their discoveries

Learning Objectives:

  • Understand how to use the line-following sensor to detect black lines.
  • Use conditional logic (“if-then” and “if-then-else” blocks) to control the robot’s actions based on sensor input.
  • Program the robot to follow a path and respond to different conditions while moving.
  • Display text on the robot’s screen based on its status (following the line, adjusting, no line detected).

Resources:

Scratch Code for the session:
Grade 5 Session 6.sb3 (3.4 MB)


1. Introduction to Following a Path (5 minutes)

Activity:
Begin with an engaging, interactive activity that helps students understand the concept of following a path. You can involve some students in a game to make the concept more relatable.

Instructions:

  • You may begin by saying:

“Have you ever tried following a path, like walking along a straight line without stepping off? Sometimes it’s easy, but what happens when the path curves or changes direction?”

  • Choose a student or group of students and create a line on the floor using tape or paper. Ask the students to try walking along the line, but they have to turn if they step off or adjust their path if they’re drifting away. This simulates the challenge the robot will face.

  • Explain to the students:

“Just like you adjusted when you stepped off the line, our robot can also adjust when it’s following a path! We can give it instructions using Scratch and the line-following sensor to help it stay on track! We will do this using a special sensor. Let’s see what it looks like”

Teacher’s Role:

  • Guide students through the activity, helping them understand the idea of adjusting their movements based on feedback.
  • Make connections between the activity and how the robot will follow the path using a sensor.

2. Line-Following Sensor: Advanced Decision Making (20 minutes)

Activity:
The teacher will explain how the line-following sensor works and how students can use conditional logic blocks to program the robot’s behavior based on what the sensor detects.

Instructions:

  • Start a discussion on sensors and develop an understanding in them before showing the line sensor.

"How did you walk along that line and try to stay on it?

Wait for their response and build up on it.

You used your eyes to see the line and your brain to decide when to move forward or when to adjust right?. Well, what if I told you that we can give our robot its own ‘eyes’ to help it stay on the line too? Just like how you were using your senses to follow the path, our robot can use sensors to ‘see’ and stay on track! Today, we’re going to give our robot the power to detect the line and follow it just like you did. Let’s see how well our robot can follow the path!"

Ask them examples sensors they may have seen in their daily life to develop a better understanding. Once that is done, you can start introducing the line sensor.

  1. Explain the basics of how the sensor works:

"The robot’s sensor can ‘see’ the black line. It will send information to the robot, and the robot will react based on what it detects. It has two sensors which help it detect if there is a line or not.”

You may have the value of both sensors on display on the projector screen for students to see how the value varies in real time:
{AC483637-6DC6-4258-BAF3-F2783F54C490}

  1. Introduce the conditional logic needed for line following:

    • “If both sensors detect the line, the value changes and the robot moves forward.”
    • “If one sensor detects the line and the other doesn’t, the robot will turn and adjust itself to stay on the line.”
    • “If neither sensor detects the line, the robot will stop.”
  2. Show how they can check two conditions at the same time using the “and” block in Scratch. You can say:

“Since there are two sensors, we need to be able to check two conditions at the same time. It’s just like how we checked a single condition with one additional block called the “And” block:”
{D998D562-E19D-4377-B646-E9AD175D4734}

  • Encourage them to notice how the shape on both ends of the block is the same as the one used for conditions. This tells us that this block is also used to check conditions. You can say:

“This can be used with If-then block and it works just as it looks and sounds. If first condition and second condition both are satisfied, then the robot will perform the action. If they are not, it will not do anything.”

Demonstrate how this code block will make the robot repeat the movement only if both keys are pressed which means both conditions are true.

  • Encourage them to use the and block with different types of conditions. You may give them some problems such as:

  • Compare 2 numbers in both conditions and if the left one is greater than the right one in both conditions, the robot will start spinning left. If the right one in both conditions is greater, the robot will start spinning right.

  • Check if both up and down arrow are pressed. If they are, the robot will show confused face. If one of they keys is pressed, the robot will say “Let’s Go!”

  • Guide them if they are facing any issue coding these logical conditions.

Teacher’s Role:

  • Guide students through setting up the logic and sensor, demonstrating the “and” block in Scratch.
  • Assist them in creating their first code block that makes the robot perform actions based on two conditions simultaneously.
  • Help students understand how the sensor readings control the robot’s movement.

3. Hands-On Coding: Creating a Line Follower (25 minutes)

Activity:
Students will attach the line-following sensor to their robot and program it to follow the line using conditional logic blocks.

Instructions:

  1. Guide the students in attaching line sensor to the robot and display the two values of the line sensor on the screen:
    {1F23B2E5-55FC-43B8-8F54-D454DAAC93DE}
  • Encourage them to place the sensor on the line and then remove it to see how the value changes. Ask them to note down the value the sensor gives if it is on the line so that they can use it for their code.
  1. Walk them through the logic of how to code the robot to follow then line and stay on the line as follows:
  • If both sensor readings are above a certain value (IR Sensor 1 value > Normal value and IR Sensor 2 value > Normal value at the same time) meaning the robot is on the line, the robot should forward.**

[Note that the normal value is what the sensor reads on a white sheet of paper in the absence of any other colors.]

  • If one sensor reading is high and the other is low (IR Sensor 1 value > Normal value and IR Sensor 2 value = Normal value or vice versa), the robot will rotate to stay on the line.

  • If neither sensor detects the line (IR Sensor 1 value = Normal value and IR Sensor 1 value = Normal value), the robot will stop.**

  1. Guide students to code their robot’s movements based on these sensor inputs. Explain how the robot can adjust its path based on what the sensor detects.

  2. Encourage students to test their code on the pre-drawn black line and adjust as needed.

Their final code should look like this:

Teacher’s Role:

  • Guide students through attaching the sensor and writing the code.
  • Help troubleshoot and provide guidance as students test and modify their programs.

4. Enhancing the Robot’s Behavior (5 minutes)

Activity:
Students will add text and expressions to the robot’s screen based on the robot’s status (on the line, adjusting, no line detected).

Instructions:

  • Show students how to add “Show Text” and “Express” blocks to display the robot’s status:

    • If both sensors detect the line, the robot shows “Following Path” on the screen.
    • If only one sensor detects the line, the robot shows “Adjusting.”
    • If neither sensor detects the line, the robot shows “No Line Detected.”
  • Encourage students to experiment with the robot’s expressions and text blocks to make the robot seem more interactive.

Teacher’s Role:

  • Provide guidance as students incorporate text and expressions into their code.
  • Encourage creativity by letting students choose different expressions or messages to display.

5. Reflection and Wrap-Up (5 minutes)

Activity:
Students will reflect on the line-following activity, discussing how the sensor helped the robot stay on track and how they used conditional logic to control the robot.

Reflection Questions:

  • “What was the most fun part of making the robot follow the line?”
  • “How did the sensor help the robot stay on the line?”
  • “How do you think we could improve the robot’s performance?”
  • What was the challenging part in making the robot follow a path?
  • Was your robot able to follow the line successfully? If not, what were the reasons.

Teacher’s Role:

  • Lead the reflection, helping students express what they learned.
  • Encourage students to think about how sensors and coding can be used in real-world applications.

Learning Outcome:

By the end of the session, students will understand how to use the line-following sensor and conditional logic blocks in Scratch to program the robot to follow a path. They will learn how sensor data can be used to make decisions and control robot behavior, and they will gain hands-on experience coding robots to respond to different conditions.