Introduction
Add a distance sensor to your micro:bit powered Xylophone and play songs by waving your hands or running around.
Tools
Parts
No parts specified.
Video Overview
Featured Document
-
-
If you haven't built a micro:bit powered Xylophone yet, start with our Xylophone guide.
-
If you want to check out another distance sensor project, or see more information on the sensor, see our Distance Display guide.
-
Once you have a working (micro:bit powered) Xylophone you can add your distance sensor.
-
-
-
If you've build the micro:bit powered Xylophone from our previous guide you'll have a row of 8 push buttons that were used to trigger the mallet to play notes.
-
We're going to remove the first button, that is connected to Pin 1 because we'll be using Pin 1 to connect our Ultrasonic Distance Sensor.
-
You can remove all the buttons if you want to do a full conversion (or just skip adding them when you build your Xylophone.)
-
If you already have buttons it's easy to keep them in place if you want to switch back to button control later.
-
-
-
Use the 4 jumper wires to connect the Ultrasonic Distance Sensor to the header pins on the Bit Board.
-
We found that a few rubber bands and LEGO bricks work well to hold our sensor in place pointing in the right direction. (Tape can also work.)
-
-
-
Connect a USB cable to the micro:bit and then plug it into your computer.
-
We'll be using makecode.microbit.org to program our board. It uses a simple drag and drop block interface.
-
We're going to load the following code for our Distance Xylophone program: https://makecode.microbit.org/_aAC0vX4Rp...
-
Remember that when the USB cable is plugged in it will power the micro:bit but not the servos for the Xylophone, so you'll need to add a battery pack before it works.
-
-
-
Once you've got your battery pack connected to the Bit Board you can test it out!
-
Try standing at least half a meter in front of the distance sensor and then walking slowly towards it (or just run fast if that's your style!)
-
Try standing out of the line of sight of the distance sensor and lowering your hand at different distances... can you play a song?
-