Micro:bit can be programmed using Block Coding, Python, or JavaScript. Learn more about each coding method below and try examples!
Block Coding with MakeCode provides a beginner-friendly way to program the Micro:bit using a drag-and-drop interface. Students can use pre-built blocks to control Micro:bit's features without needing to write code. It’s ideal for students new to coding.
Lights up LEDs on the Micro:bit’s 5x5 grid in patterns.
show leds block
Detects when button A or B is pressed and triggers an action.
on button A pressed block
Detects the movement and tilting of the Micro:bit.
on shake block
Detects the direction the Micro:bit is facing.
on compass heading
Enables wireless communication between Micro:bits.
radio send number block
Control an LED pattern with button presses and shake detection.
on button A pressed -> turn on LEDs in heart shape | shake -> show random number
Python allows students to control the Micro:bit using written code. It’s more flexible than block coding and provides deeper control of Micro:bit’s features. Python is great for students transitioning from visual to text-based programming.
Scrolls a message across the Micro:bit's LED display.
from microbit import *\ndisplay.scroll('Hello!')
Checks if button A is pressed and displays an icon.
if button_a.is_pressed():\n display.show('A')
Detects shaking or tilting of the Micro:bit.
if accelerometer.was_gesture('shake'):\n display.show('S')
Detects the direction the Micro:bit is facing.
compass.calibrate()\nheading = compass.heading()
Reads the current temperature from the sensor.
temperature = temperature()\ndisplay.scroll(temperature)
Program Micro:bit to show the temperature when button A is pressed:
from microbit import *\nif button_a.is_pressed():\n display.scroll(temperature())
JavaScript is another text-based option for coding the Micro:bit. It’s a great step for students familiar with block coding who want to transition to more advanced, text-based programming.
Turns on LEDs on the Micro:bit’s display in a heart pattern.
basic.showLeds(\n`# . . . #`\n)`
Detects button presses and triggers an action.
input.onButtonPressed(Button.A, function () {\n basic.showIcon(IconNames.Happy)\n})
Detects shaking or tilting of the Micro:bit.
input.onGesture(Gesture.Shake, function () {\n basic.showString("Shake!")\n})
Detects the direction the Micro:bit is facing.
let heading = input.compassHeading()\nbasic.showNumber(heading)
Reads the temperature and displays it on the LED screen.
let temp = input.temperature()\nbasic.showNumber(temp)
Program the Micro:bit to detect button A press and show a smiley face:
input.onButtonPressed(Button.A, function () {\n basic.showIcon(IconNames.Happy)\n})