Intermediate Micro:bit
Algorithms and ProgrammingCADDigital Literacy

Intermediate Micro:bit

Grades 5–12
4 hrs
8 steps
Groups of 20
NC SCOSNC CTEGrade 8

Standards Alignment

NC SCOS

Computer Science

  • HS-AP-03: Evaluate algorithms in terms of their efficiency, correctness, and clarity.
  • 68-AP-04: Construct programs that include events.
  • 35-CS-02: Model how computer hardware and software work together as a system to accomplish tasks.
  • 35-AP-05: Construct programs that implement conditionals.
  • 68-CS-02: Design projects that combine hardware and software components to collect and exchange data.
  • 68-AP-01: Implement flowcharts and/or pseudocode to address complex problems as algorithms.
  • HS-DA-02: Select appropriate data collection tools and techniques.
  • 68-DA-02: Collect data using computational tools.
  • 68-AP-03: Design and iteratively develop programs that combine control structures including nested loops and compound conditionals.
  • 35-AP-02: Create programs that use variables to store and modify data.
  • 35-AP-04: Construct programs using simple loops.

NC CTE

Cyber Foundations II (2025)

  • 10.1.b: Identify and explain the functions of various physical computing devices, including microcontrollers and sensors.

Showing 12 of 27 standards.

Lesson Steps

1

Compass North

30 min

Step 1: Make it

 

What is it?

This simple compass will show you which way is North.

 

micro:bit showing N for North on LED display next to compass pointing North

 

How it works

  • Your micro:bit has a compass sensor called a magnetometer that measures magnetic fields. It can sense the Earth’s magnetic field and so you can use it as a compass.
  • When you first use the micro:bit compass you have to calibrate it. A little game appears on the screen where you have to tilt the micro:bit to light up every LED, then you’re ready to go.
  • The program uses an infinite (forever) loop to keep taking compass readings and it stores them in a variable called ‘bearing’. It then uses selection: an if… else statement to show N for North on the LED display ifthe bearing is greater (>) than 315 degrees or less than (<) 45. This means that it will show you where North is as long as your micro:bit is pointing in roughly the right direction.

 

What you need

  • micro:bit (or MakeCode simulator)
  • MakeCode or Python editor
  • battery pack (optional)
  • a planet with magnetic poles to stand on, such as Earth!

 

Step 2: Code it

 

MakeCode

 

Python

1from microbit import *
2compass.calibrate()
3
4while True:
5    bearing = compass.heading()
6    if bearing < 45 or bearing > 315:
7        display.show('N')
8    else:
9        display.show(' ')
10

 

Open in Classroom

Open in Python

Download HEX

Open in MakeCode

 

Step 3: Improve it

  • Make the compass more accurate by reducing the range of bearings: make the number 45 smaller and 315 bigger.
  • Add other points of the compass to show when the micro:bit is pointing East, West and South.
  • Add sound so it makes a noise when pointing North so someone who is visually impaired can use the compass.

 

Compass rose showing numerical bearings for N, S, E, W, NE, SW etc

2

Make Some Noise

30 min

Step 1: Make it

 

What is it?

Attach headphones to your micro:bit and make music!

 

diagram showing tip of headphone plug connected to micro:bit pin 0 and the long part of headphone plug connected to GND on micro:bit

 

How it works

  • To make sounds with micro:bit, attach headphones or a speaker. Clip the tip of the headphone plug to pin 0 on micro:bit. Clip the longer part of the headphone plug to the GND pin on micro:bit.
  • Use this program to make your micro:bit play one of its built-in tunes when you press button A.
  • The gold pins on the bottom of the micro:bit are used for inputs and outputs. Here we use pin 0 as an output. The micro:bit sends pulses of electrical signals from pin 0 when it plays the tune. The headphones must also be connected to the GND pin on the micro:bit to complete the electrical circuit.

 

What you need

  • micro:bit (or MakeCode simulator)
  • MakeCode or Python editor
  • battery pack (optional)
  • a pair of headphones, buzzer or amplified loudspeaker
  • two crocodile clip leads

 

Step 2: Code it

 

MakeCode

 

 

Python

 

1from microbit import *
2import music
3
4while True:
5    if button_a.was_pressed():
6        music.play(music.NYAN)
7

 

Open in Python

Open in Classroom

Open in MakeCode

Download HEX

 

Step 3: Improve it

  • Try different tunes like ODE, BLUES or BIRTHDAY. You can find a list of tunes you can use in Python here.
  • Make the tune repeat more than once using a loop.
  • What happens if you connect pin 0 to the middle part of the headphone plug instead of the tip?
3

Tell Me a Secret

30 min

Step 1: Make it

 

What is it?

Use micro:bit’s radio feature to answer questions in secret.

 

Two people sharing secrets using micro:bit radio

 

How it works

  • Flash this program on to two micro:bits. You and a friend ask each other questions that have ‘yes’ or ‘no’ as the answer.
  • Press input button A to send ‘yes’ and button B to send ‘no’ messages. A tick or cross will flash on both micro:bits’ LED display outputs for half a second.
  • The program uses radio to send your answer secretly - no-one (except your partner) can hear the radio signal.
  • When a radio message is received, the program uses selection to test the message: if the received message is equal to ‘yes’, then it shows a tick on the LED display, but if the message is equal to ‘no’ then it shows a cross.
  • Make sure the radio group number is the same on both micro:bits – you can use any number between 0 and 255.
  • If lots of you are using this program in the same place, you’ll want to make sure each pair of people has their own radio group number.
  • Keep your radio group number a secret if you don't want anyone snooping on your messages!

 

What you need

  • Two micro:bits (or MakeCode simulator)
  • MakeCode or Python editor
  • battery pack (optional)
  • a friend and a secret to share!

 

Step 2: Code it

 

MakeCode

 

 

Python

from microbit import *
2import radio
3radio.config(group=7)
4radio.on()
5
6while True:
7    message = radio.receive()
8    if message:
9        if message == 'yes':
10            display.show(Image.YES)
11            sleep(500)
12            display.clear()
13        elif message == 'no':
14            display.show(Image.NO)
15            sleep(500)
16            display.clear()
17    if button_a.was_pressed():
18        radio.send('yes')
19        display.show(Image.YES)
20        sleep(500)
21        display.clear()
22    if button_b.was_pressed():
23        radio.send('no')
24        display.show(Image.NO)
25        sleep(500)
26        display.clear()
27

 

Open in Python

Open in Classroom

Open in MakeCode

Download HEX

 

Step 3: Improve it

  • Show different icons or messages for ‘yes’ and ‘no’.
  • Use shake, tilt or buttons A and B together to send different answers such as ‘maybe.’
  • Change ‘yes’ and ‘no’ to ‘dot’ and ‘dash’ and send Morse code messages.
4

Treasure Hunt

30 min

Step 1: Make it

 

What is it?

Use several micro:bits to make a physical treasure hunt game using radio communication.

 

A micro:bit and a treasure map

 

How it works

  • Like the Heartbeat beacon project, this uses two different programs, one to transmit radio signals, and another to receive the signals.
  • Flash the beacon (transmitter) program onto different micro:bits, making sure you change the number in the id variable so each one is different. The beacons briefly show their ID number on the display, so you know which is which. Attach battery packs and then hide the beacons which transmit their ID number every 200 milliseconds (0.2 seconds).
  • Flash the receiver code on to micro:bits for the treasure hunters. This program can be the same for all receivers. When you approach a beacon, the receiver program shows the ID number it’s broadcasting. The display will blink when you are further away and become steady as you get closer.
  • Make your own rules for the game – note the numbers down and where you found them, or collect the physical micro:bit beacons. Team with the most wins.

 

What you need

  • Several micro:bits and battery packs
  • MakeCode or Python editor
  • a reasonably large space to hide beacons in – it could be indoors or outdoors

 

Step 2: Code it

 

Beacon / transmitter

 

MakeCode

 

 

Python

 

from microbit import *
2import radio
3radio.config(group=1, power=1)
4radio.on()
5id = '1' # change this number for each beacon
6display.show(id)
7sleep(2000)
8display.clear()
9
10while True:
11    radio.send(id)
12    sleep(200)
13

 

 

Open in Python

Open in Classroom

Open in MakeCode

Download HEX

 

Receiver

 

MakeCode

 

 

Python

from microbit import *
2import radio
3radio.config(group=1)
4radio.on()
5
6while True:
7    message = radio.receive()
8    if message:
9        display.show(message)
10        sleep(200)
11        display.clear()
12

 

Open in Python

Open in Classroom

Open in MakeCode

Download HEX

 

Step 3: Improve it

  • Change the transmitter power to cover a larger or smaller area. The power can be any number from 0 to 7.
  • Further reduce the radio power of the beacons making them hard to find – be careful not to place the micro:bits directly in any metal containers, but if you put one in a cardboard or plastic box and then partially cover the outside of the box in tin foil, for example, the radio signals will not travel as far.
  • Transmitting radio signals uses more power, so you could make the beacon batteries last longer by increasing the delay between transmissions to more than 200 milliseconds.
5

Simple Door Alarm

30 min

Step 1: Make it

 

What is it?

 

Has anyone been in your room? With a micro:bit, a battery pack and a magnet you can make an alarm to alert you to sneaky snoopers...

 

Introduction

 

Coding guide

 

How it works

  • In this project you'll make a door alarm that works just like a real door sensor in a home security system.
  • Your micro:bit has a built-in compass sensor called a magnetometer. You can use it to measure the Earth’s magnetic field as a compass - or to sense how strong magnetic fields are much closer to home!
  • Fix a magnet in the corner of a door and a micro:bit with the door alarm program close to it on the door frame like in the video.
  • The program uses the micro:bit’s compass (magnetometer) input sensor and a forever loop to keep measuring the strength of the magnetic field.
  • It uses selection so when it falls below a certain level (the threshold), it shows an angry face on the LED display. This means the magnet moved away from the micro:bit - when the door was opened - so someone may have been in your room!
  • Pressing button A shows the current magnetic force reading. Use this to decide what threshold number to use by taking readings with the door open and closed. We used 200 in our example, but this depends on how strong your magnet is and if there are any other magnetic fields nearby. The coding video above shows you how to do this.
  • Press button A to clear the angry face and reset the alarm.

 

What you need

  • a micro:bit
  • MakeCode online code editor
  • battery pack
  • magnet
  • some way of fixing the magnet, micro:bit and battery pack to the door and door frame

 

Step 2: Code it

 

MakeCode

 

 

Python

# Python uses nanoteslas to measure magnetism.
2# Experiment with different numbers depending on the
3# strength of your magnet, which you can read by 
4# pressing button A.
5
6from microbit import *
7
8while True:
9    if button_a.was_pressed():
10        display.scroll(compass.get_field_strength())
11    if compass.get_field_strength() < 200000:
12        display.show(Image.ANGRY)

 

Open in Python

Open in Classroom

Open in MakeCode

Download HEX

 

Step 3: Improve it

  • Add a speaker and an audible alarm
  • Use a variable to count the number of times your door has been opened - you'll need to add code to sense when it's been opened and closed
  • Create a timer to measure how long a door has been left open

 

6

Micro:bit Pet

30 min

Step 1: Make it

 

What is it?

Code your own electronic pet and customise it to make it your own. The micro:bit's built-in speaker makes it even more fun with its expressive sounds.

 

Introduction

 

Coding guide

 

What you'll learn

  • How to use variables and loops to make a simple timer.
  • How to use selection to make different events happen at different times.
  • A trick to make it appear as if a micro:bit program has stopped running!

 

How it works

  • Electronic pets were invented in Japan in the 1990s and soon became a popular toy all over the world.
  • They’re small gadgets that you can keep on your keyring. A creature is shown on a simple display. You have to look after it, interacting with it by pressing buttons and playing simple games. If you ignore it and don’t feed or clean it, it will get sad, misbehave or become unwell.
  • The code uses a variable called timer to keep track of how long your pet has been ignored. A forever loop adds 1 to the timer every 1 second (1000 milliseconds).
  • If timer reaches 20, your pet shows a sad face on the LED display and makes a sad sound on the built-in speaker outputs.
  • If it reaches 30, your pet falls asleep.
  • If it gets to 40 your pet plays a mysterious sound and dies. The code uses the 'set built-in speaker off' block to stop any other sounds coming out of the speaker. A 'while true' loop makes sure only the skull icon is shown on the LED display.
  • Your pet will stay alive and happy if you interact with it, however! Stroke the logo to make it happy, or shake it to make it giggle. This resets the timer back to 0.
  • If your pet dies you can bring it back to life by pressing the reset button on the back of your micro:bit.

 

What you need

  • V2 micro:bit with sound (or MakeCode simulator)
  • MakeCode or Python editor
  • battery pack (optional)

 

Step 2: Code it

 

MakeCode

 

 

 

Python

from microbit import *
2import audio
3
4timer = 0
5display.show(Image(
6    "00000:"
7    "09090:"
8    "00000:"
9    "09990:"
10    "00000"))
11audio.play(Sound.HELLO)
12
13while True:
14    if pin_logo.is_touched():
15        timer = 0
16        display.show(Image.HAPPY)
17        audio.play(Sound.HAPPY)
18    elif accelerometer.was_gesture('shake'):
19        timer = 0
20        display.show(Image.SURPRISED)
21        audio.play(Sound.GIGGLE)
22    else:
23        sleep(500)
24        timer += 0.5
25        # sleep for half a second only to make it react more quickly to logo touch & shake
26        
27    if timer == 20:
28        display.show(Image.SAD)
29        audio.play(Sound.SAD)
30    elif timer == 30:
31        display.show(Image.ASLEEP)
32        audio.play(Sound.YAWN)
33    elif timer == 40:
34        display.show(Image.SKULL)
35        audio.play(Sound.MYSTERIOUS)
36        break
37    

 

 

Open in Python

Open in Classroom

Open in MakeCode

Download HEX

 

Step 3: Improve it

  • Experiment with different times for each stage of its life.
  • Create your own facial expressions using the micro:bit's LED display.
  • Add more variables to track how hungry or dirty your pet is, and add new interactions to feed or clean your pet, for example by pressing buttons or making a loud sound picked up by the micro:bit's built-in microphone.
7

Environment Data Logger

30 min

Step 1: Make it

 

What is it?

Discover the best places to grow plants by using your BBC micro:bit to study light levels and temperatures over several hours or days.

 

Introduction

 

Coding guide

 

 

What you need

  • a micro:bit V2
  • a computer and micro USB cable for coding the micro:bit and viewing your data
  • micro:bit battery pack (optional but recommended)
  • our data logging guide may be useful

 

Gather data

  • Flash the program below onto your micro:bit.
  • Disconnect it from your computer, attach a battery pack and put the micro:bit where you'd like to study temperature and light levels.
  • Transferring a new program to your micro:bit will erase any previous data logs, but you can also delete old data by pressing buttons A and B together. Having one set of data with continuous timestamps makes it easier to view later.
  • Press button A to start logging. A tick (or check mark) will appear on the LED display. It will now record data every 1 minute (60,000 milliseconds). You can change this interval by modifying the 'every' block in the code. A heart flashes on the LED display to show when data is being recorded.
  • In the unlikely event the log becomes full, the code lets you know by lighting all the LEDs on the display.
  • Press button B to stop logging. You'll see an 'X' appear to show it has stopped.

 

Analyse your data

  • Disconnect the battery pack and plug the micro:bit back into a computer. The micro:bit appears like a USB drive called MICROBIT. Look in the MICROBIT drive and open the MY_DATA file to see a table of your data in a web browser:

 

 

The MICROBIT drive as it appears in Windows

How to find your data on the MICROBIT drive

 

The MY_DATA file as it appears when you open it in a web browser

Your data appears in a table in a web browser

 

  • The time stamps in the log represent the amount of time that has passed since your micro:bit was powered on. If you log more than one set of data without clearing the log, you may not be able to see the visual preview of the data you want to study, so it’s a good idea to delete the previously stored log before starting a new experiment.
  • Click on Visual preview to see a graph of your data:

 

Graph showing light and temperature data

 

  • You can isolate individual lines by clicking on their labels. Light readings may vary between 0 and 255, but temperatures are likely to vary in a smaller range. Here we can see changes in temperature more clearly by viewing its line on its own:

 

Showing only the temperature line on the graph

 

  • You can also click on the Copy button and then paste your data into a spreadsheet.

 

Step 2: Code it

 

MakeCode

 

 

Open in Classroom

Open in MakeCode

Download HEX

 

Step 3: Improve it

  • Record data over a longer period of time, such as once an hour for several days.
  • Run the experiment in different places and compare your data.
  • Create a report based on your findings to help people make decisions about where plants will grow best.
  • You could user this project to study patterns of electric light and heating use and use the data to suggest ways of saving energy.
  • Modify the code to study noise levels over time using the microphone.
8

Hot Potato Game

30 min

Step 1: Make it

 

What is it?

Turn your micro:bit into a ‘hot potato’ by coding it to become a random timer. To play the game, pass the ‘micro:bit potato’ on to the next person before the timer goes off.

 

 

 

How to play it

Press button A and pass the ‘hot potato micro:bit’ around a circle of players. If it makes the sad sound and turns to a cross while you are holding it, then you are out. The last person left is the winner.

 

How it works

This project uses button A as in input to start a series of events.

First the ‘timer’ variable is set to a random number between 5 and 15, and a chessboard image appears on the LEDs.

Then the ‘timer’ variable starts counting down, changing by –1, once a second, until it gets to 0.

The 'while loop' helps us shorten the code. While the ‘timer’ variable is above zero, the section of code counting down keeps repeating, but as soon as the ‘timer’ variable reaches zero, the loop stops.

Put the code on a micro:bit and attach a battery pack to turn it into a ‘hot potato micro:bit’.

 

What you need

  • micro:bit (or MakeCode simulator)
  • MakeCode or Python editor
  • battery pack

 

Step 2: Code it

 

MakeCode

 

Python

from microbit import *
2import music, random
3
4while True:
5    if button_a.is_pressed():
6        timer = random.randint(5, 15)
7        display.show(Image.CHESSBOARD)
8        while timer > 0:
9            timer -= 1
10            sleep(1000)
11        display.show(Image.NO)
12        music.play(music.WAWAWAWAA, wait=False)
13        audio.play(Sound.SAD)
14        

 

Open in Python

Open in Classroom

Open in MakeCode

Download HEX

 

Step 3: Improve it

  • Change the duration of the timer to suit different tasks or change from random to a specific length of time.
  • Modify the program so a different icon or your own picture appears when you press button A.
  • Change the sound to a happy/positive sound to indicate when someone has ‘won’ something.
  • Use it in different contexts, for examples, to practise spellings or times tables, or use as a class countdown.

Materials

  • Micro:bit Club Pack (10x) — 2 per classroom

Related Supply Kit

Micro:bit Pack

All the hands-on materials you need for this lesson, delivered to your classroom.

More robotics lessons

Ready to bring this lesson to your classroom?

Sign up to save this lesson, order supplies, and track student progress.