$USD
  • EUR€
  • £GBP
  • $USD
PROJECTS micro:bit

micro:bit Project 7: Music Box

DFRobot Oct 15 2018 1010

In the gift shop, we can always see various eye-catching music box in different shapes which are not only cool but also interesting. This lesson to be learnt is about producing a music box. Now, let’s begin. 

Components needed

Main control board of micro:bit
1×  Expansion board of micro:bit
1× headphone
motion sensor module
1× USB cable

Hardware Connection

Connect the mainboard of micro: bit to the computer and plug the headphone into the jack.

Connect the motion sensor module to interface P1 of the expansion board.

Note: since the jack occupies the interface P0, so P0 is not available when playing the sound.


Program

Task1: Electronic music box
Functions: enable the mainboard of micro: bit play the music.
STEP1: drag the “start melody dadadum repeating once” of the “Music” to “forever”. There are already many built-in melodies for choices. The one we chose here is the first melody "dadadum" to be repeated once.

STEP2:  since the complete melody "dadadum" accounts for 4 beats, so the time range needed be set for play is 4 beats in the below module. Final procedure

STEP3: try to adjust the sound that the micro: bit board plays by turn the "turntable" next to the earphone jack on the expansion board.


Task2 : smart music box

Functions: When someone is approaching, the mainboard of micro: bit will play a piece of music that you have edited; when no one is near, it does No play any music.
STEP1:edit "Twinkle, Twinkle Little Star" .

First, look at the musical notation, tones, Noes and the vocal frequency required of the song before trying writing the code to play the first sentence of it.


"Twinkle, Twinkle Little Star" .
Take the middle C as an example, the sound frequency and its corresponding notes are shown in the following table:

Notes1234567
Hz262294330350393441495

Click the “Music”, now the used module is about the “play tone Middle C for 1 beat”. Here, you can set the tone and beats.

After editing the song, we enable our micro: bit to sing, but how can it be made more smart? Now, we need to use a motion sensor. In fact, it principle is very simple. We can make the music box smart by adding a conditional statement we have learned before! Let’s study how to make come true.

STEP2:the final program

REVIEW