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 Speed program: https://makecode.microbit.org/_Yda4DpiPt...

    • 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 first forever loop we read the distance sensor and assign the value to the delayTime variable, mapped from the distance sensor values 15cm to 5cm as 1ms to 30ms.

    • In our second forever loop we basically have two loops to make the servo sweep back and forth between angle 0 and angle 180, pausing between each 1 degree move by the amount of time assigned to delayTime.

    • 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 speed will decrease proportionally to how close the object is.

  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: 8

Past 30 Days: 8

All Time: 8