Introduction
The shake alarm repeats a musical tone when movement is detected. This activity introduces creating a complete project from the Microsoft MakeCode for micro:bit homepage and working with ‘repeat’ blocks.

What you need
- BBC micro:bit V2 connected to MakeCode (see Preparation below)
- 50cm to 1m long USB A to USB Micro B cable (the additional length to the standard 0.3m cable length helps with freedom of movement)
- Computer with a keyboard
- Screen reader software
- Tactile code for this activity. Choose one of the following:
- Shake alarm tactile cut-out blocks (including the MakeCode tactile toolbox key)
- Shake alarm completed tactile program (including the MakeCode tactile toolbox key)
- Shake alarm text program (for use with a braille embosser or as a digital document)
- Recommended: MakeCode editor tactile diagram and key
- Optional: Refreshable braille device
Preparation
In these activities, instructions are given for Windows users. Mac users should use Command instead of Control and Option instead of Alt when using keyboard controls.
Before downloading your program to the micro:bit for the first time, you need to go through a series of steps to connect the micro:bit to MakeCode. These steps are screen reader accessible. However, educators may choose to complete these steps as part of preparation for this activity to give students a straightforward first experience. To do this, in MakeCode press Control + B then 5 to move to the Bottom bar then press Tab to move to the Download Options button and then press Enter and choose Connect Device, then follow the steps.
After connecting, a single L keypress can be used by the student to download a program to the micro:bit.
If you are using the tactile blocks, then use them to talk your student through creating the Shake alarm completed project including replacing the block inputs.

You can return to tactile blocks at any point during the activity to reinforce concepts and students can use the completed project as a reference.
Instructions
Explore the tactile code
Explore the tactile shake alarm code.
The ‘on shake’ block is a container block. It has a block that goes at the start, and a matching end. In MakeCode, the end gets added automatically. When a shake gesture is detected, the code inside the ‘on shake’ block will run.
The ‘repeat’ block is a container block that can be placed inside other container blocks. It also has a matching end that gets added automatically in MakeCode.
Each code block has a tactile icon. Use the MakeCode tactile toolbox key to identify which section to find the block in the toolbox in MakeCode. For example, the ‘repeat’ block is in the Loops section.
In the toolbox, the Loops section has a ‘repeat 4 times’ block. After adding the block to the workspace, you can change the 4 to a 3.
Create a new project in MakeCode
- Go to the MakeCode for micro:bit home page. If you already have a project open, you can press Control + B, then 1 to go to the top bar. Then press Tab to reach ‘Home screen’ and press Enter.
- Press Tab to move to ‘New Project’ and then press Enter.
- Type “Shake alarm” as the name of your project and press Enter to create a new project. The MakeCode editor will open with a new project.
Delete the on start and forever blocks
- Press Tab to reach ‘Skip to Blocks workspace’ then Enter to go to the workspace. You can also use Control + B, then 4 to get to the workspace.
- Use the up and down arrow keys to explore the blocks on the workspace. When MakeCode creates a new project, two blocks are added to the workspace, an ‘on start’ block and a ‘forever’ block.
- You do not need these blocks so navigate to each block and press Delete.
Tip:
- Make sure screen reader mode is on. Press Alt + Shift + A from the workspace to turn screen reader mode on or off.
Create the shake alarm project
Create the Shake alarm project from the tactile code or view Shake alarm text program online if you prefer.
- Press T to open the toolbox, use the up and down arrow keys to select the Input section.
- Press the right arrow key to move to the Input blocks then the down arrow key to find the ‘on shake’ block and press Enter to add it to the workspace.
- The block is in Move mode. Press Enter to confirm the position.
- Open the toolbox, choose the Loops section and add a ‘repeat 4 times’ block inside the ‘on shake’ block. When you add a block from the toolbox it is in Move mode. MakeCode positions the block based on the currently selected block. If the added block is a statement block, it will add it inside a selected container block. If the position is not correct, then use the up and down arrow keys to move the block. Press Enter to confirm the position.
- Press the right arrow key to move to the number 4 input on the ‘repeat’ block. Change the 4 to 3.
- Open the toolbox, choose the Music section and add a ‘play tone Middle C’ block inside the repeat block.
- Open the toolbox, choose the Music section and add a ‘rest for 1 beat’ block inside the repeat block. When you add a block from the toolbox it is in Move mode. MakeCode positions the block based on the currently selected block. If the added block is a statement block, it will add it after a selected statement block.
- On the rest block, change the 1 beat to ½ beat.
- Use the up and down arrow keys to check your code. When you use the down arrow key to move inside a block, MakeCode plays a higher pitched beep when you move inside a container block to indicate the level of nesting.
- Press L to download your program to the micro:bit. Shake the micro:bit to set off the alarm.
Tips:
- Hold the micro:bit horizontally and give it a firm shake backwards and forwards to trigger the shake gesture.
- Each time you enter a container block MakeCode beeps at a higher pitch. When you leave a container block the beep gets lower.
The completed shake alarm project is available below:
Make it your own
- Change or add musical notes
- Change the length of the rest
- Change the number of repeats