Make a Hello World DrawBot
Intro to BBC micro:bit and Microsoft MakeCode
Robot Basics
What is a robot? How is a regular vacuum different than a robot vacuum?
How do you make robots get along with people?
What are Kathy’s Rules of Robot Building?
Build the Robot
Materials
BBC micro:bit board with USB cable
1 servo (positional)
3 alligator clip-to-header pin wires
cups or cardboard for head and body
extra scrap corrugated cardboard, pipe cleaners, etc for pen holder
ruler
scissors (preferably pointy) or other cutting tool to make holes in cardboard
sharp pencil
washable marker
drawing paper
Turn the cup or container flat side up. Trace around the servo. Cut out a hole for the servo.
Cut a hole in the back of the cup (near the seam) big enough to pull the servo cable through from the inside.
Insert the servo into the hole on top, cable first. Pull the servo cable out through the hole in the back.
Use the materials you have to design and make a holder for the marker. Use a pencil to punch a hole for the pen. You may need to add a head to balance the weight of the pen when it is inserted in the holder.
Tape a servo horn to the bottom of the pen holder.
Meet the micro:bit and MakeCode
Easy Tilt DrawBot https://makecode.microbit.org/_TwE7ts3cD65A
Cut a holder for a marker from cardboard. Tape a servo horn onto the bottom with one arm facing front. Then poke a hole for the marker with a sharp pencil.
Press the servo horn onto the servo motor so the holder faces front.
Calibrate the servo so it faces front at neutral (90 degrees):
Gently turn the holder as far to the right as it will go.
Detach the holder and re-attach it so it faces directly right.
Gently turn the holder to face straight ahead again.
Make a head from a cup or cardboard and attach to the holder. (It helps with balance.)
Insert a marker into the holder. Gently turn the holder back and forth and adjust if needed.
Meet the Servo Motor
A positional servo motor can move 180 degrees from left to right. Keep your servo between 5 and 175, to avoid straining the tiny little motor.
Use colored alligator clips to connect the servo to a micro:bit board. It is VERY IMPORTANT to connect the wires correctly.
Plug connector wires into the servo cable, matching colors (or marking the wires).
Clip the connector wires to the micro:bit. IMPORTANT! Double-check colors are correct before you connect the board to power!
Black = ground: GND
Yellow = signal: 0 (Pin Zero/P0 )
Red = power: 3V
Plug the micro:bit into your computer and download your code!
As you write your code, start by moving the servo(s) a little way to the right or left. This will help you avoid jerking the arms around too far and damaging the cardboard or the electronics. If needed, increase the movement in small steps until you reach the amount you want.
Click on Extensions to add the Servo blocks to the list of menus.
Get a set servo angle to 90 block and insert it into the on start block. Ninety degrees is the servo’s neutral position.
From Input, grab the on shake block. Open the drop-down menu and choose tilt left.
Insert a set servo angle block into the tilt left block. Open the slider and set it a little to the right or left. After you download and test the program, you can adjust the setting.
Duplicate the tilt left stack of blocks. Change it to right tilt and change the servo setting to the opposite side.
Get a button A block from Input to use as a panic button that quickly sets the servo back to 90.
Download and test your code.
Troubleshooting Tip: Sometimes the servo tries to move when you play a sound. If that happens, change Pin 0 to Pin 1 wherever it appears in your code. (Pin 0 is also used for connecting a speaker to the micro:bit.) Be sure to move the alligator clip to the connector hole marked “1” as well.
Advanced Coding — Mapping Tilt to Turn
DrawBot Mapping code: https://makecode.microbit.org/_a4m27m8jyD9R
DrawBot Mapping Graph code: https://makecode.microbit.org/_hRA0TrDUy8HY
The map block in the MATH menu lets you match the low and high ends of one set of numbers to the low and high ends of another set of numbers. In this case, you want to match the tilt of the board between 0 and 1023 (all the way left and all the way right) to the servo’s position between 30 to 150 (a little to the left, and a little to the right). Here’s what to do:
In the on start block, set the servo to 90 degrees. Also add a sound to let you know the program is running.
Then go to the forever block and insert a servo block inside.
Next, grab a map block from the MATH menu. It’s oval shaped. Drag it over the white oval on the servo block that says 90. It should snap right in.
Go to Input and find an oval-shaped block that says acceleration (mg) x. Snap it over the first white oval on the map block. That tells the map block to measure the tilt from side to side (the “x” coordinates on a graph).
Now change the numbers in the white ovals on the rest of the map block. The first two numbers, 0 and 1023, stay the same. Over the third number, type 30, and for the fourth number, type 150. You can adjust these as you test your bot.
Use the on logo pressed or on Button A pressed to show the tilt reading on the micro:bit screen. (If you want, make Button B a “panic button” that sets the servo to 90 degrees when you press it.)
That’s it! Download and test out your code.
Extra: Double-click on any block to attach a comment. This is called documenting your code — it helps you (or the next person) figure out what the code you wrote is supposed to do.
Videos
(Note: These videos show Adafruit CIrcuit Playground Express microcontrollers, which are similar to the BBC micro:bit. The MakeCode blocks used are similar as well.)