Introduction: Run a Mini Servo With Micro:bit

About: CU Boulder Craft Technology Lab, Institute of Cognitive Science, University of Colorado, Boulder.

This quick Instructable will show you how to program your BBC Micro:bit using the MakeCode editor to run a mini servo motor.

The directions for hooking your micro:bit to the motor are here: http://www.papermech.net/bbcmicrobit/

The basics of working with the MakeCode editor are here: https://microbit.org/code/

Start a new project in the MakeCode editor at: https://makecode.microbit.org/

WARNING: the micro:bit can only output a very small amount of power to a mini servo motor. In order to power a stronger motor, you will need a different configuration (Instructable coming soon).

Supplies

BBC Micro:bit, USB cable, mini servo motor, three alligator clips with pigtails (single prongs), or regular two-headed alligator clips with jumper wires. MakeCode editor in a web browser.

Step 1: Input Blocks

Under the Input menu, drag two button press blocks (the purple block at the top of the column) to the editor window. One should read "button A" and change the other to read "button B".

Step 2: Load the Servo Menu

Click the "Advanced" menu item, and then click on "Extensions". You will be taken to a screen with various functions that you can load into MakeCode. Select the "Servo" option. Once you select it, you will return to the MakeCode editor.

Step 3: Add Servo Controls

Now when you look at the menu column, you will see an option called "Servos". From that menu, drag the top block that says "set servo P0 angle to 90 degrees" into each purple "on button pressed" blocks in your editor space. You'll now see a servo added under the micro:bit picture to the left on the screen.

Step 4: Put in Servo Values

Change the settings in the green servo blocks to read 30 degrees for button A, and 180 degrees for button B. Now, if you click on buttons A or B on the simulator pictures on the left of the window, you should see the servo arm move.

Step 5: Download and Run

Download the code to your micro:bit. Now when you press button "A", the servo arm should move to 30 degrees, and pushing button "B" should move the arm to 180 degrees.