Run a Micro Servo With Micro:bit
by hypergami in Circuits > Microcontrollers
6032 Views, 2 Favorites, 0 Comments
Run a Micro Servo With Micro:bit
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 micro servo motor. In order to power a stronger servo, you will need a different configuration with an external battery.
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.
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".
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.
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.
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.
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.