[RL53] Grade 5 - Session 3

Session 3: Introduction to Variables in Coding

Session Architect: Muhammad Bilal
Duration: 50-60 minutes


Equipment Required:

  • M3D Robotics kit.
  • Laptops with Scratch pre-installed.
  • Projector to display Scratch interface for demonstration.
  • Paper and pencils for students to document their discoveries and ideas.

Learning Objectives:

  • Understand the concept of variables in coding and how they can store information.
  • Learn to use pre-existing variables in Scratch (e.g., “answer”, “timer”, “position”).
  • Create custom variables in Scratch to store and change values.
  • Apply variables in real-time to track data (e.g., robot’s distance traveled, time elapsed).
  • Experiment with adjusting variable values to observe changes in robot behavior.

Resources:

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


1. Introduction to Variables and Constants (10 minutes)

Activity:
Students will track how high they can jump, which will change as different students participate.

Instructions:

  1. Set the Stage:
  • Call a student to the front of the class.
  • On the board, write: “Total Height jumped by [Student’s Name]: 0 cm”
  • Explain:

“Right now, [Student’s Name] hasn’t jumped, so their jump height is 0. This is like our rough notes—we can use it to store information that can change, in this case, the height of the jump.”

  1. Demonstrate Changing the Variable:
  • Ask the student to jump as high as they can, and estimate or measure the height (e.g., 20 cm). Write it on the board:
    3.*“Total Height jumped by [Student’s Name]: 20 cm”**
  • Point out:

“Now the answer has changed! It was 0, but now it’s 20 cm because [Student’s Name] jumped.”

  1. Modify the Variable:
  • Ask the student to jump again and write: "Total Height jumped by [Student’s Name]:
  • Do not write the answer yet. Ask the students what the answer should be. When the students tell how it is the sum of the new reading and the previous reading, you may ask them:

"How do you remember the previous value? Our rough notes helped us remember and our new value will be:

  • Write the new answer.
  • What do you notice about the variable? It changes based on each jump!"
  1. Explain the Concept of Variables:
  • Tell the class:

"Just like we tracked different jumps using our rough notes, in Scratch the robot can keep track of changing information using something similar called “variables.”.

Teacher’s Role:

  • Guide the student through jumping and make sure the class follows along with the changes on the board.
  • Emphasize how the height of jump changes based on the actions performed.
  • Encourage the class to think about other examples where variables might be used (e.g., keeping track of scores in a game).
  • Lead them to the idea that variables in Scratch work just like keeping track of jumps height—they change as actions happen.

2. Exploring Pre-Existing Variables in Scratch (10 minutes)

Activity:
You can say:

“Let’s start by looking at some variables that Scratch already has.”

Introduce students to variables that already exist in Scratch, like “answer,” “timer,” “position x/y”.

Instructions:
Demonstrate on the projector how certain blocks in Scratch already store and use variables. For example:

  1. “Ask ___ and wait” stores the response in a variable called “answer.”

Let students experiment with these pre-existing variables:

“Now, let’s ask the robot a question and see how the ‘answer’ variable works.”


Show them how they can check the value stored in the variable by dragging it from the list of blocks and clicking on it.

  1. “Timer” keeps track of how many seconds have passed since the program started.

image


Show them how to use these variables. You may say:

“Look at the timer here—it tells us how long it’s been since we clicked the green flag. That’s a variable that stores the time!”

  1. “Position x” and “position y” tell the horizontal and vertical position of the sprite.

Note that the students don’t confuse the position of the actual robot with the position of the sprite. These code blocks tell us the position of the sprite inside the gamepad.

Teacher’s Role:
Explain each pre-existing variable with simple examples and encourage students to test them out. Help them understand how variables help store important information that changes as the robot moves or as they interact with the code.


3. Creating and Using Custom Variables (15 minutes)

Activity:
Students will learn how to create their own variables in Scratch, store information in them, and adjust values.

Instructions:

  1. Introduce the “Make a Variable” option in Scratch. Show them how to create a new variable:

“Let’s say we want to keep track of how many steps our robot takes. We can make a new variable called ‘Steps Taken’ and store that information.”


Highlight the importance of choosing the right name for the variable so that when the student looks at it, it can remind them of the value that is stored in it.

After the variable is created, it will look like this:

Encourage them to identify how all variables are “pill-shaped” blocks. This will help them identify variables from other blocks quickly when creating larger code blocks.

  1. Guide them in creating a few custom variables, such as:
  • Robot’s Name: Store the robot’s name.
  • Distance Traveled: Store how far the robot has moved.
  • Number of Goals Scored: Store the number of goals if the robot is playing a game.
  1. Demonstrate how to use variable blocks like:

Teacher’s Role:
Help students create their own variables and guide them in understanding how the robot uses these variables to store changing information. Help them understand the difference between changing the value and incrementing the value of the variable.


4. Experimenting with Variables in Robot Movement (15 minutes)

Activity:
Students will apply what they’ve learned by creating variables to track the robot’s movement in real time.

Instructions:

  • Ask students to create a variable called “Steps Taken” and have it increase each time the robot moves:

“Every time the robot takes a step, we’ll increase the value of ‘Steps Taken’ by 1. Let’s see how far it travels!”

  • Let them program the robot to move forward, and after each movement, they’ll use the “Change [Steps Taken] by 1” block to update the variable.

  • Students can also track time using the “Timer” variable to see how long it takes for the robot to reach a destination.

  • Encourage students to build larger coding blocks where they store different values e.g. steps taken, left turns taken, right turns taken etc.

Ask them to check if the variable is showing the correct number of steps when the movement ends by using the “Show Variable” block:

Teacher’s Role:
Encourage students to observe how the robot’s behavior changes when they adjust the variables. Guide them to experiment with combining variables like distance and time to see how fast the robot moves over a given distance.


5. Conclusion and Wrap-Up (10 minutes)

Activity:
End the session with a discussion about how variables help us store and use information in real life and in coding.

Instructions:

  • Recap the key points about variables and how they store information.
  • Ask students to share one example of a variable they created today and how it changed during the activity.
  • Ask them what they enjoyed most during the session and which part was most challenging.

Teacher’s Role:
Facilitate the discussion, encouraging students to reflect on how they used variables to track robot movements and other information. Help them connect this lesson to the idea of storing and using information in everyday situations.


Learning Outcome:
By the end of the session, students will have a solid understanding of how variables work in coding, how to create and modify them, and how they can be applied to real-time tasks like tracking distance, time, or other data related to the robot’s behavior. With the addition of a fun activity at the end, students will be able to relax and have fun with the robot by making it come alive with expressions and messages.