How can a variable affect a sensor?

Challenge learners to think about what might happen if Marty detects a color they don't know. The two examples are 'air' and 'unclear'. Air is when there is nothing detected and unclear is when the color is not red, blue, green, purple or yellow.
Variables may still be a very new concept for learners. The connection to real world example is crucial. This lesson uses recipes, with the number of cakes being a variable.
Reinforce that the purpose of the learning is not to build a complex program with variable but rather just to describe what they are and change the declared value. Share with learners more examples of variable in their daily life to remove the stigma that 'variables are hard': learners will use and interact with variables on a daily basis without realising or thinking about it.
Some examples of variables can include:
22 of 22 linked standards shown.
| Curriculum area | Linked standards |
|---|---|
| Digital Technologies, Design & technologies: Design & Technologies | |
| Digital Technologies, Design & technologies: Digital Technologies |
Select a code to read the full standard.
| Curriculum area | Linked standards |
|---|---|
| General standards |
Select a code to read the full standard.
| Curriculum area | Linked standards |
|---|---|
| Health and Wellbeing: Mental, Emotional, Social and Physical Wellbeing | |
| Literacy & English: Listening and Talking | |
| Literacy & English: Writing | |
| Technologies: Computing Science | |
| Technologies: Craft, Design, Engineering and Graphics |
Select a code to read the full standard.
| Curriculum area | Linked standards |
|---|---|
| Computing, Design and Technology: Computing | |
| Computing, Design and Technology: Design and Technology |
Select a code to read the full standard.
| Curriculum area | Linked standards |
|---|---|
| International Society for Technology in Education (ISTE) |
Select a code to read the full standard.
| Curriculum area | Linked standards |
|---|---|
| Elementary Technology Applications: Grade 3 to Grade 5 |
Select a code to read the full standard.
Learners will explore events, measurements and objects that change in terms of size, value, or number over the course of time. We say that things that can change, vary. A variable is used to represent an amount, either when we are not sure what the amount is or when it can change.
Knowledge of block values and repeats; experience with conditional statements
This lesson will involve Marty walking and might be best to have Marty on the ground for all code tests.
Share with the learners a recipe for making a cake, the video shows how to make a cake in a mug using a microwave. Some measurements use the customary, or imperial, measurement and some use metric. There is no need to focus on the measurement types, the important part is the numerical value of each measurement; however, this could lead to a discussion on conversion if it is appropriate. Each measurement shows onscreen as the video plays.
As learners watch, have them record the values for the recipe in their workbooks. Once complete, have learners calculate how much of each ingredient would be needed for two or more cake cups, support learners with the calculations as needed, the goal is more about thinking how the recipe amounts will vary - when I have two cakes I will double the ingredients, when I have three cakes I will treble them - rather than the actual amount at the end - 2 x 3 = 6 or 1/2 x 3 = 1 1/2.
After the learners have completed the table, ask them what the variable was (the number of cakes). Reinforce that the variable is the number of cakes by explaining that as it changes, the total ingredients change but the types of ingredients for each cake do not change. The focus is not to define independent and dependent variables in this lesson, just to compute the new values for the total quantity of each ingredient.
The following video features Marty acting based on a variable. The variable counts the number of times a user taps a sprite in 10 seconds. Then, the program instructs Marty to take that many steps. The video below shows that the variable name is steps, this makes sense for this variable because the output will be Marty's steps. Encourage learners, when it comes to them declaring, or naming, their variables, to use a name that makes sense.
Below is a sample of Marty using a variable and the code that instructs them.
Have learners share their observations at the end. The video has this program run twice so that learners can see that the number of steps and sprite taps have both changed. The transitions are only to give Marty more screen space when walking.
After viewing this video, have learners record the values for the variables in their workbook. Below is the process of setting the code to have Marty walk based on the taps.
As a whole class, it would be good to model a variable and its changing nature affecting Marty. This could be done with the tapping, as demonstrated, or it could be showcased with a loop that increases Marty's step count or arm movement. There are example code blocks in the teacher guide that you could use to display this functionality.
The workbook describes the task for the learners to complete for this lesson but there is information in the presentation that is useful for first steps with variables; additionally, the information is available in the section that expands, below.
Variables have their own section in the MartyBlocks environment. The image in the presentation (below) shows where to find the variable section and the purpose of two of the blocks.

The following image shows what happens after tapping 'Make a variable'.

After tapping OK, learners will see a new block called Value, which is set to 0 for just now.

This video shows learners how to find the variable section, and declare one for using with Marty, assign an initial value and change its value. This is a manual change rather than an automatic one, the earlier video of Marty walking had an automatic change. The video has no output through the physical Marty, the output is on the sprite Marty in MartyBlocks. The video stops before the green flag is pressed, have learners suggest what the Marty sprite will 'say' Discuss with learners what the output for a physical Marty could be: number of waves, kicks, steps, degrees for a movement, time taken for a movement, basically anything that is an argument in MartyBlocks for one of Marty's movements or looks.
Learners need to have time to practice:
The workbook offers a series of guiding questions in order to have learners design a program to make use of variables with color detection, rather than focusing on numerical values. The teacher guide shows finished examples of the code learners could create, with explanations for what is happening.
Bring learners back together to discuss the challenges they faced and overcame. Have groups describe their creations and explain what is happening. If you can do so, model them on the trial Marty using each group's device. Encourage other groups to ask questions to deepen their understanding of the processes.
Suggested questions you might ask:
Carry out any end of lesson routines.
Log off devices and clear everything away.