Skip to main content

1.1

Major VersionM

by Pete Prodoehl

Introduction

Connect a Distance Sensor to a Bit Board and view the output using four LEDs.

Video Overview

Featured Document

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

    • Plug + (red) into VCC; S2 (orange) into TRIG; S1 (yellow) into ECHO; and - (black) into GND.

    • We'll use Maker Tape to connect the LEDs to the Bit Board on a LEGO baseplate.

    • Connect the Negative (-) side of each LED to a Ground (GND) hole on the Bit Board.

    • Connect the Positive (+) side of the LEDs as shown, so each LED connects to one of the following pins on the Bit Board: Pin 0, Pin 1, Pin 2, and Pin 3.

  2. 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. (It's the same one we use in our Bit Board Rover Kit).

  3. 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 Sensor LEDs Meter program: https://makecode.microbit.org/_ETgMiUYhL...

    • In the forever block we'll set Pin 14 and Pin 13 to TRIG and ECHO (respectively) so we can read the Distance Sensor. This allows us to continually read the sensor and assign the value to distance.

    • We first check if the distance is greater than 3. In testing we've found that trying to measure 3cm or less can be a bit tricky, so we ignore any distance under 4cm.

    • We then check the distance with a series of if/then statements to determine how many LEDs to light up.

    • Our lightUpLEDs function accepts four values, of either 0 or 1, and then uses those to determine which LEDs will be lit up.

    • The function passes these values directly to the digital write pin statements to control the LEDs.

    • In the if/then we start with our lowest value test (10) and if the distance is 10 or lower, we light up all four LEDs. If the distance is over 10 we move to the next test (15) and so on down the line.

    • 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) in front of the sensor. As you get closer more LEDs will light up.

Finish Line

Pete Prodoehl

Member since: 3/4/20

2,090 Reputation

449 Guides authored

0 Comments

Add Comment



View Statistics:

Past 24 Hours: 4

Past 7 Days: 4

Past 30 Days: 15

All Time: 15