🔎 Unit Overview
- You will understand the constructs of sequencing, selection and iteration – programming
- Develop a physical computing solution using a micro:bit for navigating around a set course
- Learn how to design a flowchart diagram and the importance of pre-planning a project
🎯 Learning Objectives
Develop the Programming & Development, Algorithms Learning Strands:
- Understand basic sequencing, selection and iteration
- Develop a flowchart for a robot sequence
- Program a micro:bit robot to move in a set pattern
- Continue to use the MakeCode website to program the micro:bit
- Learn how to program with the Klip motor components
💬 Key Vocabulary
- algorithm
- sequencing
- selection
- iteration
- function
- robot
- flowchart diagram
- micro:bit
📝 Starter Activity – Maze Runner
- A student is at the start of a maze and needs to make their way through the maze to reach the finish
- There is a safe path through the maze and the student must not step off the path at any point
- The student is blindfolded so can only be guided by you and the instructions you give so be accurate with directions and distance
…
What do you need to think about when giving the instructions to guide the student safely through the maze?
Think then discuss it in pairs and be ready to share your thoughts.
Remember – The student must not walk off the safe path and they must reach the finish!
📖 Robotics with micro:bits
Over the next three lessons you will be programming a micro:bit robot to navigate through a predesigned maze.
Before you can begin to program your robot you need to think about the following points
- What is the layout of the maze?
- What movement commands will I use when navigating the robot through the maze?
- In what order will I program these movement commands so the robot makes it successfully through the maze?
Lets begin with how you plan the order of the movement commands by using an algorithm
📖 What is an algorithm?
An algorithm is a set of step–by–step instructions designed to solve a problem.
Think of this like the instructions you use when performing tasks such as…
- The recipe you follow to bake cookies or a cake
- The instruction book you follow to build a Lego set
- The steps you follow to brush your teeth
- Pick up toothbrush
- Put toothpaste on toothbrush
- Brush teeth with toothbrush
- Stop after 3 minutes
You will need to plan and create an algorithm to successfully navigate the robot through a maze.
📖 Construct Basics
An algorithm is made up of three basic building blocks: sequencing, selection, and iteration.
These are know as constructs.
Sequencing
An algorithm is a step-by-step process, and the order of those steps are important to successfully complete the task.
For example, you wouldn’t brush your teeth before picking up the toothbrush first, or put the toothpaste on after you’ve stopped brushing your teeth.
Selection
An algorithm has to make a decision because it has reached a step where one or more options are available. When the choice is made, the algorithm will follow a certain step and ignore the others.
For example, you walk along a path and ahead the path splits into two opposite directions. You now have to made a decision and choose one of the paths to take. Remember, you can only take one of the paths.
Iteration
An algorithm makes a single pass through a set of instructions. This can be repeated, or looped, a set number of times or until a condition is met.
For example, a car could go round a race track for exactly 100 laps before it then stops. Or a car could keep going around a race track until it runs out of fuel and stops.
📖 Sequencing and Flowchart Diagrams
You will use sequencing to design your algorithm when programming your micro:bit robots to navigate through a maze.
Using a flowchart diagram is a way of writing down the step-by-step instructions in an ordered layout.
📝 Silver Badge Activity – Design a Flowchart Diagram
Your first challenge is to plan out how a robot would move along the lines of this ‘T’ shape opposite using the flowchart worksheet. You only need to write down the direction and not the distance travelled.
- Download the flowchart worksheet
- You are going to design a flowchart diagram to plan out the robot’s full route
- You will need to use the following instructions. Some of these instructions you will need to use more than once
- Switch robot on – Start
- Switch robot off – Stop
- Turn Right
- Turn Left
- Drive Forward
- When you have finished upload to the Silver Badge on Bourne to Learn
…
📝 Gold Badge Activity – Hip to be Square
Working in a group of three, you will now learn how to program the robot to move in the pattern of a square.
Each group member will be creating their code on the MakeCode website and taking screenshots of the code as evidence for the badges.
You will have a single robot per group but each group member must program their own micro:bit.
The robot will use one micro:bit at a time but make sure each team member has a turn at using their micro:bit within the robot.
REMEMBER – Save your code frequently
Step 1
First you need to go to the Micro:bit website and create a new project
- Go to the makecode.microbit.org website
- Click on New Project and name it ‘Micro:bit Robotics‘
Step 2
Now you need to add the Klip motor components to allow you to control and move the robot
- Click the extension part at the bottom of the screen
- Search for the Kitronik Klip Motor and add the extension by clicking on it
- You should now have the Klip Motor option for building your robot code
.
Step 3
You will now learn how to command the robot to move from turning on the motors and setting the travel distance.
The first step is to set the travel distance and turn time then create the four functions to allow the robot to move forward, turn left and right and stop.
- Create two variables labelled travelDistance and turnTime.
- Set travelDistance to 1500 and turnTime to 500 and add them to ‘on start‘
- You need to create four functions labelled driveForward, turnLeft, turnRight, and Stop. Start with creating the driveForward function
- Click on Advanced then click on Functions
- Within the Functions option click ‘Make a Function…’
- Click on the doSomething label and overwrite it with driveForward then click Done
- You have now created the driveForward function. Next is to add in the code to turn both the motors to make the robot move forward.
- Click on the Klip Motor menu then add in the turn motor command
- You will need to add this in twice to turn motor 1 and motor 2
- Make sure both motor 1 and motor 2 have the speed set to 100
- Now create the functions for turnLeft, turnRight and Stop as shown below. The reverse option is used as well as forword to enable the robot to change direction
.
Step 4
With the functions created, call the functions in the correct sequence to move the robot in the pattern of a square
- Open the Input menu and drag the ‘on button A‘ block onto the canvas
- Open the Advanced dropdown menu then the Functions menu.
- Click on the call driveForward block
- Move this to within the ‘on button A’ block
- Add in a pause block from the Basic menu and use the travelDistance variable to set the pause time length
.
Step 5
Continue to add the blocks of code to allow the robot to move in a square pattern then come to a complete stop
- Once you have completed the code download your code onto the micro:bit
- Plug the micro:bit into the robot then test by pressing the button A
- If the robot drives in a square pattern upload a screenshot of your code to the Gold Badge section on Bourne to Learn
.
📝 Platinum Badge Activity – Research Task
- You have been requested to write a document explaining to a Year 6 school class about today’s lesson.
- In your own words describe and explain the following programming concepts…
- What is an algorithm?
- What is Sequencing?
- What is Selection?
- What is Iteration?
- Make sure to include examples of each construct above and remember your audience is Year 6 students.
- Upload a screenshot of your finished document to Bourne to Learn.
…
🏅 Badge it
🥈 Silver Badge
- Upload a screenshot of your Flowchart Diagram Worksheet to Bourne to Learn.
🥇 Gold Badge
- Upload a screenshot of your working code making the robot drive in a square pattern to Bourne to Learn.
🥉 Platinum Badge
- Upload a screenshot of your Research Task Word Document to Bourne to Learn.
In this lesson, you…
- Learned what an algorithm is and the constructs of sequence, selection and iteration
- Created a workflow diagram for instructions on completing a set course
- Learned how to program a micro:bit robot using commands in a sequence
Next lesson, you will…
- Program the micro:bit robot to complete a course
- Design your own course, create a workflow diagram and program the micro:bit robot to complete it