Overview
In this project you will learn how to code your 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 → to play rock, paper, scissors using gestures and 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 →. We will start by understanding the basic game logic and how to present rock, paper, and scissors on the LED matrix. You will discover how to use RandomRandom means you can't guess what's coming next, a bit like rolling a dice. The computer picks for you, so you get a different surprise each time.Full entry → selection for the micro:bit's choice and show it on the LED matrix, so players can see what the micro:bit picked and work out whether they have won. Through this project you will develop fundamental coding concepts like 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 →, conditionals and random numbers while creating something fun and interactive. By the end you will have a fully functional game that you can play with friends or challenge the micro:bit yourself.
What you'll learn
- How to Importing LibrariesA 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.Full entry →
- How to use 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 →
- How to create and use 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 →
- How to use the 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 →
- How to display your own images 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 →
- How to use If statementAn if statement checks whether something is true, and only runs its instructions when it is. It's how code makes decisions.Full entry →, elif and else statements
- How to use Comparison OperatorsA comparison operator checks how two things measure up, for example whether they are equal or one is bigger than the other. It gives back a simple true or false answer.Full entry →
- How to RandomRandom means you can't guess what's coming next, a bit like rolling a dice. The computer picks for you, so you get a different surprise each time.Full entry → choices
What you'll need
- The micro:bit EduBlocks editor
- micro:bit
- micro USB cable
- battery pack for the micro:bit (optional)
Key words
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.
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.
If statement
An if statement checks whether something is true, and only runs its instructions when it is. It's how code makes decisions.
Real-world example: "If it's cold, put on a coat." If it's warm, you skip the coat, the action only happens when the check is true.
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.
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.
Comparison Operators
A comparison operator checks how two things measure up, for example whether they are equal or one is bigger than the other. It gives back a simple true or false answer.
Real-world example: Asking "is 6 == 6?" gives back true, but "is 6 == 2?" gives back false, so your code knows whether the two numbers match.
Random
Random means you can't guess what's coming next, a bit like rolling a dice. The computer picks for you, so you get a different surprise each time.
Real-world example: Asking a computer for a random number between 1 and 6 is just like rolling a dice, you never know if you'll get a 1 or a 6.
Set up your micro:bit EduBlocks Editor
- Open your web browser. We recommend Google Chrome or Microsoft Edge.
- In the address bar type app.edublocks.org.
- Under Create New Project, select micro:bit. Name your project Rock Paper Scissors, and make sure block is selected under type.

- Select Create to open the micro:bit editor.

Importing MicroPython libraries
- Select Basic, select Imports. Select
from microbit import *and snap it to the# Start code hereblock. - Select Basic, select Imports, select an
import randomblock and snap it to thefrom microbit import *block.
This Importing LibrariesA 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.Full entry → that we need to create our game.

Create a While Loop
Select Basic, select Loops. Select a while True: block and snap it to the import random block.
This creates a loop that goes around and around forever.

Create the Paper Variable
- Select Variables. Select Create Variable and name it paper.
- Select a
paper = 0block and snap it within thewhile Trueblock. - Select Display. Select an
Imageblock and snap it onto thepaper =block where it says 0. - Create the following pattern within the
Imageblock. A 9 means the LED is turned on and a 0 means the LED is off.

Here is the code so far:

Create the Rock Variable
- Select Variables. Select Create variable and name it rock.
- Select a
rock = 0block and snap it below thepaper = Image ("99999:", "90009:", "90009:", "90009:", "99999")block. - Select Display. Select an
Imageblock and snap it onto therock =block where it says 0. - Create the following pattern within the
Imageblock.

Completed code so far:

Create the Scissors Variable
- Select Variables. Select Create Variable and name it scissors.
- Select a
scissors = 0block and snap it below therock = Image ("00000:", "09990:", "09990:", "09990:", "00000")block. - Select Display. Select an
Imageblock and snap it onto thescissors =block where it says 0. - Create the following pattern within the
Imageblock.

Completed code so far with the scissors variable added.

Check for a Shake
- Select Basic, select Logic, select an
if True:block and snap it to thescissors = Image ("90099:", "09099:", "00900:", "09099:", "90099")block. - Select Accelerometer. Select an
accelerometer.was_gesture ("shake")block and snap it onto theifblock where it says True. - Select Variables, select Create Variable and name it choice. Select a
choice = 0block and snap it inside theif accelerometer.was_gesture ("shake"):block. - Within the 0 of the
choiceblock type random.randint(0, 2)
This will check to see if the micro:bit has been shaken and if it had it will set choice to a random number between 0 and 2.

Create the If Condition
- Select Basic, select Logic, select an
if True:block and snap it to thechoice = random.randint(0, 2)block. - Select Basic, select Logic, select a
0 == 0block and snap it on to theifblock where it says True. - Select Variables. Select a
choiceblock and snap it onto theifblock before the == sign. - Select Display. Select a
display.show(10)block and snap it inside theif choice == 0:block. - Select Variables. Select a
paperblock and snap it onto thedisplay.showblock where it says 10.
This will check to see if choice is equal to 0 and if it is paper will be displayed on the LED matrix.

Create the elif Condition
- Select Basic, select Logic. Select an
elif True:block and snap it to theif choice == 0:block. - Select Basic, select Logic. Select a
0 == 0block and snap it onto theelifblock where it says True. Change the 0 to 1. - Select Display. Select a
display.show(10)block and snap it into theelif choice == 1:block. - Select Variables. Select a
rockblock and snap it onto thedisplay.showblock where it says 10.
This will check to see if choice is equal to 1 and if it is rock will be displayed on the LED matrix.

Create the Else Condition
- Select Basic, select Logic. Select an
else:block and snap it to theelif choice == 1:block. - Select Display. Select a
display.show(10)block and snap it inside theelse:block. - Select Variables. Select a
scissorsblock and snap it onto thedisplay.showblock where it says 10.
This will display scissors on the LED matrix if choice does not equal 0 or 1.

Downloading the Code
- Connect the micro:bit to the computer with the micro USB cable.
- Select Connect and follow the on-screen prompts to pair the micro:bit with your web browser.
- Select Download to send the code to your micro:bit.
Run it and Watch
In the web browser
EduBlocks has a built-in micro:bit simulator, handy if you haven't got a micro:bit to hand.
- On the right-hand side of the screen, select Simulator.
- From the accelerometer menu below the simulator, select Shake.
- Select Send. This simulates a shake of the micro:bit and you will see a rock, paper, or scissors icon display on the LED matrix.

On a real micro:bit
Once the code has downloaded, give the micro:bit a shake and see an icon display on the LED matrix. Why not find a friend and see who can beat the micro:bit?
Try it yourself
Challenge: Can you add a sound so your micro:bit gives a little beep each time it makes a choice? Try snapping an audio.play(Sound.HAPPY) block from Audio inside your if accelerometer.was_gesture("shake"): check, just after you set the choice. For an extra challenge, pick a different sound for rock, paper and scissors!
Good to know: the sound plays through the built-in speaker, which only the micro:bit V2 has. If you have a V1, you can still try this challenge by clipping a buzzer or headphones to the pins. Everything else in this project works happily on both V1 and V2.
Stuck? Quick fixes
| Problem | Try this |
|---|---|
| Nothing happens when I shake it | Give it a firm shake, not too gentle. Also check your blocks are snapped inside the if accelerometer.was_gesture("shake"): block. |
| The same icon keeps showing | That's normal! The choice is random, so shake a few more times and the others will appear. |
| My icons look wrong or blank | Open each Image block and check you've selected the right squares for rock, paper and scissors. |
| It only ever shows two icons | Check your elif is set to choice == 1, and that random.randint goes from 0 to 2. |
| It won't download to my micro:bit | Make sure the micro:bit is plugged in with the USB cable, then try Connect again. |