Introduction
Connect a 270˚ Servo to a Bit Board and control it with a Pushbutton and code.
We'll explore using a momentary push button (and some code) to control the movement of a servo motor.
Video Overview
Featured Document
-
-
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 is closest to the number 13 for the Pin 13 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).
-
Connect the Button with Maker Tape, with one side to Pin 5 and the other to GND.
-
-
-
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 Servo Selector program: https://makecode.microbit.org/_Jg1e4DTfp...
-
When the button is pressed we'll repeat a loop 20 times where we set the angle of the servo to a random value between 30 and 150.
-
Remember that even though the servo is able to move 270 degrees we can only send values between 0 and 180, but we can shrink that scale as well to constrain it even more.
-
-
-
Once the code is loaded it should start running immediately, but the servo won't move until you press the button.
-
You can power the micro:bit via the USB cable you used to load the code, but now that we are using servos we recommend using a battery pack plugged into the Bit Board.
-
The Blue Pins on the Bit Board provide extra power (5 volts instead of 3 volts) by boosting the voltage coming from the battery pack. This helps improve servo performance, especially with multiple servos.
-
When the button is pressed the servo should make a number of moves and then on the 20th move it will stop moving.
-
This might be a good example for a game that needs to randomly select or point at something.
-
-
-
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: https://www.youtube.com/live/Og8T6cw5Ai0
-
