Skip to main content

1.0

Major VersionM

by Pete Prodoehl

Introduction

Connect a Distance Sensor to a Bit Board and use it to control the output of a Piezo Speaker.

Video Overview

  1. 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.)
    • 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.

  2. 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.
    • 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.

  3. 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!)
    • 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.

  4. If you've never used a micro:bit before you'll want to check out this guide:  Bit Board V2 Setup and Use
    • 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 Alarm Icon program: https://makecode.microbit.org/_2gCYoACYr...

    • In the on start block we enable the LED matrix, set myLimit to 10, and set the volume to 127 (out of 255).

    • In our forever loop we'll check if the distance is less than myLimit, and if it is, the micro:bit will play the sound...

    • In this version we've also added the show icon command when the sound is played.

    • You'll notice that this slows down the response time of our program. When you move the object away from the sensor it will continue to play the sound (and show the icon) for another 600 milliseconds.

    • The show icon command adds a 600ms delay which can only be adjusted in the Python or JavaScript mode, not in the Block mode. (The show LEDs command adds 400ms.)

    • 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 10cm away the piezo will play a sound and show an icon.

    • When you move the object away from the sensor the sound will keep playing and the icon will keep displaying for an additional 600 milliseconds.

  5. Follow along with our recorded Live Stream!
    • Follow along with our recorded Live Stream!

    • (We'll add the video to this step after we do the stream!)

Finish Line

Pete Prodoehl

Member since: 3/4/20

2,290 Reputation

464 Guides authored

0 Comments

Add Comment



View Statistics:

Past 24 Hours: 0

Past 7 Days: 14

Past 30 Days: 14

All Time: 14