Make your own iPod with a micro:bit

By Valérie Gillon, team Wallonia

To see the original article in French, go to:
Dutch translation coming soon.

 For this workshop you will need:
• Two crocodile clips
• Earphones
• A micro: bit 😊

To complete this tutorial, we suggest using mu editor

1. Connect our earphones

Here we will use the 2 crocodile clips to connect the microbit and the earphones.

First, place a clip on port 0 of the Microbit and one on the GND port (ground) like this:

Then connect our crocodile clips to one of the earphones. We connect the ground (GND port), here the black wire, at the base of the earphone plug.
The other crocodile clip is then connected, linking port 0 to the tip of the earphone jack. Like this :

Great, our earphones are now connected!


What a strange tittle? LOL 😉 wait, you will understand. Let's open our Python code editor: mu editor.
To be able to play music, we have to use the music library and import it into our code.
import music
Then we will use this library to play a melody.
Let's test these 2 lines of code… So you see what is dadadadum now !!!!

The Micro:bit has a lot of music already programmed. Here is the list :


You can take the example code and change the melody. What is your favorite? How could you use these tunes, as signals or clues, in some of your games?

3. Be your own Mozart!

Now you can create your own melodies too! That's really cooool!

Musical notes

The Micro:bit is from England, it does not use “Do Ré Mi” but the letters of the alphabet to identify the musical notes whose A is the “La” of the tuning fork.

Do=C Re=D Mi=E Fa=F Sol=G La=A Si=B

For example, let's play a do:'C')

And the Octaves?

Octaves are indicated by a number. 0 is the lowest and 8 is about as high as you need, unless you do music for your dog. here find some examples:'C')'C1')'C5')

So, what is the default value? Did you guess?

Now the duration!

The note duration is also expressed using numbers.
The longer the value of the duration, the longer the note will be played. These values ​​are related to each other - a duration of 4 will last twice as long as a duration of 2 (and so on).'G:2')'G:2')'G:2')'E:4')


If you use the note named R (R for Rest or silence) then the Micro:bit will pause (silence) for the specified duration.'G:2')'G:2')'G:2')'E:4')'R')'F:2')'F:2')'F:2')'D:4')

A little flat note

Hmmm, there is a problem with the code above, right? It doesn’t sound right. It lacks alterations like sharp and flat. In code, how do we do it?

It's actually quite simple: a flat is indicated by b (lowercase) and a sharp by a #

How to correct this last note? Sharp or Flat? Try to find by yourself, before looking at the answer!!!'G:2')'G:2')'G:2')'Eb:4')'R')'F:2')'F:2')'F:2')'D:4')

Yes! It needed a Mi (or E) flat!

Another way to write all these notes is to make a list first:

tune = ["C4:4", "D4:4", "E4:4", "C4:4", "C4:4", "D4:4", "E4:4", "C4:4",

        "E4:4", "F4:4", "G4:8", "E4:4", "F4:4", "G4:8"]

Go ahead, write the rest of the song!

For example, you could write a pop song using a variable for each part. Then play them using a typical canvas of a song.

For example:


4.   Sound Effects

Python allows you to make sounds that are not musical notes. For example, here's how to create a police siren effect:

for x in range(5):   

    for freq in range(880, 1760, 16):

        music.pitch(freq, 6)

    for freq in range(1760, 880, -16):
        music.pitch(freq, 6)

First, like you don’t want to drive insane friends next to you, we decided to ring the siren only 5 times.
To do this, we used a for loop that will repeat the siren 5 times. This loop for that amounts to saying "for each element in a certain collection, do stuff with".

So here it's for each element in the range from 0 to 5. The loop goes through every number from 0 to 5, and then repeats itself 5 times (0, 1, 2, 3, 4 because it starts at 0 )
You can note how the music.pitch method is used in this example. It is waiting for a frequency, that is, a pitch of sound. For example, a frequency of 440 is the same as a note A (which corresponds to the LA) used to tune a symphony orchestra.

In the above example, the range function is used to generate an assortment of numeric values. The three arguments of the range function are the start value, the end value, and the step size. In this way, the first use of range is to say, "created an assortment of numbers between 880 and 1760 from 16 to 16". His second use says "created an assortment of numbers between 1760 and 880 from -16 to -16". This is how you get a list of frequencies that go up and down like a siren.
We also used another for loop. More precisely, in the example above it says "for each frequency in the frequency set, play the height of this frequency during 6 milliseconds". Note that things to do in this loop are indented (as we saw earlier) so that Python knows which code to execute with each element.

Go ahead now, change these loops and the values ​​used to make another known sound.


  1. Be very careful if your ninja's are using headphones or earpĥones because you cannot control the volume of the sound level from the micro:bit. To control the volume, you'll need some external circuitry or headphones or earphones with volume control.

    For show and tell we use a speaker (like the Sony SRS-XB10). You will need a stereo kabel (3,5 mm, male-male).

    We bought a micro:bit audio kabel (Kiwi Electronics). Makes changing earphones or speakers easier for our ninja's.

    Your siren doesn't make a continuous sound. There is an annoying "plop" switching off a tone and switching on the next tone.
    To get rid of this "plop", you can start the next tone before the current tone has ended. Like so:

    from music import pitch, set_tempo
    from microbit import sleep


    def siren():
    for x in range(5):
    for freq in range(880, 1760, 16):
    pitch(freq, 20, wait=False)
    for freq in range(1760, 880, -16):
    pitch(freq, 20, wait=False)


  2. <pre>
    from music import pitch, set_tempo
    from microbit import sleep


    def siren():
    for x in range(5):
    for freq in range(880, 1760, 16):
    pitch(freq, 20, wait=False)
    for freq in range(1760, 880, -16):
    pitch(freq, 20, wait=False)



Post a Comment