Metronome and beat maker

Touch the logo to start the beat, A and B change the tempo: learners build a metronome that counts four beats to a bar and play along.

Go to the code ↓

Lesson at a glance

45 to 60 minutes · Grades 4 to 7

maze.education/microbit/lessons/metronome

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
micro:bit V2 only
This lesson needs a micro:bit V2, for its touch logo and speaker.
Code with
MakeCode blocks, with Python as an extension
CAPS
Creative Arts, Mathematics, Coding and Robotics
Fits: Grade 6, Term 3 · Where it fits

Learning intentions

Learners will learn to:

  1. Explain tempo as beats per minute, and keep a steady beat.
  2. Work out how long one beat lasts by dividing 60 000 milliseconds by the tempo.
  3. Use a counter that goes 1, 2, 3, 4 and starts again, with a stronger sound on beat 1.

Success criteria

Each learner can say:

  • I can explain tempo as beats per minute, and keep a steady beat with the metronome.
  • I can work out how long one beat lasts by dividing 60 000 milliseconds by the tempo.
  • I can use a counter that goes 1, 2, 3, 4 and starts again, with a higher note on beat 1.
  • Grade 7: I can trace beat, the note and the pause through five passes of the loop.

Competencies

From the Coding and Robotics CAPS places this lesson cites.

  • C.2Present a simple coding solution

Key words

beat
The steady pulse you tap your foot to.
tempo
How fast the beat is, counted in beats per minute (bpm).
bar
A group of beats. Many songs have four beats to a bar, with beat 1 a little stronger.
millisecond
A thousandth of a second. One minute is 60 000 milliseconds.
toggle
To switch between two states, such as on and off, with the same action.
trace table
A table that follows the value of each variable, step by step, as a program runs.

What you need

  • A micro:bit V2 for each pair (it has the speaker and the touch logo), with a USB cable and a battery holder
  • A computer with Chrome or Edge for each pair
  • A few songs the class knows, and the stopwatch on the class computer or a clock with a second hand

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

Safety

  • Keep the volume low and the micro:bit away from ears. Someone may be sensitive to sudden sounds, so warn the class before the first sound plays.
  • 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.
  • Unplug the battery holder by holding its plug, never by pulling the wires.

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 seconds are there in one minute, and how many milliseconds in one second? (There are 60 seconds in a minute and 1 000 milliseconds in a second.)

    Problem statement

    When the school's marimba band or choir practises without the music teacher, the players tend to speed up and drift apart. Build a metronome that keeps a steady beat, marks the first beat of every bar with a higher note and changes tempo at the press of a button.

    1. Play a song and ask the class to clap along. Ask: is the beat fast or slow? How could we measure it? Count the claps in 15 seconds together and multiply by 4: that is the tempo in beats per minute.
    2. Read the problem statement. Ask: why do players drift apart when nobody keeps time?
  2. Lesson development

    35 to 40 minutes
    1. Unplugged first. Be a human metronome: one learner taps a steady beat on the desk while the class counts 1, 2, 3, 4 and claps louder on 1. Then try 60 beats per minute against a clock (one tap a second), then twice as fast.
    2. Plan on paper first. Pairs work out how long one beat lasts at 60, 90 and 120 bpm: 60 000 milliseconds divided by the tempo. Then they write the algorithm and fill in the IPO table. Grade 7 learners add the trace table for five passes of the loop at 120 bpm.
    3. Predict. Ask: at 90 bpm, how long will each beat last? Which light will show on beat 3? What will the board show after B is pressed three times?
    4. Build in blocks. Pairs share one computer. The driver builds the variables, the logo toggle and the tempo buttons from the Blocks tab; the navigator checks each block against the IPO table. Swap roles halfway, after step 3, so the new driver builds the beat counter, the notes and the pauses in forever.
    5. Test and debug. Test in the simulator (click the logo to touch it), then download it to a micro:bit V2. Count the beats for 15 seconds against the clock and multiply by 4: does it match the tempo you set? If the beat is uneven, check the last pause, and check that the tone plays in the background.
    6. Pairs find the tempo of a song they know by matching the metronome to it, then compose a short clapping rhythm that fits four beats, with the strongest clap on beat 1.

    Plan on paper: a model answer

    In pairs, work out the beat lengths, then write the metronome's algorithm and fill in the IPO table. Grade 7 learners also trace five passes of the loop at 120 bpm.

    Algorithm
    1. Set bpm to 90.
    2. When the logo is touched, switch playing on or off.
    3. When A is pressed, take 10 off bpm, but not below 40, and show it. When B is pressed, add 10, but not above 200, and show it.
    4. While playing: add 1 to beat, and if it goes past 4, set it back to 1.
    5. If beat is 1, play the high note; otherwise play the lower one. Light the beat's light in the middle row.
    6. Wait until 60 000 ÷ bpm milliseconds have passed in all, then go back to step 4.
    IPO table
    InputProcessingOutput
    The logo is touchedSwitch playing from false to true, or from true to falseThe beat starts or stops
    Button A is pressedTake 10 off bpm, but not below 40The new tempo scrolls
    Button B is pressedAdd 10 to bpm, but not above 200The new tempo scrolls
    Each pass of forever, while playingAdd 1 to beat (back to 1 after 4), then pause so the beat lasts 60 000 ÷ bpm millisecondsA high note and the left light on beat 1; a lower note and the next light along on beats 2, 3 and 4
    Trace table
    Grade 7: five passes of the forever loop at 120 bpm (B pressed three times from 90), after the logo is touched.
    PassbeatNote (Hz)Light (x, y)Last pause (ms)
    119880, 2400
    226591, 2400
    336592, 2400
    446593, 2400
    55, then 19880, 2400
  3. Consolidation

    5 to 10 minutes
    1. Ask: how long is one beat at 100 bpm? At 150 bpm?
    2. Ask: why does the counter go back to 1 after 4? What would change for a waltz, with three beats to a bar?
    3. Back to the problem: perform a few rhythms with the metronomes playing together. Do they stay in time? Would the band stay together at practice with one of these? 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.

The logo starts or stops the beat, A and B change the tempo by 10 between 40 and 200, and four grids show the light moving across the middle row for beats 1 to 4, with beat 1 at 988 Hz and the others at 659 Hz.
One beat lasts 60 000 milliseconds divided by the tempo: at 90 beats per minute, about 667 milliseconds.

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 Metronome. In Variables, make bpm, beat and playing. In on start, set bpm to 90.
  2. From Input, add on logo pressed and put set playing to not playing inside (not is in Logic).
  3. Add on button A pressed: set bpm to the max of bpm minus 10 and 40, then show number bpm. Add on button B pressed with the min of bpm plus 10 and 200.
  4. In forever, add if playing then. Inside, change beat by 1, and if beat > 4 then set beat to 1.
  5. Still inside, add if beat = 1 then else: play tone 988 Hz (a high B) for 1/16 beat in the background, else 659 Hz (an E).
  6. Add plot x beat minus 1 y 2, pause (ms) 100, clear screen, then pause (ms) with 60000 ÷ bpm minus 100.
  7. Test in the simulator, then Download to a micro:bit V2.
The same blocks as text (to paste into MakeCode)
let beat = 0
let playing = false
let bpm = 90
input.onLogoEvent(TouchButtonEvent.Pressed, function () {
    playing = !(playing)
})
input.onButtonPressed(Button.A, function () {
    bpm = Math.max(bpm - 10, 40)
    basic.showNumber(bpm)
})
input.onButtonPressed(Button.B, function () {
    bpm = Math.min(bpm + 10, 200)
    basic.showNumber(bpm)
})
basic.forever(function () {
    if (playing) {
        beat += 1
        if (beat > 4) {
            beat = 1
        }
        if (beat == 1) {
            music.play(music.tonePlayable(988, music.beat(BeatFraction.Sixteenth)), music.PlaybackMode.InBackground)
        } else {
            music.play(music.tonePlayable(659, music.beat(BeatFraction.Sixteenth)), music.PlaybackMode.InBackground)
        }
        led.plot(beat - 1, 2)
        basic.pause(100)
        basic.clearScreen()
        basic.pause(60000 / bpm - 100)
    }
})

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

    Turn it into a drum machine: play a low note on beats 1 and 3 and a high note on 2 and 4.

  2. Challenge 2

    Add a tap tempo: press A twice, and the micro:bit works out the tempo from the time between taps.

  3. Challenge 3

    Play the Music maker tune in time with the metronome on a second board.

Support and extension

Support

For learners who need more help

  • Start with a plain metronome: one note on every beat, no counter. Add the bar once the beat is steady.
  • Give the beat lengths for 60, 90 and 120 bpm on the board, so learners check their sums against them.

Extension

For learners who are ready for more

  • Change the bar to three beats for a waltz, or to a setting that A and B together switch between 3 and 4.
  • Measure the real tempo with the computer's stopwatch: count beats for 30 seconds and compare with the bpm on the board. How close is it?

Informal assessment

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

  1. What does bpm stand for, and what does it measure?
  2. Why does beat 1 sound different from the others?
  3. What does the logo do in our program, and why is it called a toggle?
Exit question

How long is one beat at 120 bpm? Show how you worked it out.

Observation checklist

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

Watch forBeginningDevelopingAccomplishedExemplary
Keeps a steady beat in the human metronome.
Works out beat lengths with 60 000 ÷ tempo, and checks them.
Builds the counter so that it goes back to 1 after 4.
Checks the real tempo against a clock and explains any difference.
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 beat is uneven or stops.Fix: Check that the last pause is 60000 ÷ bpm minus 100, and that the tone plays in the background, not until done.
  • Problem: The logo turns it on and off again straight away.Fix: Check there is only one on logo pressed block, and touch the logo once rather than tapping it twice. In Python, keep the lines that wait for you to let go of the logo.
  • Problem: There is no sound.Fix: The speaker is on the back of the micro:bit V2. Check the volume is up (set volume in Music) and that the board is a V2.

Where it sits in CAPS

  • Creative ArtsGrade 6 Creative Arts: making short musical phrases with pitch and rhythm.Source: CAPS Life Skills, Grades 4 to 6 (opens in a new tab), Grade 6, Creative Arts (Performing Arts), Topic 2: Improvise and create: Musical phrases exploring dynamics, pitch and rhythmic patterns
  • Coding and RoboticsFitsGrade 6, Term 3: division and the other calculations in a program, here to work out how long a beat lasts.Source: Coding and Robotics CAPS, Grades 4 to 6 (opens in a new tab), Grade 6, Term 3, Coding, C.2 Present a simple coding solution, page 149: You have learned about the following calculations: plus, minus multiply and divide (+ - * /):
  • MathematicsFits Mathematics: time in seconds and milliseconds, and division with a real reason to do it.

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