About this project


This project shows pupils how to introduce music and sound effects into their BBC micro:bit projects by teaching them how to write the tune 'Happy Birthday' using blocks of code.


What you'll need


1 x BBC micro:bit

1 x Micro USB

1 x Computer or tablet

2 x AAA Batteries & Battery Holder

1 x mini speaker or similar (optional)

2 x sets of crocodile clips (optional)



Project walkthrough



  • Click 'Music' in the left-hand command menu and select the tile that reads 'Play tone (Hz) [C] for (ms) [1] beat (ms)'. This tile tells your BBC micro:bit to play a specific note, for anything from 1/16 to a full beat.


  • Right click on this cool and select 'duplicate' to clone the tile. Repeat until you have six identical tiles. This saves you from dragging and dropping a new tile from the command menu for every individual note.


  • Attach the six tiles together, and change the notes until they form the first stanza of 'Happy Birthday', like so...

BBC micro:bit

  • You may also want to change the '[1] beat (ms)' to [1/4] beat (ms) as indicated to speed up the song.


  • Add a 'pause' tile from the basic commands menu, and set it to 500 milliseconds.


  • Duplicate a further six 'play tone (Hz)...' tiles and connect them to the 'Pause' tile to create the second part of the song.


  • The notes for this stanza are: C, C, D, C, G, F

BBC micro:bit

  • Add another 500 millisecond pause tile, then duplicate another seven 'Plat tone (Hz)...' tiles for the third part of the song.


  • The notes for this section should be: C, C, C, A, F, E, D.

BBC micro:bit

  • Add another 500 millisecond pause tile followed by six 'play tone (Hz)...' tiles for the final part of the song.


  • The last set of notes should be: A, A, B, F, G, F

BBC micro:bit

  • You've now mastered the basics of writing songs for the BBC micro:bit! Click 'run' to test the tune out on the emulator.


  • To play the song on your BBC micro:bit, you'll need to connect the device to a suitable speaker system. A simple general purpose mini speaker should be sufficient.


  • Before attaching the BBC micro:bit to the speaker, you might want to wrap your code in a function telling the device to only play the tune when button A is pressed, like so:


BBC micro:bit


  • When you're satisfied, click 'compile' to download your script and transfer to your device.


  • To connect your BBC micro:bit to a speaker, use your crocodile clips to attach the positive and negative inputs on the speaker to the 0 and GND pins on the device. It doesn't matter which way round they're connected.


BBC micro:bit


  • Finally, push the A button, and your newly composed jingle should start playing!


Once your pupils understand how to create simple songs, encourage them to apply their new skills to previous projects. Can they figure out how to add a sound effect when their countdown timer reaches zero, for example? Let us know how your pupils get on in the comments section below...