Element 14 Micro:Bit Summer of Code Club Challenge 2019

We were very lucky to be selected as winners of Element14’s Micro:Bit Summer Code Club Challenge!

To help us bring coding to our community we received:

The challenges I set myself for this code club were:

  • any age, including adults
  • scalable in both number of participants, and complexity
  • fun!

The final idea:

An electronic puzzle/escape room device.

System Outline

Lock Box

There will be a central “lock box” to which the “lock-master” micro:bit will be connected.
The lock box will be any container that can be secured in such a way that a servo can be used to “unlock”. The box will contain some sort of reward or prize for participants.

It will be programmed to listen on a known radio group.

There will be an admin mode that allows the mentor running the session to adjust the number of puzzle bits being used.

The lock-master awaits messages from the puzzle-bits that indicate they have been solved. When all puzzle bits are solved, the servo is activated and the lock-box unlocked.

Things to Consider

Cheating. The initial code will probably just wait for 5 “unlocked” messages.
This can be enhanced:

  • check the serial number sent from each micro:bit
  • an initial “setup” stage that records the serials of the “allowed” puzzle-bits

Suggestion: leave it open, have a discussion about hacking, let participants try to hack, secure, and hack again :slight_smile:

Puzzle Bits

These are the micro:bits that participants will work with.

They will be provided with a template that includes the steps needed to send the “puzzle solved” message to the lock-master.

Participants then create a puzzle (as simple or as complicated as they like) for a user to solve.

Session Outline

Minimum session time: 2 hours.

  • welcome
  • brief description of micro:bit
  • show maker:code
  • download basic “press button->message” example
    • verify download is working with known good code
  • go over basic loops and logic
    • practice
  • go over displaying messages
    • practice
  • introduce the sensors
    • practice. Potentially limit sensors covered if time is short.
  • Challenge: Come up with a puzzle for a person to solve on your micro:bit
    • introduce template code that sends “solved” message to master
  • Wrap up:
    • swap puzzle-bits with other participants, see if group can unlock the lock box and earn the reward!


  • movement based puzzles (accelerometer, compass)
  • physical inputs (switches, LDR, etc)
  • other sensors
  • connecting to more advanced computers (eg puzzle on Raspberry Pi, BrainPad Arcade, …)


  • location of a cooler full of ice blocks, etc
  • discount coupons to an escape room (working on that for Courtenay.)

MakeItZone Micro:Bit SoCCC 2019 Blog #2 - LockBox/Safe Design

I bounced the LockBox/Safe idea around with a few people of different ages, interests, and skill-sets, and got general agreement that this has potential.

The next step was to design it.

I opted to use Fusion360 to design it in 3D, even though it will be laser-cut out of 3mm birch plywood sheets. I’m learning that the parametric modelling and timeline features are amazingly powerful- especially if you think of the design as a series of programmed geometric operations.

However, there are two caveats/“Gotcha’s” that regularly catch me up:

  1. Rolling the timeline back to a feature, editing it, breaking later steps, and not noticing the yellow exclamation marks that appear on the timeline. These indicate that your design ‘program’ is ‘not compiling’. Unfortunately for me, Fusion360 will try and use cached data from before I broke the design. I have to diligently keep checking for these issues. I would like to have these more prominently highlighted in the UI.
  2. You can set up a table of parameters (eg sheet_thickness) and base your design on these variables. Change one, and if your design is well built, the final geometry will magically update correctly. However you can’t keep the parameter table window on screen as you edit, nor can they be shared across sub-assemblies/designs. To help with the later I use the ParameterIO add-on.

I modelled the door as a sub-assembly and then imported it into the final fully assembled model.

As a rendering it looks something like this:

The box on the left of the door is the AAA battery pack for the MicroBit. The servo is mounted on the inside of the door, with the circle-with-a-side-chopped-off latch attached to a servo horn. Hidden in this view is a cutout to run the servo wires from the inside to the MicroBit, and mounting holes for bolts to run through the door and attach the MicroBit. The servo can be attached to power and Pin 0 by soldering or looping under a mounting bolt. The MicroBit is on the outside of the LockBox so it can be configured, reset, and so the screen can display status messages.

Next step is to export the flat surfaces into SVG files ready for laser cutting. I’ve found the Shaper Utilities addin to be the most reliable way to do this.

The SVG files are then imported into Inkscape where the final required tweaks were made to match our laser cutter’s requirements.

The parts were cut and packed, ready for our trip to Hornby Island and a session at a new Makerspace- the Hornby Island Spark.

The final assembly was done at a small cabin in the woods:

Very happy it went together with only one minor issue- the door should be slightly narrower to have a little more clearance so that it can be more easily opened and closed.

Note: the door is 1mm narrower in the latest version of the design on Autodesk’s design sharing site.

The design files have been shared publicly:

Next post- the MicroBit Code.

MakeItZone Micro:Bit SoCCC 2019 Blog #3 - LockBox/Safe Software

LockBox/Safe Controller

Our rough requirements for the LockBox/Safe software are:

  • There will be an admin mode that allows the mentor running the session to adjust the number of PuzzleBits being used.
  • The lock-master awaits messages from the puzzle-bits that indicate they have been solved. When all puzzle bits are solved, the servo is activated and the lock-box unlocked.
  • Prevent (obvious) cheating by checking the serial number sent from each micro:bit

I implemented this as a basic state machine, with the following key states:

Reset (starting point): initialize variables and set servo to a specified rotation.

Configuring: Allow the user to enter the number of unique PuzzleBits required to send an unlock message to fully open the latch. Entry is via the A and B buttons. A+B exits this state.

Running: When an unlock message arrives via radio, and it’s from a PuzzleBit we haven’t had an unlock from, rotate the lock 1/(number of puzzle bits) towards being opened. A PuzzleBit can also send a lock radio message that will remove it from the list of known PuzzleBits and rotate the lock 1/(number of puzzle bits) towards being closed. Can be moved back to the reset state by pressing the A+B keys.

Unlocked: The lock is open- hooray! Displays a success animation.

Override: There is a “Konami code” (A, B, B, A) that can be entered in the running state. This will open the lock without resetting the current completion state. Useful if you need to check on what’s hidden in the lockbox. Can be escaped, moving the lock back to it’s previous level of “unlock”-edness by pressing the A+B keys.

It’s too complicated for beginners to look at, but can be a good thing to review at the end, once they have made some PuzzleBit applications.

The code:

Here are versions you can manipulate/copy/read:


  • there are minAngle and maxAngle variables in the onStart callback that will need to be tweaked to your servo. They represent the lock being fully closed and fully open.


These are the core of the exercise: the PuzzleBits are MicroBits that are running an application that provides the end user with a problem to solve. When the puzzle is solved, it sends an Unlock message to the LockBox.

The coding participants are given the task of creating the puzzle applications.

Template PuzzleBit Application

Links to source code you can manipulate/copy/read:

This application is both a test tool for the LockBox, and a simple template to be used as the basis for participants. For beginners I may not explain what functions are, but just from the visual construction, many “just get it” before being presented a formal description.

It simply waits for button presses and sends an unlock message when button A is pressed, and lock when button B is pressed.


  • by default MicroBits don’t send a unique ID with radio packets. So the lock can identify each PuzzleBit we need to enable the sending of the device unique ID with radio packets. The radio set transmit serial number command is in the radio...more sub menu.

Example Compass & Button PuzzleBit

And finally, a very simple example puzzle application that uses a sensor, a button, and introduces Boolean logic:

Links to source code:

The puzzle: turn the MicroBit to the correct orientation and then press the A key to trigger sending the unlock radio message.

Some notes discovered while creating this and showing it to some beginners:

  • the event-callback system is very intuitive, but dealing with syncing state between blocks of code, using variables, is far more complicated than explaining and implementing a polling loop
  • onStart is not guaranteed to complete before any forever blocks. Explaining random startup glitches (eg holding a button after reset and having that handler start before onStart has finished) is complicated and frustrating. Implementing guard states/variables is a giant leap, and adds a lot of boilerplate code all over the place.
  • Instead of call-backs and variables you can test the state of buttons and the compass bearing
  • There is a bug with the accelerometer gestures if you don’t use callbacks. They’ll never trigger. You have to kick the accelerometer framework and get it running so that there is input data flowing into the gesture recognizer. I found that assigning an acceleration measurement to a dummy variable in the onStart callback is enough.

Now we have the physical and software building blocks needed to run a session. The next blog post will cover how we set up and ran sessions.

MakeItZone Micro:Bit SoCCC 2019 Blog #4 - Lesson Plan and Sessions

Finally we reach the purpose of all this preparation: some hands on sessions!

Wherever possible, I aim to make my materials scalable: length of session, range of abilities, range of ages. For this project, I aimed to make it work for a two hour session, through to about a two day session.

No matter the length of the session, we need to do some introductions. This can be as simple as your name and interests, through to an ice breaker. Something for everyone to get to know each other. From there, I like to do a “real world” discussion and exercise about programming. My favourite is to pretend to be a very dumb robot. The goal is to “write a program” for me to walk out a square. Each participant gets to yell out one instruction which I “execute” in the most literal, hammy, method possible. A call of “walk” will probably result in my choosing a random direction and walking in/over/through things until I reach an impenetrable barrier; usually a wall. This pretty naturally leads to some discussion about the required level of specificity they need to be thinking about for their program instructions, and that there’s usually more than one way to write code that ends up with the same results- e.g. loops vs a long list of repeating instructions.

From there we move to the computers and MicroBits and work on the session challenge: creating a PuzzleBit that acts as one of the “keys” to unlock the Safe with the goodies.

I’ll include my full lesson plan below.

So far, we’ve used this project twice, with great success in both cases!

Session One: Hornby Island Spark

The Hornby Spark is a new Makerspace serving the community of Hornby Island, off the East coast of Vancouver Island. My family had planned to vacation there for a week, and I got in touch with the executive team to see if we could put on a session. They agreed, and we arranged to do a two hour session, that Saturday:

We had no idea how many people would show up- Hornby is a very popular holiday destination for it’s beaches, hiking, and cycling. We weren’t sure if locals would have time, or visitors the interest.

I wasn’t sure if we would have internet access, so was very glad to find out that there is an offline version of MakeCode. One thing I noticed, the offline version seems to do a better job of automatically detecting connected MicroBits and programming them. I also downloaded the source code for the MicroBit version of the PXT/MakeCode environment- just in case I had to run a local server. It’s not that difficult, but the offline app version is much easier to deploy!

To our happy surprise we had 8 participants attend, ranging in age from approximately 5 to 55- both elementary aged kids and a holidaying high school shop teacher!

At the end of the two hours we had 5 puzzle bits! A couple of them were the same “puzzle”, as there wasn’t enough time for the participants to learn how to use much more than the buttons. But everyone got the idea and there was a lot of excitement watching the servo of the lockbox move 1/5th of the required rotation as each puzzle was solved! And of course everyone enjoyed the chocolate bars that they had unlocked!

We were happy to be able to leave the laser cut box and 5 MicroBits with the Spark for future sessions!

Again, my thanks to the Spark for letting me use their space!

Session Two: MakeItZone Summer Camp

I also did a five day summer camp introducing programming for physical devices. The participants were aged between 9 and 13, and got to explore MicroBits and Lego EV3.

For this week long session we spent about 2.5 days working with the MicroBits. With the extra time we got to investigate logic, variables, sensors, and basic electronics. The KitTronix inventor kits worked spectacularly for this! They made the process of prototyping with the MicroBits much easier than separate breadboards and jumpers to the MicroBit. I also used some of their example circuits and applications as launch points for the participants. The kids loved using the piezo, and making things move with the motor.

Interestingly, none of them decided to use the parts as part of their final puzzle. Instead they opted to create complicated sequences of A and B button presses. If you press the wrong one in the sequence it’s reset back the beginning! From memory, the longest sequence was around 16 steps!

Again, we swapped PuzzleBits and all of us enjoyed watching the latch move a small fraction of the required rotation as each puzzle was solved! This time the treasure was a box of popsicles- which were greatly appreciated on a hot summer day!

Session 3: OceanSide Community Makerspace, Parksville

Oceanside Makerspace is another, relatively new, Makerspace, located in Parksville, Vancouver Island.

I had planned on sending them a kit of lockbox, servo, and 5 microbits before the end of the summer break, and have it be the first session using these materials mentored by someone else. Unfortunately other things have come up and caused this to be delayed. I’m still planning on sending them the remaining 5 MicroBits that we received as part of the summer of code challenge- hopefully in the next week or so.


I think we came up with a winning programme, that achieves the goal of being scalable. And the Kittronik Inventor’s kits really do make it a lot easier to add basic electronics circuits to the MicroBits!

I’m also very glad that we were able to share the MicroBits that we received with our neighbouring Makerspaces! Thank you Element14!

Lesson Plan

PNG version of Mindmap.

PDF and iThoughts version are available at the github repo for this project.