BBC micro:bit
Noise Maker
Introduction
This page describes how to make a basic noise maker. This is a classic electronics and microcontroller project. You connect up a light dependent resistor and a buzzer. You get the buzzer to change pitch depending on the amount of light hitting the sensor.
Circuit
There are other ways to configure a light dependent resistor. This setup worked well for me. A speaker is shown where the buzzer is. Treat it the same way with whatever you are using to buzz and connect the - to GND and the + to pin 0.
Before you flash this program, press the REPL button. It is used to test that we get a number from our LDR that can be used easily with the buzzer. I had to multiply the reading by 2 to get a high enough frequency to pass to my buzzer. Depending on the amount of light and your component, you might get different readings.
from microbit import * while True: light = pin1.read_analog() light = light * 2 print (light) sleep(50)
This program adds the buzzing effect. You have to be pressing button A for the noise to be made. I like to have some way to stop the noise completely.
from microbit import * import music while True: if button_a.is_pressed(): light = pin1.read_analog() light = light * 2 print (light) music.pitch(light,-1) else: music.stop()
Challenges
You can change the behaviour of the noise maker by spending a bit more time thinking about the frequency that you want to play. Instead of just playing the raw frequency or some multiple of it as we have here, it would be good to play an actual note. You can do this by making a list of the note frequencies you want. Those are shown in the table at the bottom of this page.
The main programming task for this is to successfully choose a note to play based on the reading from the sensor. Arithmetic is your friend. Use the first example program and record all of the information you can about the readings you are getting. Choose your notes carefully. A couple of octaves works well, but you might find a more interesting scale to use.
When you crack the problem of getting the right note, start to think about features. You could go for a relatively small number of notes with button presses or other interactions changing the octave. You could work out how to bend the note.
Light show on the LED matrix to finish the whole project off nicely.
Note | Hertz | Note | Hertz | Note | Hertz |
---|---|---|---|---|---|
C0 | 16 | C3 | 131 | C6 | 1047 |
CS0 | 17 | CS3 | 139 | CS6 | 1109 |
D0 | 18 | D3 | 147 | D6 | 1175 |
DS0 | 19 | DS3 | 156 | DS6 | 1245 |
E0 | 21 | E3 | 165 | E6 | 1319 |
F0 | 22 | F3 | 175 | F6 | 1397 |
FS0 | 23 | FS3 | 185 | FS6 | 1480 |
G0 | 24 | G3 | 196 | G6 | 1568 |
GS0 | 26 | GS3 | 208 | GS6 | 1661 |
A0 | 27 | A3 | 220 | A6 | 1760 |
AS0 | 29 | AS3 | 233 | AS6 | 1865 |
B0 | 31 | B3 | 247 | B6 | 1976 |
C1 | 33 | C4 | 262 | C7 | 2093 |
CS1 | 35 | CS4 | 277 | CS7 | 2217 |
D1 | 37 | D4 | 294 | D7 | 2349 |
DS1 | 39 | DS4 | 311 | DS7 | 2489 |
E1 | 41 | E4 | 330 | E7 | 2637 |
F1 | 44 | F4 | 349 | F7 | 2794 |
FS1 | 46 | FS4 | 370 | FS7 | 2960 |
G1 | 49 | G4 | 392 | G7 | 3136 |
GS1 | 52 | GS4 | 415 | GS7 | 3322 |
A1 | 55 | A4 | 440 | A7 | 3520 |
AS1 | 58 | AS4 | 466 | AS7 | 3729 |
B1 | 62 | B4 | 494 | B7 | 3951 |
C2 | 65 | C5 | 523 | C8 | 4186 |
CS2 | 69 | CS5 | 554 | CS8 | 4435 |
D2 | 73 | D5 | 587 | D8 | 4699 |
DS2 | 78 | DS5 | 622 | DS8 | 4978 |
E2 | 82 | E5 | 659 | E8 | 5274 |
F2 | 87 | F5 | 698 | F8 | 5588 |
FS2 | 92 | FS5 | 740 | FS8 | 5920 |
G2 | 98 | G5 | 784 | G8 | 6272 |
GS2 | 104 | GS5 | 831 | GS8 | 6645 |
A2 | 110 | A5 | 880 | A8 | 7040 |
AS2 | 117 | AS5 | 932 | AS8 | 7459 |
B2 | 123 | B5 | 988 | B8 | 7902 |