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 create 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 on shake function
- 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 →, else if and else statements
- 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 → numbers
- How to show patterns 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 →
What you'll need
- The micro:bit MakeCode editor
- micro:bit
- micro USB cable
- battery pack for the micro:bit (optional)
Key words
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.
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.
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.
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.
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.
Navigating to the MakeCode Editor
On a Computer
- Open your favourite web browser. We recommend either Google Chrome or Microsoft Edge.
- In the Address bar type makecode.microbit.org.
- Select New Project and give it the name RockPaperScissors.

On a Tablet or Phone
- Open the micro:bit app. If you don't have the app yet you can download it from your devices app store by searching for micro:bit.
- Select Create Code.
- Select New Project and name it RockPaperScissors.
Set up the Code Area
- Select the
on startblock and drop it on the bin icon to delete it. - Select the
foreverblock and drop it on the bin icon to delete it. - Select Input. Select a
on shakeblock and drop it within the code area.

Create and Set choice Variable
- Select Variables, choose Make a Variable, and name it choice.
- Snap a
set choice toblock inside theon shakeblock. - Select Math. Select a
pick random 0 to 10block and snap it onto theset choice toblock where it says 0. Change 10 to 2.
Everytime the micro:bit is shaken it will choose a number between 0 and 2.

Creating the if Condition
- Select Logic. Select an
If true then elseblock and snap it below theset choice to pick random 0 to 2block. - Select Logic. Select a
0 = 0block and snap it onto theifblock where it says true. - Select Variables. Select a
choiceblock and snap it onto theifblock before the = sign. - Select Basic. Select a
show ledsblock and snap it inside theif choice = 0block. - Make the following pattern by selecting the squares to represent paper.

This piece of code will check to see if choice is equal to zero and if it is it will display the paper icon 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 →.

Create the else Condition
- Select Basic. Select a
show ledsblock and snap it inside theelseblock. - Create the following pattern by selecting the squares to represent rock.

For now the else block is the catch-all: if choice isn't 0, it displays the rock icon on the LED matrix. In the next step we'll add an else if branch for choice = 1, which leaves the else handling the last value, 2.

Create the else if Condition
Select the + below else.

- Select Logic. Select a
0 = 0block and snap it onto theelse ifblock where it says false. - Select Variables. Select a
choiceblock and snap it onto theelse ifblock before the = sign. Change the 0 to 1. - Select Basic. Select a
show ledsblock and snap it inside theelse if choice = 1block. - Create the following pattern by selecting the squares to represent scissors.

This piece of code checks to see if choice is equal to 1. If it is, it displays the scissors icon to the LED matrix.

Downloading Your Code
Using a Computer
- Select the three dots next to Download.
- Select Connect Device.
- A pop-up will show you how to connect the micro:bit to the computer. Keep following the on-screen instructions.
- Select BBC micro:bit XXX and select Connect. The XXX is your own micro:bit's name, so don't worry if it looks a little different.
- Select Download.

Using a tablet or phone
- Select Download.
- Follow the on-screen instructions to pair the micro:bit with the micro:bit app.
Once you've finished the on-screen steps, your code downloads to your micro:bit.
Run it and Watch
Shake the micro:bit to see either a rock, paper, or scissors icon display on your micro:bit. Remember the choice is random, so you may have to shake it a few times to see all three icons.
Don't have a micro:bit? We can test it on the MakeCode editor by selecting the white dot next to Shake on the micro:bit Simulator and watch it select the rock, paper, or scissors icon and display it on the virtual LED matrix.
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 a play tone block from Music inside your on shake block, just after you set the choice. For an extra challenge, play a different note 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 on 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 show leds block and check you've selected the right squares for rock, paper and scissors. |
| It only ever shows two icons | Check your else if is set to choice = 1, and that pick random goes from 0 to 2 (not 0 to 10). |
| My code won't download to the micro:bit | Use a data USB cable (not a charge-only one), make sure the micro:bit is paired, and try a different USB port. |