Micro:bit – Sound and Light

In this project you will use the light sensor to control the sound coming out of the microbit. There are lots of things you can do with light and sound!

Connect your speaker using the diagram below

1. Create a burglar alarm

Make a light sensitive alarm. You could hide this in a drawer or box where you keep secret things. The alarm will go off if anyone lets light in!

Inside a forever loop, check the light level and play a sound if it is lighter than a certain level. The micro:bit light sensor goes from 0 (dark) to 255 (full brightness) so you will need to choose what brightness should trigger the alarm.

2. Create a theremin

A theremin is a musical instrument which is controlled without touching it. We will use brightness to change what note the microbit plays.
Every musical note has a frequency, which is measured in Hertz. The light sensor goes from 0 to 255, but the microbit can play notes from 131 to 988 Hertz, so we need to convert the brightness to Hertz.

First make a variable called note

Then use the Map block to convert the brightness to the frequency of the note you want to play

Finally, play the note

Now test your Theramin! You can change the note which is played by changing the brightness. Try covering the microbit with your hand, or shining a torch on it for extra brightness!

Download as PDF