Overview
Can you send a ghost across the room without touching it? Let’s find out!
In this project you will learn how to send messages between two micro:bitThe micro:bit is a tiny programmable computer, about the size of a matchbox, made for learning to code. It has two buttons, a grid of little red LED lights and built-in sensors that can detect movement, light and temperature.Full entry → using Radio GroupA radio group is a number that works like a secret channel. Only micro:bits with the same radio group number can send messages to each other.Full entry →. You will write a While loopA while loop keeps repeating its instructions for as long as something stays true. The moment that thing stops being true, the loop stops.Full entry → that keeps checking for messages and shakes, and use an AccelerometerAn accelerometer is a tiny part inside the micro:bit that senses movement, like tilting, shaking or being turned over. It turns that movement into numbers your code can react to.Full entry → to notice when your micro:bit is shaken. When a message arrives, it gets stored in a VariableA variable is something that can change. Think of it like a labelled box: you pop something inside, and the label tells you what it is. You can swap what's inside whenever you like.Full entry →, and the code shows a ghost on the LED MatrixThe LED matrix is the grid of little red lights on the front of the micro:bit. By switching them on and off in patterns, your code can show numbers, letters and tiny pictures.Full entry →. Shake one micro:bit, and the ghost jumps to the other one!
Before you start, you’ll import the tools your code needs. Each step adds a little more to your ghost game, so take your time and test as you go.
What you'll learn
- How to connect two micro:bits using radio
- How to use an accelerometer to detect a shake
- How to use a while loop to keep checking for messages
- How to store a message in a variable
- How to show a picture on the LED Matrix
What you'll need
- 2 x micro:bit
- EduBlocks coding editor
- Micro USB cable
- 2 xBattery pack (optional)
Key words
Accelerometer
An accelerometer is a tiny part inside the micro:bit that senses movement, like tilting, shaking or being turned over. It turns that movement into numbers your code can react to.
Real-world example: A bit like the sensor in a games controller that knows when you tilt it to steer, the accelerometer notices when the micro:bit moves.
Importing Libraries
A library is a ready-made bundle of code that someone else has written for you. Importing a library means bringing it into your project so you can use all its ready-made commands and features, without building them from scratch.
Real-world example: It's like borrowing a recipe book from the library. Instead of working out every recipe yourself, you bring the book in and use the recipes whenever you need them.
micro:bit
The micro:bit is a tiny programmable computer, about the size of a matchbox, made for learning to code. It has two buttons, a grid of little red LED lights and built-in sensors that can detect movement, light and temperature.
Real-world example: A bit like a pocket-sized computer you can program yourself, a micro:bit can become a step counter, a thermometer or even a simple game.
LED Matrix
The LED matrix is the grid of little red lights on the front of the micro:bit. By switching them on and off in patterns, your code can show numbers, letters and tiny pictures.
Real-world example: Like a mini scoreboard made of dots, the LED matrix lights up to spell out your step count.
Radio Group
A radio group is a number that works like a secret channel. Only micro:bits with the same radio group number can send messages to each other.
Real-world example: It’s like two walkie-talkies agreeing to use channel 30, so they only hear each other.
Variable
A variable is something that can change. Think of it like a labelled box: you pop something inside, and the label tells you what it is. You can swap what's inside whenever you like.
Real-world example: A variable called score might start at 0, then change to 1, 2 and 3 as you collect points in a game.
While loop
A while loop keeps repeating its instructions for as long as something stays true. The moment that thing stops being true, the loop stops.
Real-world example: "While it's still raining, keep the umbrella up." As soon as the rain stops, you put the umbrella down, and the loop ends.
Navigating to the EduBlocks editor
First, let’s create a new EduBlocks project.
- Open your favourite web browser. We recommend either Google Chrome or Microsoft Edge.
- In the address bar, type app.edublocks.org.
- Select micro:bit under Create New Project.
- Name your project Spooky Signals, and make sure Blocks is selected under Type.
- Select Create to open the micro:bit code editor.
The EduBlocks micro:bit editor will now open.

EduBlocks lets you build Python code using colourful blocks. The blocks snap together and help you see how the finished Python code is organised.
Import the Tools
- Select Basic, then select Imports. Drag a
from microbit import *block under the# Start code hereblock. - Select Basic, then select Imports again. Drag an
import radioblock under thefrom microbit import *block.
Your starting code should look like this:

Turn On the Radio
- Select Radio, then drag a
radio.on()block under theimport radioblock. - Select Radio, then drag a
radio.config(group=23)block under theradio.on()block.
The radio group is like a secret channel. Both micro:bits need the same number to hear each other.

Note: If you are working with more than one pair of micro:bits, give each pair a different radio group number. Groups range from 1 to 255.
Create the While Loop
- Select Basic, then select Loops. Drag a
while True:block under theradio.config(group=23)block.
The code inside a while loop keeps running, so your micro:bit is always ready to check for messages and shakes.

Create the incoming Variable
- Select Variables, then select Create variable. Name it incoming.
- Select Variables, then drag an
incoming = 0block inside thewhile True:block. - Select Radio, then drag a
radio.receive()block onto the 0.
The incoming variable is a labelled box. It stores any message the micro:bit receives. If no message has arrived, the box stays empty.
Your code should look like this:

Show the Ghost When a Message Arrives
- Select Basic, then select Logic, then drag an
if True:block under theincoming = radio.receive()block. Keep it inside thewhile True:block. - Drag an incoming block onto the True part of the
ifblock. - Select Display, then drag a
display.show("Hello")block inside theif incoming:block. - Select Display, then drag an
Image.RABBITblock onto the word Hello. Change RABBIT to GHOST, so it readsImage.GHOST.

Send the Ghost When Shaken
- Select Basic, then select Logic. Drag another
if True:block under theif incoming:block. Make sure it lines up with theif incoming:block, and is not inside it. - Select Accelerometer, then drag an
accelerometer.was_gesture('shake')block onto the True part of the newifblock. - Select Display, then drag a
display.clear()block inside theif accelerometer.was_gesture('shake'):block. - Select Radio, then drag a
radio.send("Hello")block under thedisplay.clear()block. Change Hello to GHOST.
When you shake the micro:bit, the ghost clears from its screen, and the word GHOST is sent to the other micro:bit.

Download your code
Your spooky signals is ready to transfer to the micro:bit.
- Connect the micro:bit to your computer using the micro USB cable.
- In EduBlocks, select Connect.
- Follow the instructions on the screen to pair your micro:bit.
- If your browser asks for permission, choose the micro:bit from the list.
- Select Connect.
- Select Flash to send the code to the micro:bit.

If EduBlocks cannot find the micro:bit, try another USB cable. Some cables can only charge devices and cannot transfer code.
Test your Spooky Signals
Unplug both micro:bits from the computer, and plug in a battery pack for each one. Shake one micro:bit. Its ghost vanishes, and a ghost appears on the other micro:bit’s screen. Shake the other one to send the ghost back!
It’s like a game of supernatural catch. Grab a friend and have a go!
Try it yourself
Challenge: Ghost TimerHint: Inside the if incoming: block, after the display.show(Image.GHOST) block, add a sleep(3000) block from Basic. Then add a display.clear() block after it. Each 1000 is one second, so 3000 is three seconds.
Bonus: Can you make the ghost appear and vanish three times in a row? Try a for loop from Loops.
Good to know: If the ghost doesn’t vanish, check that the sleep block is inside the if incoming: block, and that you typed 3000, not 300.
Stuck? Quick fixes
| Problem | Try this |
|---|---|
| The ghost doesn’t appear on the other micro:bit | Make sure both micro:bits have the code, and that both use group 23. Keep them close together. |
| Shaking doesn’t send a ghost | Check that the second if block lines up with the if incoming: block, and sits inside the while True: block. |
| The Flash button doesn’t work | Select Connect first, choose the right micro:bit, then try Flash again. Use a data USB cable, not a charge-only one. |
| There’s an error message in red | Check your capital letters: Image.GHOST and radio.send("GHOST"). Make sure every word is in quotation marks. |
| Another pair’s ghost appears on your micro:bit | Give each pair a different radio group, such as 23 for one pair and 24 for another. |
Don’t worry if it doesn’t work first time. That’s how coding works! Check one block at a time and compare it with the pictures.
