micro:bit project: Interactive Valentine

Motion Sensor Valentine Box

Description

This project shows you how to create an interactive box that uses movement as an input to determine the behavior of a micro:bit. The box is designed to be big enough to hold a micro:bit and a battery pack. There is a heart-shaped cutout to display the LED array embedded on the front of the micro:bit. The micro:bit is coded to play a song and to display a flashing heart based on the box being tilted right or left. The pattern box for the project was cut using a Silhouette Cameo 4 but it is simple enough to cut by hand.

Programming Language

MakeCode blocks

Difficulty Level

Beginner

Age Range

11 and up.

Materials

Note: If you are using a version 1 micro:bit, you will need to add a speaker. My recommendation is the Pimoroni noise:bit.

Designing the Project

Develop the problem statement

This project is about creating a fun way to incorporate a micro:bit into a paper crafting project. An important feature is to make it easy for the user to interact with the micro:bit. The micro:bit has two built-in ways of communicating: lights and sound. I want to have the project use both of these.

The problem statement I used for this project was:

Create something that can hold a micro:bit and battery pack,  Have two inputs that the user can initiate with no training, Have the micro:bit react to one input by playing a melody and to the other input with an animated light display.

  • Create a box big enough to hold the micro:bit.
  • Use tilt right and tilt left as the inputs since having the micro:bit hidden in a box rules out using the buttons and the touch pads as input.

Write the Algorithm

When box is tilted left, play a song

When box is pointed right, draw a heart and flash it 3 times

Write the Pseudocode

This project is set up to sense two behaviors from the micro:bit and respond differently depending on the behavior. The code is going to have two event blocks and initialize anything else in the ‘on start’ block:

  • When ‘on start’
    • Initialize speaker (V2 micro:bit only)
  • When ’tilt left’
    • Play first several notes of “Can’t Help Falling in Love”, sung by Elvis Presley
  • When ’tilt right’
    • Repeat 3 times Draw a heart in three steps
    • for 3 times
      • flash it off and on

Write and Test the Code

Here is the Sample code that I wrote.

Build the box