Introduction
Connect a Distance Sensor to a Bit Board and view the output using a NeoPixel Strip.
Video Overview
Featured Document
-
-
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.
-
-
-
We'll connect the NeoPixel Strip with a Crazy Circuits Ribbon Cable using just three of the wires.
-
Plug the three-wire connector of the Crazy Circuits Ribbon Cable into the row with Pin 1 on the Bit Board. The wire colors should match the pin header colors, with S1 (yellow) going to the yellow pin.
-
We do not need to plug in the S2 (orange) wire, so you can leave it disconnected.
-
To the NeoPixel Strip plug S1 (yellow) into IN; + (red) into VCC; and - (black) into GND.
-
(Again, we do not need to plug in the S2 (orange) wire, so you can leave it disconnected.)
-
You should now have the Distance Sensor and NeoPixel Strip connected to the Bit Board.
-
-
-
We used a 3D printed part we designed to hold the Distance Sensor and NeoPixel Strip 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 and Rover NeoPixel Beam Holder. (They're the same ones we use in our Bit Board Rover Kit).
-
-
-
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 NeoPixel Flashing program: https://makecode.microbit.org/_VPDbYeA2M...
-
In the on start block we'll set up our NeoPixel Strip and a variable called myLimit with a value of 20. We'll also create a variable named multiplier and set it to 10.
-
In our forever loop we'll check if the distance is lower than myLimit and if so we blink our NeoPixel Strip, first setting it to red, then setting it to black (or "off").
-
We'll pause between the blinking on and off for an amount of time that is determined by multiplying the distance by our multiplier.
-
This means as the distance becomes a smaller number (as you get closer) the rate of blinking will increase causing the NeoPixels to blink faster the closer you get to 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) in front of the sensor. When you are within 20cm of the sensor the NeoPixel Strip should start blinking and blink at a faster rate as you get closer to the sensor.
-
-
-
Follow along with our recorded Live Stream!
-
You can watch the full video of us walking through this project, along with explaining and exploring the code: Chapter 36 - Distance Sensor NeoPixel Strip
-
