Introduction
Connect a Distance Sensor to a Bit Board and use it to control the output of a Piezo Speaker.
Video Overview
-
-
We'll connect the Distance Sensor with a Crazy Circuits Ribbon Cable using all four wires.
-
Plug the three-wire connector of the Crazy Circuits Ribbon Cable into the row with Pin 13 on the Bit Board. The wire colors should match the pin header colors, with S1 (yellow) going to the yellow pin.
-
Next, plug S2 (orange) into Pin 14. (S2 is separated from the three-wire connector to allow you to plug it into another row.)
-
To the Distance Sensor plug + (red) into VCC; S2 (orange) into TRIG; S1 (yellow) into ECHO; and - (black) into GND.
-
-
-
For this guide we'll use the built-in piezo speaker found on the micro:bit V2.
-
If you prefer to connect a Crazy Circuits Piezo Speaker take a look at Chapter 13 for notes on connecting one and adding code to use it.
-
-
-
We used a 3D printed part we designed to hold the Distance Sensor in place on the LEGO baseplate.
-
A few Technic pins, a Technic beam, and some LEGO bricks are all that is needed.
-
Alternately you can use some LEGO bricks and a rubber band or tape to hold the sensor in place. (But don't use anything conductive!)
-
3D print your own Distance Sensor Holder with Holes.
-
-
-
If you've never used a micro:bit before you'll want to check out this guide: Bit Board V2 Setup and Use
-
We're going to load the following code for our Distance Piezo Theremin program: https://makecode.microbit.org/_3y9Fhz9ss...
-
In the on start block we'll disable the LED matrix, set myLimit to 20, and set the volume to 127 (out of 255).
-
In our forever loop we'll read the distance sensor and assign the value to a variable named distance.
-
We'll then use map function to take the value of distance and map it from a scale of 20 to 1 onto a scale of 988 to 131, then assign that to a variable named pitch.
-
In the if/then block we'll check if distance is less than myLimit and if so, play the sound at the pitch which we've calculated based on the distance of an object from the sensor.
-
-
-
Once the code is loaded it should start running immediately.
-
You can power the micro:bit via the USB cable you used to load the code or you can use a battery pack plugged into the Bit Board.
-
Move your hand (or a flat object) close to the sensor. If the object is less than 20cm away the piezo will play a sound and the pitch will change based on the distance of the object.
-
Congratulations! You now have a low-tech theremin!
-
-
-
Follow along with our recorded Live Stream!
-
(We'll add the video to this step after we do the stream!)
-
