Micro:bit – Use MakeCode to Make a Treasure Chest with a Burglar Alarm

Light Activated Treasure Chest

Description

This micro:bit project combines arts and crafts with coding to make a treasure chest with a burglar alarm. The alarm uses the LED array on the micro:bit as a light sensor. When the lid of the treasure chest is opened, the light on the LEDs triggers the micro:bit to play a sound. The portion of the project that requires coding the micro:bit is easy so it makes a nice beginning coding project.

Programming Language

MakeCode Blocks

Difficulty Level

Beginner

Age Range

Ages 9 and up

Here is a video of the final project

Materials

Designing the Project

Project information

The treasure chest has a bottom where the micro:bit is hidden. Here are the steps for setting it up:

  • Paint and decorate treasure chest
  • Cut the cardboard to fit chest opening. You can use this template if you are using the chest linked above.

Light Activated Treasure Chest

 

  • Decorate it to look like jewels

  • Code and test the micro:bit (directions below)
  • Attach the micro:bit to the bottom of the insert with some easily removed tape like painter’s tape

  • Turn the battery pack on,  place the insert in the box, and close the box

Programming the micro:bit

Develop the problem statement

The problem statement for this project should be something like “make an alarm that goes off if the box is opened”. Here is my problem statement:

Make a siren sound play if the box is opened

This isn’t that complicated. The only thing it specifies is a siren sound.

Write the Algorithm

The algorithm needs to get a little more specific about what is going to cause the alarm to sound and how long it sounds. Here is my version:

  • Check light level
  • if any light is present
    • play siren sound for 2 or 3 seconds
  • Repeat the above steps forever

Write the Pseudocode

The pseudocode should look more like the real code. It is useful because it helps get students thinking more in terms of the programming language they are going to use rather than plain English.

Here is my version of the pseudocode:

  • Do Forever:
    • Read lightLevel
    • If lightLevel > 0
      • Play sound
    • Pause for 3 seconds
  • End Do

Write and Test the Code

Once you are happy with the pseudocode, go ahead and write the code in MakeCode.

Sample Code

Here is the code I wrote

<other headings particular to this post>

Concepts Involved

Math used

  • Inequalities

Programming Concepts

  • Conditional Logic

NGSS Concepts

PS4 – Wave properties