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 a 270 Degree Servo.

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. The 270 Degree Servo Motor has a 3-wire connector on the end that can plug directly into the pins on the back of the Bit Board. Make sure the Orange Wire from the servo is closest to the number 15 for the Pin 15 column. Then the Brown Wire should be closest to the micro:bit (in the - row) and the Red Wire will be in the middle (the +5v row).
    • The 270 Degree Servo Motor has a 3-wire connector on the end that can plug directly into the pins on the back of the Bit Board.

    • Make sure the Orange Wire from the servo is closest to the number 15 for the Pin 15 column.

    • Then the Brown Wire should be closest to the micro:bit (in the - row) and the Red Wire will be in the middle (the +5v row).

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

    • The bottom of the servo is "Brick Compatible" and can snap right onto a LEGO baseplate.

    • 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 Servo Angles program: https://makecode.microbit.org/_fJpf10AMP...

    • In the on start block we disable the LED matrix. (In this case we don't need to, but we tend to disable it if we are not specifically using it.)

    • We also assign digital pin P15 to a variable named servoPin.

    • In our forever loop we read the distance sensor and assign the value to the distance variable and then check if the distance is lower than 5, and if it is not, check if it is lower than 10, and if it is not, check if it is lower than 15.

    • For each of those if/else if checks we'll set the servoAngle to a specified angle if the comparison is true. At the end of the block we'll use servo write pin to move the servo.

    • You'll notice we used the constrain function when reading the distance sensor. This will ensure we never get a value lower than 1 or higher than 20.

    • 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. The servo will move to one of three positions depending on how close the object is to the sensor.

  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,240 Reputation

460 Guides authored

0 Comments

Add Comment



View Statistics:

Past 24 Hours: 0

Past 7 Days: 11

Past 30 Days: 11

All Time: 11