Introduction: Musical Instrument With Micro:bit

Hi. Today I'm going to show you how you can turn your BBC Micro:Bit into a musical instrument that reacts to the ambient light in the room. It's super simple and super fast, so follow these steps and start making some jams.

Step 1: Step 1: Get Your Parts

For this project, you are going to need 4 things
- A BBC Micro:Bit

-The MicroBit extender

-The Grove Speaker or any speaker compatible with microbit

-Computer and the USB wire to upload the code onto the Micro:Bit

After getting these parts you want to start setting it up.

Step 2: Step 2: Put the Micro:Bit Together

To create the contraption simply put one end of the connecting wire into the Grove speaker and the other end into the Microbit extender in p1-p14

Then plug your Micro:Bit into the extender and use the USB cable to tether the contraption into the laptop.

Follow the pictures and make it as I did

Step 3: Step 3: the Code

The code for this is really simple and only requires a couple of blocks
-First you need to get the forever block from the basic functions. Drag it into the workspace
-Next, go over to the music column, and grab the Ring tone (hz) and clip that into the forever block

-Now, head over to the math column, grab the map block, and clip it into the ring tone

-After you complete that, change the first low to 0 and the first high to 255, as it can only store 256 variables at one time. Change the second low to low c, by click on the number. A piano should appear. Click the leftmost key. Do the same for the second high, but this time click the rightmost key. You're almost done now!
-Last step: head over to input and drag light level into the workspace. Clip it into the box immediately next to map, and your code is complete!

Now you can download your code and drag the file from wherever you saved it into the Micro:Bit

Step 4: Step 4: How to Make It Work

This contraption works depending on the amount of ambient light in the room. The more light, the higher the pitch of the note that is produced. To make it fluctuate effectively, try using a torch/phone torch, as you can put a focused beam of light onto the sensor.

Step 5: Step 5: Other Uses

This could be used commercially to help visually impaired people play music, by configuring it to react differently to different colored light. By shining a different color, it could change the pitch of the note, and if you shine 2 colors it could harmonize and make a chord.

To see it work, click the link below

Thanks for following along. Have a nice day!