This is a series of projects that grew from an introductory set of group workshops that we wrote for a local school's open day to promote their Code Club. Projects 1 to 3 ran for about 20 minutes each, and projects 4 and 5 became workshops at the Code Club where I volunteer (these can each be completed within an hour). These projects were easily completed by kids from ages 7-11. The projects that use multiple micro:bits are scaleable and can work well with any number of micro:bits from 2 to class sets; with the option for kids to collaborate in pairs or larger groups.
Project 2: Shake a Number
There are sensors in the micro:bit that can detect when it is tilted. In this project, we will show different patterns on the micro:bit when it is tilted left and right.
In this project, you will learn:
- How to perform an action based on an event such as shaking your micro:bit
- How to generate a pseudo random number on your micro:bit (
pseudo randommeans a number as random as can be comfortably created with the resources available on our device)
You will need:
- A micro:bit (V1 or V2 is fine) and matching USB cable
- A computer with an Internet connection and a modern web browser
Step 1: Launch your browser, and got to the MakeCode website
- Launch your web browser by clicking on its icon
- Once your web browser loads, click in the address bar at the top and, in the address bar, type in:
https://makecode.microbit.org
Step 2: Write your code
- Click on
Inputand drag across theon shakeblock - this will let us do something when the micro:bit is shaken
- Click on
Basicand drag theshow numberblock into theon shakeblock. FromMathdrag thepick random 0 to 4block into theshow numberblock. Now change the4to a6by clicking on it and typing6.
Your code should look like this:
Step 3: Copy your code to the micro:bit and see it run
-
Hold your micro:bit carefully by the edges only, and plug in the micro:bit into the USB port on the computer. Ask for help if you don’t know how to do this. In the bottom left corner, click on the Download button.

-
Find the
MICROBITfolder and save the.hexfile there. You’ll see a light on the micro:bit flash and stop flashing. When it stops, your code will run. Shake your micro:bit to generate a number between 0 and 6.
Congratulations! You've written another program on the micro:bit!

This tutorial is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.