BBC micro:bit
Make Some Noise

Introduction

It has all been very quiet so far. Attaching a buzzer to the micro:bit will allow you to get your micro:bit to make some noise.

You will need a buzzer or speaker to do this. A buzzer might cost you less than 50p to buy from an online store. You need one that works with 3V3 logic. Most of the cheaper buzzers work with 2V-5V and are fine. One of these will look something like this,

Buzzer

Connecting

It has two metal pins at the bottom. One of the pins is labelled +. You connect this to pin 0 on your micro:bit. You can do this with the breadboard if you have the suitable connector. If not, use some alligator clips.

Connect the pin that is labelled - to GND.

Playing A Scale

In Physics, sound is a pressure wave travelling through air or water. The pitch of a sound that we hear is determined by the frequency of that wave. We can get the micro:bit to play musical notes through the buzzer or speaker if we specify the correct frequency for that note. Fortunately, the Code Editors have some tools to make this process easier.

With your buzzer connected, try some code like this,

micro:bit Code

This will play you the C Major Scale.

Musical Challenge

  1. You could get the micro:bit to play you any scale you choose. You could get it to scroll the name of the scale being played across the LED Matrix and then follow that with the buzzing. A more complex program could then be made with the buttons or accelerometer being used to allow a choice of scale.

More Notes

The blocks in the Block Editor only have notes covering a single octave. C4 is middle C.

If you want to play a complex tune, you'll need to be able to play notes outside of that range. Here is the same scale an octave higher. By entering the frequencies instead of a letter (pick up value block from the Maths section).

micro:bit Code

Here is a table of the approximate frequencies of musical notes. In the note names, the letters A-G are used for the notes. The number is the octave for the note, with 4 being the octave starting with middle C. The letter 'S' indicates a sharp. The note is a semitone higher than its note letter and semitone lower than the next note. This means each note with an S in the table is also a flat of the next note.

NoteHertzNoteHertzNoteHertz
C016C3131C61047
CS017CS3139CS61109
D018D3147D61175
DS019DS3156DS61245
E021E3165E61319
F022F3175F61397
FS023FS3185FS61480
G024G3196G61568
GS026GS3208GS61661
A027A3220A61760
AS029AS3233AS61865
B031B3247B61976
C133C4262C72093
CS135CS4277CS72217
D137D4294D72349
DS139DS4311DS72489
E141E4330E72637
F144F4349F72794
FS146FS4370FS72960
G149G4392G73136
GS152GS4415GS73322
A155A4440A73520
AS158AS4466AS73729
B162B4494B73951
C265C5523C84186
CS269CS5554CS84435
D273D5587D84699
DS278DS5622DS84978
E282E5659E85274
F287F5698F85588
FS292FS5740FS85920
G298G5784G86272
GS2104GS5831GS86645
A2110A5880A87040
AS2117AS5932AS87459
B2123B5988B87902

Tempo

The timings for the notes can be in milliseconds or, more handily if you want to play a tune, in beats. Setting the tempo in your script sets the length of a beat. Treat a crotchet as a quarter note and work out other note sizes based on that. Here is a small part of tune using this method.

micro:bit Code

Challenges

  1. There are lots of web sites that will let you look at free sheet music, particularly for traditional songs. If you are happy reading or decoding sheet music, then you can work out the notes you need from that. If not, you could try one of the sites that has free online 'courses' or tutorials in instruments like the recorder or the flute. They will have some short tunes that are easy to follow.
  2. You can use the random number generator to make noise. Rather than generate a number for the frequency, it is best to use IF statements and match the random number to a set of notes. Generate random numbers for the number of beats for the note too.
  3. Randomness, even if you choose from a small range of notes, tends not to sound too interesting or melodic. You can get something more pleasant if you add more control to the process. Start by reducing the computer's composition to a fixed number of bars of music, no more than 16 of them. Instead of choosing each note at random, write statements to generate a shorter sequence of notes. Think about the different ways you combine a handful of notes, increasing or decreasing the pitch towards the end of a sequence ending in a longer note. Use the randomness, but if you want the sequence of notes to progress upwards, make sure each note is never lower or more than one note lower than the previous.