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.

micro:bit Circuit

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.

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