Samsung and Micro:bit
Learn to code anywhere, any time
Computer code is at the heart of loads of things now – computers, TVs, phones, even fridges! It’s the instructions that make them do what they do. The great thing is, anyone can do it, you just need a few simple tools.
Samsung has partnered with the micro:bit foundation to provide school children across the UK with their very own mini computer, the micro:bit. Every Year 7 child will receive one for free in the UK. This tiny device makes coding easier than ever before, especially when you add in Samsung’s powerful micro:bit app. The app lets you code anywhere you want – at home, on the bus, or even in the playground – by pairing your Android phone and the micro:bit!
Introducing Team micro:bit
The best way to learn how to code is through doing. Don’t worry about what happens – if you get stuck, we’ve got our very own experts on hand. Dot, Jax and Dot’s mum Kate are ‘Team micro:bit’, and they’re here to help.
Select a character below to get to know them.
Close
Team Leader
Name    Dorothy (only my mum calls me that!)
Age    11 years old
Best at    Thinking up fun new games for micro:bit
Favourite food    Pizza topped with cheese and broccoli
When I grow up    Astronaut
Idol    Valentina Tereshkova (Google her now!)
Close
Deputy
Name    Jackson
Age    11 years old
Best at    Finding cool new ways to use micro:bit with a phone
Favourite food    Spicy fish fajitas
When I grow up    World famous rock star
Idol    Pharrell Williams
Close
Support guru
Name    Kate (Dot's mum)
Age    38 years old
Best at    Solving those unexpected little coding hiccups
Favourite food    Sushi (though a hot buttered crumpet’s great too!)
When I grow up    Winning gardener at the Chelsea Flower Show (never too late to dream!)
Idol    Nigella Lawson
Close
Secret genius
Name    Meow
Age    Meow?!
Best at    Meow.
Favourite food    MEOW!
When I grow up    Purr?
Idol    ...Meow.
Discover
What is programming?
Read more
What is an algorithm?
Read more
What is coding?
Read more
Why is coding important?
Read more
Getting started
Read more
What is Bluetooth?
Read more
Micro:bit app interface
Read more
Sequencing
Basic Coding Concepts
Read more
Repetition
Basic Coding Concepts
Read more
Variables
Basic Coding Concepts
Read more
Selection
Basic Coding Concepts
Read more
Boolean logic
Basic Coding Concepts
Read more
Input/Output
Basic Coding Concepts
Read more
Control
Basic Coding Concepts
Read more
Further reading
Read more
What is programming?
Close
Previous
Next
Although computers are incredibly powerful, they’re not what we’d normally think of as ‘intelligent’. Instead, a computer works by simply following the sequence of instructions given to it, in the order given. We need to give a computer the correct instructions, in the right order, so that it can successfully do what we want it to.
Essentially, any game, app or electronic device you use will have been programmed to do what it needs to do. Programming can be broken down into two stages: algorithms and coding.
What is an algorithm?
Close
Previous
Next
Firstly, we decide exactly what the computer will do by creating a set of steps for it – otherwise known as an algorithm. It’s really just like a cooking recipe. In fact, a recipe is actually an algorithm! Algorithms describe the steps that a computer would need to follow in order to complete a task. An algorithm can be created in a natural language (like English) or through a flow chart.
What is coding?
Close
Previous
Next
Once an algorithm has been developed, it needs to be given to the computer in a language it will understand. This is called coding. There are many languages available, each with their own advantages and disadvantages. You might have heard of some of them already - HTML (the building blocks of most websites), C++, Javascript and Python. The language you’ll be using in the app to code your micro:bit is called Touch Develop – if you’ve used micro:bit already, you’ll be familiar with it.
Why is coding important?
Close
Previous
Next
Computers aren’t just another name for your laptop or desktop PC – they’re in your mobile phone, your washing machine and cooker – even your fridge! They’re what make these devices intelligent.
Pretty soon, all these devices will be able to connect together (in fact, some of them already do), as part of the growing Internet of Things. As the objects in our lives become smarter and communicate with each other more, knowing how to make the most of them will in turn make coding as important as reading or writing. This doesn’t mean that you’ll have to become a professional programmer though! Instead, children will naturally learn how to make things with digital technology, in just the same way they learn to write a great story at school.
From scientists to artists, teachers to musicians – there’s something in coding for everyone. And by learning to code, you’re also learning to become logical thinkers and problem solvers. By working together and collaborating to code micro:bit, you’re well on your way to creating all sorts of great things.
Getting started
Close
Previous
Next
micro:bit has been designed to get you into coding as soon as possible, but if it’s your first time using it you’ll probably need a little hand getting things set up. Check out our short videos for more info on how to start coding with micro:bit:
Meet your micro:bit
Discover the Touch Develop editor
What is Bluetooth?
Close
Previous
Next
Bluetooth is a technology for wirelessly connecting devices over short distances, sending and receiving data between them.
Bluetooth can be used to connect a keyboard and mouse to your computer, or to send music from your phone to your headphones. Most modern games consoles also use Bluetooth for their wireless controllers.
Because Bluetooth connects devices over small distances, it doesn't use as much power as wifi, and can be powered using small batteries - or even solar power. This means that Bluetooth connectivity can be added to almost anything. Bluetooth socks that let you know if you are running incorrectly, helping you avoid injury.
Your micro:bit includes a Bluetooth Low Energy chip – an even more efficient version of Bluetooth, which lets your micro:bit and Android device ‘talk’ to one another, sending code from the app to micro:bit, and letting the micro:bit ‘tell’ your device when to follow the instructions of your code (e.g. by taking a photo or playing a sound).
Micro:bit app interface
Close
Previous
Next
Samsung has developed the official Android app for the micro:bit app to be simple and easy to use. When you use it for the first time, it will guide you through the process of pairing your device and micro:bit together. You can also register multiple micro:bits by assigning unique names to each computer.
• Home screen
This is the Home screen - the first thing you’ll see after loading the micro:bit app. From here, you can pair devices in the ‘Connections’ setting, upload code to your micro:bit through ‘Flash’, start editing your own programs in ‘Create Code’, or find out more projects and activities in ‘Discover’.
• Connections screen
The ‘Connections’ setting lets you pair a new micro:bit to your Android device, as well as adjust settings for any previously connected devices. You can even name each micro:bit individually, so that your whole family can code from one app without affecting each others personal micro:bits.
• Flash screen
The ‘Flash’ menu lets you select previously saved scripts and upload them to your micro:bit – you’ll need to do this every time you want to try out a new code on your device. You can also delete scripts from here.
• Menu screen
You can access the app’s menu at any time by tapping ‘Menu’ in the upper left corner. The menu frame will then appear. From here you can learn more about the app, read help guides, send feedback and check over technical documents on Privacy, Cookies and Terms & Conditions.
Sequencing
Close
Previous
Next
A computer will complete the instructions given to it, in the order that they are given.
Like making a cup of tea, there will be times when the order of instructions doesn’t really matter (like adding the sugar before or after the hot water), and times when it does (for example, boiling the kettle before pouring the water into your mug).
Just as with making tea or following a recipe, the order of instructions in a computer program can be important. When writing code to draw a shape , the following instructions will produce a triangle:
However, if we swap around those same instructions, we’ll get a very different result:
Our ‘Hide and Seek’ project introduces the concept of sequencing instructions in a specific order.
Repetition
Close
Previous
Next
Repetition simply means repeating (or looping) one or more instructions multiple times, or until a certain ‘condition’ (like a specific event) has been met. Here’s some code that draws a square:
It clearly works, but there are a lot of repeated instructions. This would become even more apparent if you were to try and draw an 8 or 20-sided shape! We can actually save time coding by instructing our computer to repeat a smaller set of instructions multiple times, like so:
This code will draw the same shape as the code above. In a computer game, repetition may be used to add multiple enemies at once, or to repeatedly play the game until the player runs out of lives.
Our ‘Shining Star’ project introduces the concept of repetition.
Variables
Close
Previous
Next
A computer’s memory is split up into millions of individual locations for storing data. Each memory location can be thought of as a box, inside of which is a single piece of information (data) that the computer can look at when needed. We can give a memory location a name, and then use the name to retrieve the data.
For example, a social network might store a user’s name, so that it can give them a personalised greeting when they log in:
The code used to personalise this greeting might look something like this:
Our ‘Thank you selfie’ project introduces the concept of variables.
Selection
Close
Previous
Next
There will be times when you don’t want the computer to do exactly the same thing every time. Instead, you can program the computer to choose which instruction to follow next based on, say, the value of some data stored in a variable.
At the end of a computer game, you might want to give the player a personalised message, based on their score. ‘if’ and ‘else’ statements can be used, in order to tell the computer to display the appropriate message:
Our ‘Last one standing’ project introduces the concept of selection.
Boolean logic
Close
Previous
Next
A boolean expression (statement) is one that evaluates to either True or False. For example, the expression:
evaluates to True, because it is true that 12 is greater than 7. Conversely,
evaluates to False, because it is not true that 5 is greater than 9.
Computers can use Boolean expressions to decide what to do next, or to repeat code until a certain condition is met. A quiz program could contain this code:
In this quiz, the player is asked questions until they have no lives left. At the start of the game, the player may have 3 lives. As 3 > 0 evaluates to True, the user is asked another question. Once all lives have been used, lives > 0 can only be False, and so the game will end.
Boolean logic (AND and OR) can be used to create more complex expressions, like these:
A login program that only allows access if the correct username AND password are entered:
A game might award 50 points for collecting either a red OR yellow object, but only 10 points for objects of any other colour:
Our ‘Steady Hand’ project introduces the concept of Boolean logic.
Input/Output
Close
Previous
Next
Input is data given to a computer through what we call ‘input devices’. A keyboard, mouse, microphone or temperature sensor are all input devices.
Output is data presented from a computer, through ‘output devices’ like your computer’s monitor, speaker or printer.
As you’ve probably already guessed, it’s the input and output devices of your computer that make it useful, as without them it would be unable to interact with the world around it.
Control
Close
Previous
Next
Control involves writing programs that affect the world around us. For example, a thermostat that turns on or off depending on the room temperature, or a remote controlled car that moves when buttons on its controller are pressed.
Control systems respond to an input, which is then processed by a computer program to produce an output. In the remote controlled car example, the input is through buttons on the controller , with the output being movement through the use of motors attached to the car’s wheels.
Further reading
Close
Previous
Next
Transforming learning
An exploration into how teaching and learning with 1:1 devices is changing the way teachers and pupils interact.
Future Skills
Discover how 361 teachers in 21 schools explored how the daily use of technology in schools can prepare students for future employment.
The Tech Partnership
Lots of research on the use of mobile device in classrooms and how it can help learning.
Child e-safety
More than forty organisations helped create this advice by the UK Council for Child Internet Safety ('UKCCIS'), including the Child Exploitation and Online Protection, the Department of Education, Department of Culture Media and Sport, the Home Office, the Office of Communications, the London School of Economics and more.
What’s next for Internet of Things
Journalist David Phelan gives us a glimpse into the exciting new frontier of the Internet of Things. Discover his thoughts on what amazing developments we can expect.
Touch Develop
Learn about the Touch Develop editor.
Parents
Download the
Discover Tips PDF
Get all the info you need on micro:bit, the app, and all the concepts behind our great projects in one place – ready for you to print.
Download PDF
Projects
Last one standing
It’s game time for Team micro:bit! Gather round in a circle and pass the micro:bit to learn your fate.
Coding concept explored
Selection
Shining star
Work with Jax to make a shining star animation on your micro:bit!
Coding concept explored
REPETITION
Steady hand game
See if mum can keep her nerve with a micro:bit in hand. Create an obstacle course in the garden to make it even harder!
Coding concept explored
BOOLEAN LOGIC
Hide and seek
Team micro:bit has come up with another game! Hide a phone and buzz it with micro:bit. See who can find it the quickest!
Coding concept explored
Sequencing
Thank you selfie
Jax received a great birthday gift from Dot, so he’s making her a hi-tech thank you message with micro:bit.
Coding concept explored
Variables
Get out of my room!
With micro:bit’s motion sensor, we made a trigger for a camera to capture Dot’s secret invader!
Coding concept
Control
Last one standing
Close
Previous
Next
Dot here! I’ve come up with a fun new game you can play together with your micro:bit, just in time for Jax’s birthday party. It’s my very own code-master spin on ‘Pass the Parcel’, with the micro:bit as a parcel. Except this parcel can decide for itself whether you’re passing it on...or dropping out!
Here’s how to play
1. Get the players to stand in a circle.
2. Give the micro:bit to the youngest player.
3. The player presses the A button on the micro:bit to determine their fate.
4. A left or right arrow means pass the micro:bit in that direction but a cross means you’re OUT!
5. You must sit down and pass the micro:bit in the direction it was moving (or right at the beginning of the game.)
6. Last one standing is the winner.
Psst...
Before you start coding, make sure you’ve installed and signed into the micro:bit app. You should also connect your phone or tablet to your micro:bit.
For instructions on how to do this, check out our guide in the ‘Discover’ section.
Once you’ve completed these steps, you should see your connected micro:bit on the app home screen.
For this project you’ll also need to connect the battery pack to your micro:bit so you can use it away from your computer.
Download as PDF
Download
...Let’s get started
Task One 
Random Fate
When a player presses the ‘A’ button you need to randomly select one of the fates: pass left, pass right or out. To do this you’ll need to generate a random number when the ‘A’ button is pressed.
Step 1
Create a new TouchDevelop script and name it ‘Last One Standing’
Step 2
A player’s fate is decided when they tap the ‘A’ button on the micro:bit. The micro:bit needs to detect when the button is pressed.
Tap inside your main function, and then tap input followed by on button pressed. Oh, and make sure you choose on button pressed - not the similarly named button is pressed!
At the moment, your code should look like this:
Step 3
A player’s fate will be one of three options: pass left, pass right and out. You’ll need the micro:bit to generate a random number and decide their fate.
First, create a fate variable to store the random number in.
Tap add code here, between do and end. The code you place here will run when a player presses the A button on the micro:bit.
Tap var and then change the name of the variable from x to fate.
Step 4
Touch Develop already provides a random number function for us - so use that to select the fate.
Tap after the := and then tap math followed by random.
Step 5
Change the input to random from 2 to 3. Random will then return one of 3 values: 0, 1 or 2.
Your code should now look like this:
Step 6
So you’ve generated a random number, but you can’t see what it is yet. Let’s add some code to show it on the screen so that you can test your code:
Tap the var fate line of code and tap the ‘+’ below it to add a new line.
Tap basic then show number, then tap backspace to delete the 0 and then tap fate to use the value of fate as the number to display.
Your code should now look like this right now:
Step 7
Now tap ‘run main’ to test your code. Each time you tap the ‘A’ button you should see a random number from 0 to 2.
Remember, sometimes the display won’t seem to change - don’t worry though, it is. It’s just because the random number is the same as the previous one!
Step 8
Now, delete the show number line of code - we only needed it for testing.
Tap on the show number line and then tap ‘cut’ to delete the line.
Your code should now look like this:
Task Two 
Show the Fate
When button A is pressed the micro:bit will now generate a random number (0, 1 or 2) and store it in the fate variable.
Now you need to display the fate to the players using the LEDs on your micro:bit. The random numbers correspond to the following fates:
0: pass left - display left arrow
1: pass right - display right arrow
2: out - display cross
To display the correct fate, you’ll need to use a decision...
You can use selection to choose which instruction your micro:bit should follow next.
You’re going to use if/else statements to decide which code to run depending on the value in the fate variable.
Step 1
Let’s write the ‘pass left’ fate first. This happens when the fate variable has the value 0.
Tap the ‘+’ below the var fate := random (3) line in your script to create a new blank line. Then tap if to make a decision and an if/then/else block will appear:
Now you need to add the condition to check that the fate is equal to 0.
Tap fate then ‘=’ (not ‘:=’, just ‘=’). Then tap 123 and choose 0
Your code should look like this:
Step 2
Now let’s create an image for ‘pass left’!
Tap add code here inside the if statement. This code will run when ‘fate = 0’.
You could repeat the previous image with a highlight here
Tap basic then plot leds:
Tap dots to create an arrow pointing left. Then tap OK. Nicely done!
Your code should look like this:
Step 3
Now, let’s do the same for the ‘pass right’ option.
Tap ‘add code here’ after the else then tap if. Set the condition to fate = 1.
You could repeat the previous image with a highlight here
Tap add code here below your new condition and plot your LEDs to make an arrow pointing to the right, just like before:
Your code should look like this:
Step 4
Now it’s just the final option we need - OUT!
Tap ‘add code here’ after the else.
You could repeat the previous image with a highlight here
There’s no need to check a condition this time, if fate isn’t 0 or 1 then it must be 2 and the player is out.
Add the code to plot a cross:
Your code should look like this:
Step 5
Tap ‘run main’ to test your code. Each time you tap button A one of the images should be shown. Remember, just like when we tested the numbers, sometimes it will be the same image as the turn before.
Task Three 
Add a Clear Screen and Pause
Excellent, you’ve got a working game! But we can make it even better. Let’s make it obvious that the micro:bit has selected a fate even if it’s the same as the one from the previous turn.
We can program our game to clear the screen and pause before showing the fate when a player presses the A button.
Step 1
Tap on the ‘var fate := math -> random(3)’ line and tap the ‘+’ above it to create a space to add new code before choosing the fate.
Add a basic -> clear screen line of code.
Step 2
Add another blank line after clear screen.
Tap basic and then pause to add a delay after clearing the screen. The delay is in milliseconds. Change the value to 1000 to pause for one second before displaying the fate. You can choose a shorter or longer pause if you like.
Your code should look like this:
Step 3
Now test your game again by tapping ‘run main’ and then pressing the A key.
It should be super-clear that the micro:bit has updated the fate after each button press! Now, it really feels like a complete game.
Step 4
Try changing the pause number to create a shorter or longer pause and see which you prefer.
Try it out
You can now transfer your script to your micro:bit. Tap ‘compile’ to download a compiled .hex file that you can transfer to your micro:bit.
In the micro:bit app tap ‘Flash’, then tap the arrow and ‘Flash’ to transfer your script onto your micro:bit.
You should see a message telling you that your script is being transferred.
Challenge One: Add a Forfeit Fate
Let’s make the game even more interesting!
Add a forfeit fate which displays a letter F when randomly selected. The person who passed the micro:bit to the current player gets to choose a forfeit (this is where the fun begins!).
If they complete the forfeit they get to stay in the game and pass the micro:bit on in the direction it was going (or right at the beginning of the game.) The forfeit could be anything from an exercise (“ten push ups, pronto!”), telling a joke or a game of dare!
Hint: This time you’ll need one of 4 random numbers to be selected (0, 1, 2, 3)
Challenge Two: Add a Cheat Mode
Add a cheat mode that only you know about! When it’s your turn tap button ‘B’ instead of ‘A’ (just don’t let anyone see what you’re doing!) and have the micro:bit just choose from the pass left and pass right options.
Project information
micro:bit features used:
Button input, LED Display
Android device features used:
None
Coding concepts covered:
Variables, selection (if, else), conditions, random number generation
Additional equipment needed:
Android device if using micro:bit app, Battery pack with batteries
Shining star
Close
Previous
Next
Hey, Jax here! Cloudy sky tonight? No problem! In this project, we’ll be using the micro:bit’s LED interface to create our very own, fully animated, Shining Star to light up the night sky! As well as discovering how to code the Star, you’ll also learn some of the basics behind frame-by-frame animation.
How it works
1. We’ll create our first star image by coding the micro:bit to light up certain LEDs in its display.
2. We’ll then create a second, brighter star in the same way.
3. By looping them, we’ll get a starry animation.
4. All we need to do then is decide where to place our star!
Psst...
Before you start coding, make sure you’ve installed and signed into the micro:bit app. You should also connect your phone or tablet to your micro:bit.
For instructions on how to do this, check out our guide in the ‘Discover’ section.
Once you’ve completed these steps, you should see your connected micro:bit on the app home screen.
For this project you’ll also need to connect the battery pack to your micro:bit so you can use it away from your computer.
Download as PDF
Download
...Let’s get started
Task One 
Creating your Star
Step 1
First things first - in the app, tap ‘Create Code’ and create a new Touch Develop script called ‘Shining Star’.
Step 2
Let’s start by creating your first star image. Tap inside your script’s main function, and then tap basic followed by plot leds.
Step 3
Tap the center LED (row 2, column 2) to create your star image (don’t worry, it’s going to get bigger later on!), and tap ‘OK’.
Step 4
This is how your code should look right now:
Step 5
Click ‘run main’ to test your project - your star should be showing on your micro:bit now (not bad, right?). Just tap the ‘’ button to get back to your script.
Task Two 
Shining Star
Step 1
So far your animation only has one image - but now you know how to make one, let’s add more and get that star really shining! Tap your plot leds code, and then tap the ‘+’ underneath your code to create a blank line.
Step 2
Tap basic followed by plot leds to create the second image of your shining star. We’ll start to expand the star out to show that it’s shining (and not just a dot in the sky!):
Step 3
Now, you’ll want to pause your script after each image is displayed so that you have time to see them. Tap the ‘+’ underneath the code displaying your first star image to add more code.
Step 4
Tap basic and then pause to pause your script. You can also choose how many milliseconds to pause your script for. 1000ms is 1 second, so a 200ms pause is ⅕ second.
Step 5
Tap the ‘run main’ button to test out your code again. Your single star should shine brightly. Tap the ‘’ button to get back to your script.
Task Three 
Creating an Animation Loop
Now you have an animation, but the images are only shown once. You can repeatedly show your two images, one after the other, by using repetition.
Repetition simply means repeating (or looping) one or more instructions multiple times.
Step 1
Tap the ‘+’ underneath your code to create a blank line.
Step 2
The loop you’ll need to use is a while loop. A while loop will repeat the code inside it as long as a condition is true. Tap while to create a loop.
Here’s how your code should look now! In this case, the code while true means that the code inside the loop will keep repeating forever (and ever, and ever...).
Step 3
To move your code into your while loop, you can cut and paste each line of code into the loop. Click on a line of code and click ‘cut’. You can then click inside your while loop and click ‘paste’ to move the code. Here’s how your code should look.
Step 4
You might have spotted that your while loop also added a second pause command. This lets you change add in a delay after the second image is displayed.
Step 5
Now test your code out. Is your animation looping repeatedly?
Nice one! You’ve just made your own Shining Star animation. I’ve used mine to light up the night sky for Dot, but yours could be a decoration in your room.
Try it out
You can now transfer your script to your micro:bit. Tap ‘compile’ to download a compiled .hex file that you can transfer to your micro:bit.
In the micro:bit app tap ‘Flash’, then tap the arrow and ‘Flash’ to transfer your script onto your micro:bit.
You should see a message telling you that your script is being transferred.
Challenge One: Brighter Star
What about if you added a third image to your animation, so that your star shines even more brightly?
Challenge Two: Create Your Own Animation
Using what you’ve learned in this project, how about creating an animation of your own? The more images you use, the better. Go wild!
Project information
micro:bit features used:
Button input
Android device features used:
None
Coding concepts covered:
Sequencing, repetition (while loop), variables
Additional equipment needed:
Android device if using micro:bit app
Steady hand game
Close
Previous
Next
Dot here again! It’s time to make mum sweat! In this project, we’ll make a game that uses the micro:bit accelerometer to detect movement (pretty cool, right?). The player needs to keep the micro:bit absolutely still! Every time they wobble, their score will increase.
How to Play
1. Give the micro:bit flashed with the ‘Steady Hand Game’ to the contestant
2. Get the player to stand on one leg and start the game
3. The micro:bit will track how many times they wobble before the game’s over!
4. The lower the score, the better. Make it even harder with an obstacle course!
Psst...
Before you start coding, make sure you’ve installed and signed into the micro:bit app. You should also connect your phone or tablet to your micro:bit.
For instructions on how to do this, check out our guide in the ‘Discover’ section.
Once you’ve completed these steps, you should see your connected micro:bit on the app home screen.
For this project you’ll also need to connect the battery pack to your micro:bit so you can use it away from your computer.
Download as PDF
Download
...Let’s get started
Task One 
Create the Game
Step 1
Create a new Touch Develop script and name it ‘Steady Hand
Step 2
Let’s start off by making a game countdown. When the countdown finishes the game is over.
Tap inside your script’s main function and then tap game followed by ­> start countdown.
Step 3
The game will last for 10000 milliseconds (10 seconds.) You can change this if you like ­ doubling it will make it really hard!
Step 4
Now let’s add the main game loop that will run your game.
Tap the ‘+’ underneath your code to create a blank line, then tap while followed by ­> game. This will create a basic loop that will repeat until the 10 seconds are over.
Step 5
Your code should look like this
You might have spotted that Touch Develop has added a pause. You can leave this set to 20 milliseconds ­ it means that your micro:bit will pause for 20 milliseconds before checking for another wobble.
Step 6
Test your code by clicking ‘run main.’ You have an empty game at the moment ­after all, we’re not checking for wobbles yet! After 10 seconds you should see an animation on the LEDs, and then the text ‘GAME OVER’ and ‘SCORE 0’ (we’ll add a score later).
Tap the ‘’ button to return to your code.
Task Two 
Check for Wobbles
The micro:bit has an accelerometer which can check for movement, so let’s make the most of it! It can detect movement in x, y and z directions. You’re going to use this to check for the micro:bit being wobbled in the x direction (left­-to­-right.)
Step 1
You’ll need to store the x acceleration in a variable so that you can check for wobbling.
Tap inside your while loop and choose var and name the variable xacc. Then tap after the ‘:=’ assignment operator and choose input and then ­→ acceleration.
Psst...Touch Develop automatically chooses x acceleration ­ the one you’ll be using ­so you don’t need to change anything this time.
Step 2
Your code should look like this
Step 3
An acceleration of zero means that there’s no movement in the x direction ­ but no one can stay that still! We can make it a bit more forgiving by adding some range around zero ­ let’s say ­50 to 50. When the acceleration goes outside that range a wobble has been detected. Uh oh!
First you’re going to check for x acceleration less than ­50.
Tap the ‘+’ below your var code to add a new line.
Then tap if to add a conditional statement. You need to add the condition x < ­50.
Keep the cursor between if and then and tap xacc then < then enter the number ­50 and tap OK.
Step 4
You also need to check for acceleration bigger than 50: x > 50. You can join conditions together with the boolean or operator. The result will be either true (a wobble!) or false (no wobble, phew).
Tap or and then add the condition xacc > 50 as you did with the other condition.
Step 5
Your code should look like this:
Step 6
If the result is true then the micro:bit’s detected a wobble! When this happens, we want to add 1 to the score. Remember, a high score is bad in this game! The score will show the total number of wobbles at the end of the game.
Tap add code here below the if ... then part of your code and then tap game and then add score so that your code looks like this:
Step 7
Now let’s show an ‘X’ on the screen to let the player know they’ve wobbled.
Add a new line below the add score line.
Tap basic then show leds to show a picture and then pause.
Touch Develop sets the pause to 400 milliseconds by default. If you increase it you’ll give the player more time to recover between wobbles ­ but why would we want to do that?!
After the show leds code add another new line and tap basic then clear screen.
Step 8
Your code should look like this:
Step 9
Tap ‘run main’ and move your micro:bit around to test your code. You should see an ‘X’ when you wobble too far. The score at the end shows the number of wobbles. Nice! You’ve made the ‘Steady Hand Game’. Now it’s time to try it out properly.
Step 10
Run the code on your micro:bit. Stand on one leg and hold the micro:bit as steady as you can until you see the game over screen, and the n look for your score. Remember: a low score is good, but zero is best!
Press the Reset button on the micro:bit to start a new turn.
Step 11
Now it’s time for a competition. Gather your family or friends and see who can get the lowest score. Good luck!
Try it out
You can now transfer your script to your micro:bit. Tap ‘compile’ to download a compiled .hex file that you can transfer to your micro:bit.
In the micro:bit app tap ‘Flash’, then tap the arrow and ‘Flash’ to transfer your script onto your micro:bit.
You should see a message telling you that your script is being transferred.
Challenge One: Check for y Wobble
The micro:bit can also check for wobble in the y (front to back) direction. Can you also check that y acceleration is in range?
Challenge Two: Make it Even Harder!
This game is too easy! Let’s change the acceptable wobble range to spice things up ­ we could try between ­20 and 20. We could also increase the amount of time that the game runs for, or give the players challenges to complete to make it extra tricky!
Project information
micro:bit features used:
LED matrix, Accelerometer
Android device features used:
None
Coding concepts covered:
Sequencing, repetition (while loop and forever), variables, boolean
Additional equipment needed:
Android device if using micro:bit app
Hide and seek
Close
Previous
Next
Hello! It's me, Kate. I've come up with a great game to keep Dot and Jax busy next time it's a rainy day. It works by sending signals between your micro:bit and phone (pretty cool, don't you think?). You'll hide your phone and then use your micro:bit to play a sound. When a player finds it, they have to shake it to win your micro:bit will show ‘FOUND!' to let you know!
How it works
1. Pair your micro:bit with your phone
2. Now hide your phone somewhere in the house!
3. Press the A button on the micro:bit to play an alarm on the phone
4. See who can find the phone first
5. The winner shakes the phone to win, before hiding it for the next round!
Psst...
Before you start coding, make sure you’ve installed and signed into the micro:bit app. You should also connect your phone or tablet to your micro:bit.
For instructions on how to do this, check out our guide in the ‘Discover’ section.
Once you’ve completed these steps, you should see your connected micro:bit on the app home screen.
Download as PDF
Download
...Let’s get started
Task One 
Seek!
The player who has hidden the phone will press the A button on the micro:bit to remotely play an alarm on the phone.
Step 1
First you’ll need a new script ­in the app, tap ‘Create Code’ and create a new Touch Develop script called ‘Hide and Seek’:
Step 2
To run your code when button A is pressed you’ll need to use an input event.
Tap input then on button pressed.
Step 3
Now tap add code here to enter new code:
Step 4
Tap device then ­> raise alert to then choose ring alarm.
Your code should now look like this:
This will play an alarm on your phone!
Step 5
It’d be good if we could get some feedback on the micro:bit too. Let’s add a sequence of instructions that sound an alarm and display a message on the micro:bit to let us know the game’s started. Our text can be ‘SEEK!’.
Tap the raise alert to line of code and then use the + to add code after it.
What is sequencing?
Check out the ‘Discover’ section to find out about the coding concept of sequencing.
Step 6
Tap basic then ­> show string and type ‘SEEK!’ as the string to show.
Step 7
Your code should now look like this:
Test out your code by compiling it (you can find out how below in the ‘Try it out’ section).
Task Two 
Found!
The micro:bit can also receive messages from your phone. Let’s display a ‘FOUND!’ message on the micro:bit when the winner finds the phone and shakes it.
Step 1
Add new code at the end of your script.
Tap devices then ­> on notified and choose shaken.
Step 2
Tap inside your on notified block to add code to run when the micro:bit is notified that the phone has been shaken.
Tap basic then show string then type FOUND! as the text to display.
Your code should look like this:
Step 3
Now compile, flash and test your code and make sure that your micro:bit scrolls the text FOUND when your phone is shaken.
Step 4
Excellent, you’ve made your very own hi­tech Hide and Seek game. Have fun!
Try it out
You can now transfer your script to your micro:bit. Tap ‘compile’ to download a compiled .hex file that you can transfer to your micro:bit.
In the micro:bit app tap ‘Flash’, then tap the arrow and ‘Flash’ to transfer your script onto your micro:bit.
You should see a message telling you that your script is being transferred.
Challenge One: Play A Different Alarm
Try out some different alarm sounds and text. Keep the combination you like best!
Challenge Two: Play a Sound for the Winner
Can you also play a different sound on the phone to reward the winner when they shake the phone?
If you put the code for playing the sound after the code to display FOUND! then the micro:bit will finish scrolling the text before sending the message to play the sound to your phone. Try putting the code to play the sound before the code to display FOUND!
Project information
micro:bit features used:
Display output, button input, accelerometer input
Android device features used:
Alarms
Coding concepts covered:
Sequencing
Additional equipment needed:
Android device
Thank you selfie
Close
Previous
Next
Hey, how’s it going? Jax here. Dot got me a pretty amazing remote control car for my birthday, so I’m thinking of putting together a little thank­-you note for her. Wanna help? We’ll be using the micro:bit to send her a hi­-tech selfie - one we can take without even holding the phone!
How it works
1. Place your phone wherever you want it to take the photo from
2. Get in position with your props - make sure you’re still in the camera’s view!
3. Press the A button to take your photo ­- voila, remote­controlled selfie!
4. You can also record a video for an even more awesome message
Psst...
Before you start coding, make sure you’ve installed and signed into the micro:bit app. You should also connect your phone or tablet to your micro:bit.
For instructions on how to do this, check out our guide in the ‘Discover’ section.
Once you’ve completed these steps, you should see your connected micro:bit in the ‘Connections’ section of the app.
Download as PDF
Download
...Let’s get started
Task One 
Take a Selfie
How cool is this - you can use your micro:bit to take a photo on your phone or tablet! Perfect when you need to take a selfie to say thanks. Let’s start our script:
Step 1
Create a new Touch Develop script and call it Selfie.
Step 2
Let’s take a photo when the ‘A’ button is pressed on the micro:bit.
First add the code to detect the ‘A’ button being pressed:
Tap input then -> on button pressed.
Touch Develop chooses the A button by default so you don’t need to change it.
Step 3
Now let’s put the device into photo mode.
Tap add code here. Tap devices and then tell camera to. This will give you the options for using your camera with your micro:bit.
Choose launch photo mode to enable your device’s camera.
Step 4
Next you’ll need to add a delay to allow photo mode to launch.
Add a new line below the launch photo mode code.
Tap basic then pause then enter 5000 milliseconds as the delay.
Step 5
Next, add a take photo command to take a photo after photo mode has been enabled.
Your code should look like this:
Time to test your code. Get your phone or tablet ready for a selfie.
Compile your project and run it on your micro:bit.
Press the ‘A’ button and check that a photo was taken.
You can use the back button on your device to exit photo mode.
Task Two 
Countdown
It works! But it’d be even better if we had some feedback on the micro:bit.
Step 1
A for loop repeats the code inside it a number of times. It also stores the number of the current loop in a variable called i so that you can use that number inside the loop.
What is a variable?
Check out the ‘Discover’ section to find out about the coding concept of variables.
Add a new line of after the take photo line.
Step 2
Tap for to create a for loop:
Touch Develop sets the number of repetitions to 5 which is fine.
Step 3
At the beginning for the for loop, i is set to 0. It increases by 1 each time. The for loop will run until the i < 5 is false, which will be when i=5.
Step 4
The value of the i variable will increase by 1 for each repetition of the for loop:
First time: i=0
Second time: i=1
Third time: i=2
Fourth time: i=3
Fifth time: i=4
You’ll need to calculate 5 ­- i to get the number you need for the countdown. This gives:
First time: i=0 ; 5 ­- i = 5
Second time: i=1; 5 - i = 4
...
Fifth time: i=4; 5 - i = 1
Step 5
Tap inside your for loop and then tap basic then show number:
Delete the 0 input and enter 5 ­- i. The second input to show number (the number 150) is used when scrolling larger numbers. You don’t need to change it.
Your code should look like this:
Step 6
Test that you now get a 5, 4, 3, 2, 1 countdown when you press the ‘A’ button on your micro:bit.
Task Three 
Smile!
Let’s show a smiley face after the countdown to remind you to smile.
Step 1
Select the end for line of code and them click ‘+’ to add a new line below it.
Tap basic then show leds and draw a smiley face:
Test that you now get a 5, 4, 3, 2, 1, 😊 countdown when you press the ‘A’ button on your micro:bit. If it worked, great - you’ve got a remote selfie taker!
You can adjust the countdown if you need more or less time.
Task Four 
Take a Video
So we can take a photo now, but I reckon Dot would like to see me using the remote control car. Let’s get a video recording script sorted.
Step 1
Let’s use the Selfie script as the starting point for the Video script.
Tap My Scripts to return to your list of scripts.
Step 2
Tap Clone to make a copy of your script.
Step 3
The copy will open automatically - simply rename it to ‘Video’:
Step 4
Then, change launch photo mode to launch video mode:
Step 5
Change ­-> tell camera to so that it uses start video capture instead of take photo.
Your code should look like this:
Step 6
Test your code by pressing the ‘A’ button on your micro:bit, pulling some stunts with your remote control car. Video will automatically stop recording after 30 seconds.
Step 7
Excellent! Photo and video SORTED
Try it out
You can now transfer your script to your micro:bit. Tap ‘compile’ to download a compiled .hex file that you can transfer to your micro:bit.
In the micro:bit app tap ‘Flash’, then tap the arrow and ‘Flash’ to transfer your script onto your micro:bit.
You should see a message telling you that your script is being transferred.
Challenge One: Stop!
Do you want to be able to take shorter videos? Add code to stop video capture when the B button is pressed.
You could also change the image that is shown when you start taking video and clear it when you stop taking video
Project information
micro:bit features used:
Button input
Android device features used:
Camera
Coding concepts covered:
repetition (for loop), variables (in for loop)
Additional equipment needed:
Android device
Get out of my room!
Close
Previous
Next
Hey guys, Dot here. Sorry, I'm a little bit flustered...someone's been sneaking into my room and stealing my snacks! I know just how to catch them out though - and I'll get the evidence to prove it. Follow me and we'll turn our micro:bit into a hi­-tech intruder alarm, by making it into a DIY motion sensor!
How it works
1. Pair your micro:bit with your phone
2. Now place the phone and micro:bit in your bedroom, looking toward the door
3. When someone walks through, they’ll set off the motion sensor...
4. Busted!
Psst...
Before you start coding, make sure you’ve installed and signed into the micro:bit app. You should also connect your phone or tablet to your micro:bit.
For instructions on how to do this, check out our guide in the ‘Discover’ section.
Once you’ve completed these steps, you should see your connected micro:bit in the ‘Connections’ section of the app.
For this project you’ll need some wire or tin foil to make your alarm. You’ll also need to connect the battery pack to your micro:bit so you can use it away from your computer.
Download as PDF
Download
...Let’s get started
Task One 
Coding a basic alarm
Let's start by creating a basic alarm script, which will be triggered when a connection is made on one of the micro:bit's input/output (I/O) pins.
Step 1
Create a new Touch Develop script and name it 'Room Alarm'.
Step 2
Your micro:bit includes 3 I/O pins, which can be used to detect whether a connection has been made.
To begin, you want your script to display an image when a connection has been made on Pin 0.
Step 3
You can test this script on the emulator. Click ‘run main’ and then tap on Pin 0. You should see an ‘x’ appear on the micro:bit display!
Step 4
Click ‘compile’ and then flash this script to your micro:bit to test it on the device itself. The micro:bit will detect when a connection is made between Pin 0 and the ground pin (GND). You can make a connection between these 2 pins with anything that conducts electricity, including your body!
For instructions on how to compile and flash code to your micro:bit, refer to the end of this project.
Place one thumb on the GND pin and then press and release your other thumb on Pin 0. You should see an ‘x’ appear on the micro:bit screen.
Task Two 
Constructing your alarm
Let’s use your alarm to detect when someone enters your room.
Step 1
Take a piece of wire around 10cm long, bend it in half around the ground pin and twist the 2 ends of the wire together.
Step 2
Do the same for Pin 0. Here’s how your micro:bit should look:
Step 3
Connect your battery pack to your micro:bit, and stick them both to the top of your door frame, so that the metal wire just reaches the door. Stick your micro:bit near the door’s hinge to give yourself enough room to escape.
Stick some foil to your door underneath your micro:bit. Make sure the wire doesn’t touch the door when it’s closed!
Step 4
Test your new door alarm by opening your door slightly. The foil should make a connection between Pin 0 and the ground pin, causing a ‘x’ to be displayed on your micro:bit.
You can press the reset button on the back of your micro:bit to clear the display.
Task Three 
Improving your alarm
Let’s make some improvements to your alarm system.
Step 1
You’ve probably noticed that you activate your alarm when you try to leave your room! To fix this, you can add the code basic → pause(2000) so that the alarm is only activated after 2 seconds.
Step 2
Test out your script - if it’s right then you can only trigger the alarm after 2 seconds. You can change the pause time to give yourself longer to leave your room.
Step 3
Another problem with your alarm is that you have to remove your micro:bit from the door to press the reset button. Instead, you can modify your alarm so that it can be activated with the A button.
To do this, tap var to create a new variable called activated at the start of your script, and set the value to false.
Step 4
Tap input → on button pressed to add code for responding to button A being pressed. You can then cut and paste your pause command into your new on button pressed code.
Step 5
At the start of your script your alarm is disabled by setting the value of your activated variable to false.
To set the variable to true when the A button is pressed, tap to add a new line after your pause command, and then tap activated, then := and then type true.
Here’s how your script should look:
Step 6
Finally, when a connection is made on Pin 0, you only want to trigger your alarm if the alarm is activated. To do this, tap to add a new line at the top of your on pin pressed code and tap if → activated → equals → true.
Step 7
You can then cut and paste your code for displaying an ‘x’ inside your new if statement.
Here’s how your code should look:
Step 8
Test your improved door alarm. You should see that your alarm isn’t activated until the A button is pressed. If you only want your alarm to be triggered once, you can add code to set the value of your activated variable back to false after the alarm has been triggered.
Task Four 
Catch your intruder
Let’s take a picture of your intruder, and find out who they are!
Step 1
Add code to take a picture when a connection is made on Pin 0. You can use devices → tell camera to(launch photo mode) and then devices → tell camera to(take photo) to do this.
Step 2
You can also deactivate your alarm by setting your activated variable to false after a picture has been taken.
Step 3
Test your alarm. Is a picture taken when the door is opened? Is the alarm activated afterwards?
Try it out
You can now transfer your script to your micro:bit. Tap ‘compile’ to download a compiled .hex file that you can transfer to your micro:bit.
In the micro:bit app tap ‘Flash’, then tap the arrow and ‘Flash’ to transfer your script onto your micro:bit.
You should see a message telling you that your script is being transferred.
Challenge One: Reset your alarm
Can you code your alarm so that the screen is cleared when the A button is pressed? You can use basic → clear screen to do this.
Challenge Two: More improvements
Can you customise your alarm? Here are some ideas:
  • Choose your own personal way of activating your alarm. This could be using the B button, A+B buttons together, or you could even use Pin 1 or 2;
  • Add a display to let you know when your alarm has been activated;
  • Display a message when your alarm has been triggered.
  • Play a sound when your alarm has been activated and/or triggered;
  • Modify your alarm so that once it’s triggered there’s a delay before a picture is taken or alarm sounded. You could then add a way for you to deactivate your alarm, by setting your activated variable back to false.
Project information
micro:bit features used:
Display output, button input
Android device features used:
Photo, video
Coding concepts covered:
Control
Additional equipment needed:
Android device, micro:bit battery pack, wire (20cm) and tin foil.
Citizenship
What we care about
Everyone should have access to an education and training in digital skills in today's world of technology. Samsung's Citizenship Programme aims to help close the digital divide and skills gap in the UK. 
Read more
Get the app
The official micro:bit app
Developed by Samsung
The official micro:bit app
Developed by Samsung
x
Share on Facebook
Share on Twitter
Share on Google+
Share on Pinterest
x
x