BBC micro:bit
What you’ll learn
- What’s on a BBC micro:bit
- How to program it with MakeCode blocks or Python
- How it’s used in robots
On the board
| Feature | Details |
|---|---|
| Display | 5 × 5 red LEDs |
| Inputs | Buttons A and B; on V2 also a touch-sensitive logo and a microphone |
| Sensors | Accelerometer, compass, light (via the LEDs), temperature |
| Outputs | LED display; on V2 a built-in speaker |
| Radio | micro:bit-to-micro:bit radio and Bluetooth |
| Connectors | Edge connector with pins 0, 1, 2, 3V and GND (more via a breakout) |
Programming it
- MakeCode: blocks, JavaScript or Python in the browser, with a built-in simulator.
- MicroPython: via the online Python editor at python.microbit.org.
- Download the program and copy it onto the micro:bit (it appears as a USB drive), or pair it with WebUSB from the browser.
In robots
Many robot car kits are built around the micro:bit: it plugs into a base board that has a motor driver, line sensors and an ultrasonic sensor. Its radio is great for remote control (one micro:bit as the controller, one in the robot).
Example: shake detector (MakeCode JavaScript)
input.onGesture(Gesture.Shake, function () { basic.showIcon(IconNames.Surprised)})Example: radio remote control
Controller:
radio.setGroup(7)input.onButtonPressed(Button.A, () => radio.sendString("L"))input.onButtonPressed(Button.B, () => radio.sendString("R"))Robot:
radio.setGroup(7)radio.onReceivedString(function (cmd) { basic.showString(cmd) // replace with motor commands for your robot kit})Try it
Runs on Microsoft MakeCode, free, no account needed.
DiceEasy
When shaken, show a random number from 1 to 6.
input.onGesture(Gesture.Shake, () => basic.showNumber(randint(1, 6)))
Spirit levelMedium
Show an arrow pointing to whichever side is lower, using the accelerometer’s x reading.
input.acceleration(Dimension.X) is negative when tilted one way and positive the other.
Night lightHard
Light all LEDs when the light level is below 30, and clear them otherwise.
Show an answer
basic.forever(function () { if (input.lightLevel() < 30) basic.showLeds(` # # # # # # # # # # # # # # # # # # # # # # # # #`) else basic.clearScreen()})Quick check
Finished this lesson?