[RL55] Grade 5 - Session 5

Session 5: Detecting and Avoiding Obstacles

Session Architect: Muhammad Bilal
Duration: 50-60 minutes


Equipment Required:

  • M3D Robotics kit (including distance sensor attachment)
  • Laptops with Scratch pre-installed
  • Classroom objects to act as obstacles (blocks, cones, etc.)
  • Paper and pencils for students to document their discoveries and ideas

Learning Objectives:

  • Reinforce the concept of conditionals (if-then) from previous sessions.
  • Introduce sensor data as input for controlling the robot’s behavior.
  • Learn how to integrate the distance sensor and program the robot to stop or avoid obstacles based on sensor readings.
  • Apply variables and loops to continuously check for obstacles while the robot moves.

Resources:

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


1. Introduction to Sensors and Obstacle Avoidance (10 minutes)

Activity:
Start by discussing the concept of detecting and avoiding obstacles, linking this back to the real world.

Instructions:

  1. Physical Activity:
    Begin with an interactive activity. Choose a few students and place some objects as obstacles in their path. Ask the students to walk forward and stop before touching the obstacles. Engage them by asking questions such as:

“How did you know when to stop before hitting the obstacle? Did you have to keep checking how close you were to it?”

Build on their answers by explaining that just like we use our eyes and judgment to stop before bumping into something, robots use sensors like the distance sensor to detect obstacles.

  1. Connecting to the Robot:
    Transition to how robots use their “senses” to detect objects and avoid collisions:

“Our robots don’t have eyes like we do, but they have something called a distance sensor that helps them ‘see’ obstacles in front of them. Let’s learn how we can use this sensor to make sure our robot avoids obstacles, just like how you avoided the objects during our activity.”

Ask them examples of things where they think sensors are used in their daily life.

2. Programming Obstacle Detection (15 minutes)

Activity:
Students will now learn how to use the Distance Sensor to detect obstacles and program the robot to respond when an obstacle is nearby.

Instructions:

  1. Introduce the Distance Sensor Block:
    Show students how to connect the distance sensor. You may hold it in your hand and ask students to find it from the M3D Go Kit box.
    Once connected, show them how they can see the sensor value with the help of a custom M3D Block called “Range Finder Value” that shows how far an obstacle is:

image

You can ask:

Instruct students how they can see the value of the ranger finder by clicking on the checkbox next to it.

  • Encourage them to try putting different objects in front of the sensor and see how the value changes:

“What do you think will happen if we set a condition that tells the robot to stop when an obstacle is less than 10 cm away?”

  • Instruct them to note down the readings in different conditions e.g. when the sensor is blocked by an obstacle and when it is not.
  1. Coding the Condition:
    Guide students to use the “If-Then” block to create a condition where the robot stops when the distance sensor detects an obstacle within a certain range:

“If the sensor detects an obstacle closer than 10 cm, then stop. Otherwise, keep moving forward.”

Help them create a simple code that looks like this:


3. Continuous Checking with Loops (10 minutes)

Activity:
Introduce the concept of continuous checking for obstacles, reinforcing the use of loops.

Instructions:

  1. Adding a Loop:

Remind students how they detect an obstacle in the activity they performed a the start of this session. They kept checking again and again if there is something in front of them. If they check that there is nothing in front of them and start walking with their eyes closed, they will surely bump into something.

You may ask a student to try this by using an obstacle that won’t be dangerous to dump into.

You can then lead the discussion as:

See how we need to check again and again? The robot needs to do this as well. We have learnt this concept in previous sessions, how we can make the robot do something repeatedly.

Lead the discussion toward loops and remind them of “Forever” loop.

  1. Updating the Code:

Once they do, ask them to drag it out of the blocks and use it in their code. Help them in modifying their code to include a loop for continuous checking:


4. Testing and Experimentation (15 minutes)

Activity:
Students will test their obstacle-avoidance program using real obstacles and adjust their code based on the sensor readings.

Instructions:

  1. Set Up Obstacles:
    Place various objects around the room as obstacles for students to test their robot’s program.

  2. Run the Code:
    Have students run their code and observe how the robot reacts to the obstacles. Encourage them to adjust the distance threshold or make tweaks to improve the robot’s reaction time.

“How did your robot do? Did it stop in time or did it hit the obstacle? Try adjusting the code and see if you can make it more accurate!”


5. Integrating Express and Show Text Blocks (10 minutes)

Activity:
To make the robot more interactive, students will use the “Show Text” block and “Express” block to display messages or emotions when the robot detects or avoids obstacles.

Instructions:

  1. Add Messages:
    Encourage students to program the robot to display text when it encounters an obstacle. For example, it could say:

    • “Obstacle ahead!” when an object is detected.
    • “Moving safely” when no obstacles are nearby.
  2. Add Emotions:
    Students can also make the robot display emotions using the “Express” block when it encounters obstacles. For example, the robot can show a surprised face when an obstacle is detected.

“Let’s give the robot some personality! Make it say something or show an emotion when it detects an obstacle. You could make it show a surprised face or say ‘Watch out!’ when it stops.”

To incorporate both text and emotions, they can use the “Wait_seconds” block to make the robot show a text, wait a few seconds and then display some emoji according to the action.


Teacher’s Role:

  • Guide students through the coding process, offering help when they encounter difficulties.
  • Encourage students to experiment with different sensor ranges and text/emotion displays.
  • Ask questions to help them understand how the sensor data controls the robot’s actions, reinforcing previous lessons on conditionals and loops.

Learning Outcome:

By the end of the session, students will have learned how to integrate the distance sensor with conditional coding. They will program the robot to avoid obstacles based on real-time sensor data, applying loops to continuously check for objects and adding personality with text and emotion displays. This session reinforces conditionals and introduces the concept of sensor-based inputs to control robot behavior.