Compass treasure map

Groups hide treasure, write the route as compass bearings, and the micro:bit points the way: turn left, turn right or walk on.

Go to the code ↓

Lesson at a glance

45 to 60 minutes · Grades 4 to 7

maze.education/microbit/lessons/compass-treasure-map

Grades
Grades 4 to 7
Time
45 to 60 minutes
The CAPS gives Coding and Robotics 2 hours a week (Coding and Robotics CAPS, Grades 4 to 6, page 22; Grades 7 to 9, page 22).
Level
Some experience
For classes that have used the micro:bit and MakeCode once or twice.
Board
Any micro:bit
Code with
MakeCode blocks, with Python as an extension
CAPS
Social Sciences, Mathematics, Coding and Robotics
Fits: Grade 7, Term 3 · Where it fits

Learning intentions

Learners will learn to:

  1. Give directions as compass points and as bearings in degrees.
  2. Store a route as a list of bearings and step through it with a button.
  3. Use the compass heading to decide whether to turn left, turn right or walk straight on.

Success criteria

Each learner can say:

  • I can give a direction as a compass point and as a bearing in degrees.
  • I can store a route as a list of bearings and step through it with button A.
  • I can explain how the program chooses between the tick, the arrow to turn left and the arrow to turn right.
  • Grade 7: I can work out diff for a bearing and a heading, and say which picture will show.

Competencies

From the Coding and Robotics CAPS places this lesson cites.

  • C.2Present a simple coding solution

Key words

bearing
A direction in degrees, measured clockwise from north: east is 90, south is 180, west is 270.
heading
The direction the top of the micro:bit is pointing, from 0 to 359 degrees.
route
The path from the start to the treasure, written here as a list of bearings.
list
Several values stored together in order. The first item is number 0.
calibrate
To set up the compass by tilting the board until the screen fills with lights.
trace table
A table that follows the value of each variable, step by step, as a program runs.

What you need

  • A micro:bit for each group of three, with a USB cable and a battery holder
  • A computer with Chrome or Edge for each group
  • A playground or field, a small 'treasure' for each group (a bottle top or a small stone), and paper and a pencil for the route

From our shop: BBC micro:bit V2 Go, BBC micro:bit V2.21 Next Gen Classroom Pack

Safety

  • Agree the boundaries of the hunt before anyone goes outside, and walk, never run, while looking at a screen.
  • Clear a safe space first: no bags on the floor, and enough room for everyone to move without bumping into each other.
  • Use the battery holder with two AAA batteries. Never mix old and new batteries, and take the batteries out before the kits are packed away.

The lesson plan

One lesson of 45 to 60 minutes in three parts: introduction, lesson development and consolidation. The CAPS gives Coding and Robotics 2 hours a week, so it fits one of the week's lessons. Times are a guide.

  1. Introduction

    5 to 10 minutes
    Retrieval practice

    How many degrees are there in a full turn, and in a quarter turn? (There are 360 degrees in a full turn and 90 in a quarter turn.)

    Problem statement

    On a Drakensberg hiking trail or an open field there are no street names, so hikers and search and rescue teams describe a route as compass bearings. Hide treasure on the school field, write its route as bearings, and program the micro:bit to guide another group to it.

    1. Ask: which way is north from our classroom? Point. Then draw the compass rose with eight points and add the bearings: N 0, NE 45, E 90, SE 135, S 180, SW 225, W 270, NW 315.
    2. Read the problem statement. Ask: why would a hiker give a bearing, such as 135, rather than just say south-east?
  2. Lesson development

    35 to 40 minutes
    1. Unplugged first. Play compass commands: everyone stands facing north. The teacher calls a bearing, such as 90 or 225, and the class turns to face it. Then ask: you face 300 and must face 45. Is it quicker to turn left or right?
    2. Plan on paper first. Groups write the algorithm and fill in the IPO table. Grade 7 learners add the trace table: diff for the first bearing, 45, as a learner turns on the spot.
    3. Predict. Ask: the route says 90 and the board faces 30. Which picture will show? What will show after A has been pressed four times?
    4. Build in blocks. In each group of three, the driver builds the program from the Blocks tab, the navigator checks each block against the algorithm and the third learner reads out the next step. Swap roles halfway, after step 3, so someone new builds diff and the arrows.
    5. Test and debug. Download, then calibrate the compass when the board asks: tilt it until the screen is full. Hold it flat and turn slowly on the spot. Did the tick and the arrows match your predictions? Press A four times for the diamond, then B to start again.
    6. Outside, each group hides its treasure and writes the route as bearings and steps, for example 45 for 10 steps, then 180 for 6 steps. Put your bearings into the route list, download again and swap boards and step counts with another group.
    7. Follow the other group's route: turn until you see the tick, walk the steps, then press A for the next bearing. The diamond means you should be standing on the treasure.

    Plan on paper: a model answer

    In groups, write the program's algorithm and fill in the IPO table. Grade 7 learners also trace diff for one bearing as a learner turns on the spot.

    Algorithm
    1. Store the route as a list of bearings, 45, 180, 270 and 0, and start at leg 0.
    2. If leg has reached the end of the list, show the diamond: you are at the treasure.
    3. Otherwise, work out diff: the bearing for this leg, minus the heading, plus 360, then the remainder after dividing by 360.
    4. If diff is under 20 or over 340, show the tick. If not, and it is under 180, show the arrow to turn right. Otherwise show the arrow to turn left.
    5. When A is pressed, move on to the next leg. When B is pressed, go back to leg 0.
    6. Repeat from step 2.
    IPO table
    InputProcessingOutput
    The compass heading, many times a secondWork out diff from this leg's bearing and the heading, then ask: within 20 degrees? Under 180?The tick (walk on), the East arrow (turn right) or the West arrow (turn left)
    Button A is pressedAdd 1 to leg, to use the next bearing in the routeThe picture for the next leg; after the last leg, the diamond
    Button B is pressedSet leg to 0The picture for the first leg again
    Trace table
    Grade 7: diff for the first leg, bearing 45, as a learner turns on the spot.
    Heading45 minus heading, plus 360diff (the remainder after ÷ 360)The display shows
    300105105East arrow: turn right
    040545East arrow: turn right
    3037515The tick: walk on
    60345345The tick: walk on
    90315315West arrow: turn left
  3. Consolidation

    5 to 10 minutes
    1. Ask: who found the treasure? If you missed it, where did the route go wrong: the bearing, the steps or the compass?
    2. Ask: why do we add 360 before finding the remainder? What would happen with a negative number?
    3. Back to the problem: would your route get a stranger to the treasure? Where else do people use bearings? Think of pilots, ships, hikers and search and rescue teams. Learners check themselves against the success criteria.

Build it, step by step

Pairs build the program in blocks, following the numbered steps, with the same program as text beside them to check against or paste. Test in the simulator before sending it to a board.

A compass rose with the eight points and their bearings. For an example bearing of 90, the tick shows when you face between about 70 and 110; facing from about 270 round through north to 70 gives the East arrow (turn right); facing from about 110 round through south to 270 gives the West arrow (turn left).
How the program chooses the arrow, shown for a bearing of 90 (east). The zones turn with the bearing on each leg of the route.

These are the MakeCode steps. The other routes are on the lesson's web page.

Build it in MakeCode blocks

  1. Start a New Project called Treasure map. In on start, use set route to array of from Arrays (under Advanced) with 45, 180, 270 and 0.
  2. In Variables, make leg and diff. Add on button A pressed with change leg by 1, and on button B pressed with set leg to 0 to start again.
  3. In forever, add if then else from Logic: if leg ≥ length of array route, show icon with the diamond. That is the treasure.
  4. In the else part, set diff to the remainder of (the route get value at leg, minus compass heading (°) from Input, plus 360) ÷ 360.
  5. Still in else, add if then else if then else: if diff < 20 or diff > 340, show the tick; else if diff < 180, show arrow East (turn right); else show arrow West (turn left).
  6. Download to the micro:bit and calibrate the compass when it asks.
The same blocks as text (to paste into MakeCode)
let diff = 0
let leg = 0
let route = [45, 180, 270, 0]
input.onButtonPressed(Button.A, function () {
    leg += 1
})
input.onButtonPressed(Button.B, function () {
    leg = 0
})
basic.forever(function () {
    if (leg >= route.length) {
        basic.showIcon(IconNames.Diamond)
    } else {
        diff = (route[leg] - input.compassHeading() + 360) % 360
        if (diff < 20 || diff > 340) {
            basic.showIcon(IconNames.Yes)
        } else if (diff < 180) {
            basic.showArrow(ArrowNames.East)
        } else {
            basic.showArrow(ArrowNames.West)
        }
    }
})

To use the text instead: open MakeCode, start a new project, click JavaScript at the top, replace what is there with this code, then click Blocks to see it as blocks.

To send it to the board, click Download. In Chrome or Edge, MakeCode can connect to the micro:bit by USB so the program goes straight onto it. Otherwise a .hex file downloads: drag it onto the MICROBIT drive.

Extension or homework

Challenges for learners who finish early, or to take further in a club or as homework.

  1. Challenge 1

    Draw the route on squared paper to scale, one square for each step, and check it ends where the treasure is.

  2. Challenge 2

    Add a sound on a micro:bit V2 when the board points the right way, so learners can follow the route by ear.

  3. Challenge 3

    Go back to the Compass lesson and make the board show all eight points as letters.

Support and extension

Support

For learners who need more help

  • Use only the four main points (0, 90, 180 and 270) and short routes of two or three legs.
  • Give each group the finished program and let them change only the numbers in the route.

Extension

For learners who are ready for more

  • Add the step counts to the program too: a second list, and show the number of steps when the tick appears.
  • Make the tick appear only within 10 degrees, then 5. How much harder is the hunt? Why might a real compass need a wider range?

Informal assessment

Ask these as learners work. Informal assessment happens every day and is not recorded.

  1. What bearing is south-west? What bearing is east?
  2. What is stored in the route list, and how does the program know which item to use?
  3. Give one reason a group might end up in the wrong place.
Exit question

The route says 90 and the heading is 30. Will the arrow say turn left or turn right? Why?

Observation checklist

Watch pairs as they plan, build and test. Write each pair's initials under the level you see.

Watch forBeginningDevelopingAccomplishedExemplary
Turns to face a bearing called out in degrees.
Writes a route as bearings and steps that another group can follow.
Predicts the picture for a bearing and a heading, then checks it.
Calibrates the compass and holds the board flat while turning.
Beginning:
not yet, even with help
Developing:
with help
Accomplished:
on their own
Exemplary:
on their own, and explains it or takes it further

The four levels are the CAPS rubric levels (Coding and Robotics CAPS, Grades 4 to 6, page 176; Grades 7 to 9, page 163). The short descriptions are ours.

This lesson is not a formal task, but it is good practice for the term's practical task in Grades 4 to 6 (Coding and Robotics CAPS, Grades 4 to 6, page 170), and for the mini-PATs in Grades 7 to 9 (Coding and Robotics CAPS, Grades 7 to 9, page 157).

Common mistakes and fixes

  • Problem: The arrow points the wrong way or keeps changing.Fix: Calibrate again, hold the board flat and keep it away from metal, phones and laptops.
  • Problem: The diamond shows straight away.Fix: Press B to set leg back to 0. Check the route list has bearings in it.
  • Problem: The tick never shows.Fix: Turn slowly: the tick appears only within 20 degrees of the bearing. Check the bearings are between 0 and 359.

Where it sits in CAPS

Coding and Robotics quotes come from the Department of Basic Education's final CAPS, with the page number of the 2024 printed edition (the Department's October 2025 library copies number their pages differently). Schools may teach a topic in another term: the CAPS leaves the order to each school's annual teaching plan.

Ready to teach it?

Get a micro:bit for every learner or pair, and let us train your staff to run lessons like this one.

More lessons

All lessons →
  • Grades 4 to 7

    Grades 4 to 745 to 60 minLevel: Getting started

    Step counter

    Every step adds one: learners use a variable to count steps, show the total and reset it, then test how accurate it is.

    Subjects: Coding and Robotics · Mathematics · Life Skills · Life Orientation

    Code with: MakeCodePurple MashPython

  • Grades 4 to 7

    Grades 4 to 745 to 60 minLevel: Some experience

    Music maker

    Buttons play notes, A and B together play a scale and a shake starts a tune: a pocket instrument learners compose for.

    Subjects: Creative Arts · Coding and Robotics

    Code with: MakeCodePurple MashPython

  • Grades 4 to 7

    Grades 4 to 745 to 60 minLevel: Some experience

    30-second fitness challenge

    Press A, count down, and the micro:bit counts your star jumps for 30 seconds using its motion sensor.

    Subjects: Life Skills · Life Orientation · Coding and Robotics · Mathematics

    Code with: MakeCodePython

micro:bit is a trade mark of the Micro:bit Educational Foundation, and BBC is a trade mark of the British Broadcasting Corporation. Maze Education is an independent reseller of genuine BBC micro:bit products. Our teacher training and our other products and services are our own, and are not endorsed by the Foundation or the BBC.

WhatsApp