Music maker

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

Go to the code ↓

Lesson at a glance

45 to 60 minutes · Grades 4 to 7

maze.education/microbit/lessons/music-maker

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 and Purple Mash blocks, with Python as an extension
CAPS
Creative Arts, Coding and Robotics
Fits: Grade 5, Term 3 · Where it fits

Learning intentions

Learners will learn to:

  1. Program buttons and a gesture to play notes and melodies.
  2. Compose a short melody of eight notes and play it back.
  3. Explain how pitch relates to frequency: the higher the number, the higher the note.

Success criteria

Each learner can say:

  • I can make buttons A and B, both buttons together and a shake each play a note or a tune.
  • I can compose an eight-note melody in the melody editor and play it back.
  • I can explain why 392 Hz sounds higher than 262 Hz.
  • I can explain the difference between playing a sound until done and in background.

Competencies

From the Coding and Robotics CAPS places this lesson cites.

  • R.7Create, test and execute a set of robotic instructions

Key words

pitch
How high or low a note sounds.
frequency
How many times a second a sound vibrates, measured in hertz (Hz).
beat
The steady pulse of music. Notes last a whole beat, half a beat and so on.
tempo
How fast the music goes, in beats per minute (bpm).
melody
Notes played one after another to make a tune.
IPO table
A plan with three columns: the input, the processing and the output.

What you need

  • One micro:bit per learner or pair, with a USB cable and a battery holder
  • A micro:bit V2 for the sound: it has a speaker built in, and a micro:bit V1 does not
  • A computer with Chrome or Edge for each learner or pair

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.

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

    What is an event in a program? (Something that happens, such as a button press or a shake, that starts part of the program.)

    Problem statement

    For the Heritage Day concert, the music teacher has one keyboard for a class of forty, so most learners wait a long time to try out a melody. Program a pocket instrument on the micro:bit V2 that plays notes, a scale and a tune, and compose an eight-note melody for it.

    1. Sing or play a scale: do, re, mi, fa, so, la, ti, do. Learners show high and low notes with their hands. Tell them that every note is a number to a computer: middle C vibrates about 262 times a second, so its frequency is 262 Hz.
    2. Read the problem statement together. Ask: what should the instrument play, and which button should do what?
  2. Lesson development

    35 to 40 minutes
    1. Unplugged first. Fill glasses or bottles with different amounts of water and tap them gently with a pencil. Which one makes the highest note? Learners arrange them from low to high and play a short tune.
    2. Plan on paper first. Pairs fill in an IPO table for the instrument, with a row for each input: button A, button B, A and B together, and a shake. Under the table they write their own eight-note melody as note letters, such as E D C D E E E E.
    3. Predict. Ask: which button will play the higher note, A at 262 Hz or B at 392 Hz? What will change when the tempo goes from 120 to 60, and what will stay the same? Pairs write their answers beside the plan.
    4. Build in blocks. Pairs share one computer, with the simulator's sound on low. The driver builds buttons A and B from the steps on the Blocks tab; the navigator checks each event against its row of the IPO table. Swap roles halfway, after button B, so the new driver builds A and B together and the shake.
    5. Test and debug. Test each row of the IPO table in the simulator, then download the program to a micro:bit V2. Did B sound higher, as you predicted? Change the tempo from 120 to 60, then to 200, and compare with your prediction. If there is no sound, check the board has the gold logo of a V2.
    6. In on button A+B pressed, click the melody to open the melody editor and put in the eight-note melody from your plan. Pairs perform it for another pair and explain how they built it.

    Plan on paper: a model answer

    In pairs, fill in an IPO table with a row for each input the instrument uses, then write your own eight-note melody as note letters.

    IPO table
    InputProcessingOutput
    Button A is pressedStart middle C (262 Hz) for half a beat, in the backgroundC plays, and the letter C shows while it plays
    Button B is pressedStart G (392 Hz) for half a beat, in the backgroundG plays, and the letter G shows while it plays
    A and B are pressed togetherShow the eighth note, then play the eight notes from C up to the next C at 120 beats a minute, until doneThe eighth note picture, and the scale
    The board is shakenStart the Entertainer melody, in the backgroundThe tune plays
  3. Consolidation

    5 to 10 minutes
    1. Ask: what is the difference between pitch and tempo? Play two tones, 262 and 392. Which number is the higher note?
    2. Ask: why do we start the note in the background before showing the letter? (So the letter shows while the note plays, not after it.)
    3. Back to the problem: could a class share these instruments to try out melodies for the concert, and what would you add to make it more useful? 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.

Button A plays C (262 Hz) and shows C, B plays G (392 Hz) and shows G, A and B together play the scale with an eighth note picture, a shake plays a melody, and a bar chart shows C 262, D 294, E 330, F 349 and G 392 Hz.
Every note is a number to the computer: the higher the frequency in hertz, the higher the note.

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 Music maker.
  2. From Input, drag in on button A pressed.
  3. From Music, drag the play tone block (Middle C for 1 beat) into it. Change 1 beat to 1/2 beat, and until done to in background.
  4. From Basic, add show string under it and type C.
  5. Do the same for button B: click the note, pick G on the keyboard (392 Hz) and show the letter G.
  6. Add on button A+B pressed (change the letter in a button block to A+B). Put show icon with the music note in it, then play melody ... at tempo 120 (bpm) until done from Music.
  7. From Input, drag in on shake, and from Music add play melody entertainer in background.
  8. Test in the simulator, then Download.
The same blocks as text (to paste into MakeCode)
input.onButtonPressed(Button.A, function () {
    music.play(music.tonePlayable(262, music.beat(BeatFraction.Half)), music.PlaybackMode.InBackground)
    basic.showString("C")
})
input.onButtonPressed(Button.AB, function () {
    basic.showIcon(IconNames.EighthNote)
    music.play(music.stringPlayable("C D E F G A B C5 ", 120), music.PlaybackMode.UntilDone)
})
input.onButtonPressed(Button.B, function () {
    music.play(music.tonePlayable(392, music.beat(BeatFraction.Half)), music.PlaybackMode.InBackground)
    basic.showString("G")
})
input.onGesture(Gesture.Shake, function () {
    music.play(music.builtInPlayableMelody(Melodies.Entertainer), music.PlaybackMode.InBackground)
})

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

    Keep your tune in time with the Metronome and beat maker on a second board.

  2. Challenge 2

    Turn the micro:bit into a theremin: play a tone whose pitch rises as you tilt the board, using acceleration (mg) x.

  3. Challenge 3

    Record the notes of a song the class knows as letters on paper, then play it back on the micro:bit.

  4. Challenge 4

    Program the school song Bana ba Sekolo, the song the Grade 5 CAPS uses, so that it plays when A is pressed.

Support and extension

Support

For learners who need more help

  • Build button A only, then copy and change it for button B.
  • Give learners a card with note names and frequencies: C 262, D 294, E 330, F 349, G 392.

Extension

For learners who are ready for more

  • Use on logo pressed (micro:bit V2) for a third note, and make a three-note riff.
  • Write the melody for a song the class knows, such as a school song or Happy Birthday, in the melody editor.

Informal assessment

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

  1. Which is higher, a tone of 262 Hz or one of 392 Hz?
  2. What does the tempo number change?
  3. What is the difference between until done and in background?
Exit question

E is 330 Hz. Is it higher or lower than C, and how do you know?

Observation checklist

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

Watch forBeginningDevelopingAccomplishedExemplary
Fills in the IPO table with a row for each input before building.
Builds each event and tests it against its row of the table.
Predicts which note is higher and what the tempo changes, then checks by listening.
Composes an eight-note melody and plays it back.
Explains that a higher frequency gives a higher note.
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: There is no sound on our micro:bit.Fix: A micro:bit V1 has no speaker, so use a micro:bit V2 (it has a gold logo on the front). On a V2, check the volume has not been set to 0.
  • Problem: Pressing A and B together plays the single notes.Fix: Press both buttons at exactly the same time, and check there is an on button A+B pressed block.
  • Problem: The tune keeps playing over the notes.Fix: That is in background at work. Change the shake melody to until done if you want it to finish first.

Where it sits in CAPS

  • Coding and RoboticsFitsGrade 5, Term 3: a button that plays music on the micro:bit.Source: Coding and Robotics CAPS, Grades 4 to 6 (opens in a new tab), Grade 5, Term 3, Robotics, R.7 Create, test and execute a set of robotic instructions, page 115: The music for the song must play when Button A is pressed.
  • Coding and RoboticsFitsGrade 5, Term 3: code a song for the micro:bit to play (the CAPS uses Bana ba Sekolo).Source: Coding and Robotics CAPS, Grades 4 to 6 (opens in a new tab), Grade 5, Term 3, Robotics, R.7 Create, test and execute a set of robotic instructions, page 115: write the code to produce music for the song, Bana ba Sekolo,
  • 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
  • Creative ArtsFits Creative Arts (Music) in Grade 7: composing and performing short melodies.

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

    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

  • Grades 4 to 7

    Grades 4 to 745 to 60 minLevel: Some experience

    Morse code messenger

    A sends a dot, B sends a dash: pairs tap out secret words by radio, decode them with a Morse chart and learn how the telegraph worked.

    Subjects: Coding and Robotics · Social Sciences · Natural Sciences and Technology · Technology

    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