Play a Song
Time to become a digital musician! This activity will turn your device into an instrument. You’ll learn how to program a sequence of musical notes and use timing to control their rhythm, piecing together the classic ‘Happy Birthday’ song one block at a time.
Musical notes; Sequencing; Timing; Sound; Speaker
Are you a teacher?
Courses
- Grades 3-12
Materials
- Smartphone, tablet, or computer
- Internet connection
Educational Objectives
- Understand the concepts of sequencing steps.
- Create a technological object (prototype) using a device.
- Identify relationships between technology and the surrounding world.
- Evaluate personal and others’ work.
- Engage in dialogue and reflection on improvement ideas.
Start (10 minutes) - The Science of Sound
- Welcome students and introduce the day’s activity: “Today, we are going to learn how to create a prototype of a musical toy.”
- Spark their curiosity with a question: “How do you think your phone or headphones produce sound?”
- After a brief discussion, it’s time to demystify the technology. Let’s explore how a simple speaker can turn silent electrical signals into the music and sounds we hear every day.
How do devices produce sound?
Ever wonder how your phone can blast your favorite tunes? The magic happens in a tiny component called a speaker. Think of it as a device that converts electrical signals into sound waves. A magnet and a coil inside move when electricity passes through them, causing a cone to vibrate. These vibrations create the sound waves that travel through the air to our ears. Our brain interprets these waves as music, voices, or sound effects, allowing us to enjoy a movie or sing along to a song.
Speakers are everywhere!
You can find speakers in all sorts of devices! They’re in your TV, inside your headphones, and of course, in your smartphone. If you’ve ever watched a video or listened to music on your phone, you’ve heard its speakers in action.
Development (20-30 minutes) - Composing the Melody
- Now that everyone understands the basics of digital sound, let’s start composing! The mission is to recreate the “Happy Birthday” song by programming the correct sequence of notes and delays.
- Guide your students through the step-by-step instructions for building the melody, which are detailed in the hands-on section below.
- The required sequence of notes is: C4, C4, G4, G4, A4, A4, G4, F4, F4, E4, E4, D4, D4, C4. Ensure they arrange the blocks in this precise order.
Closure (5-10 minutes) - Reflection and Remixing
- Once the students have a working song, challenge them to think like music producers. How could they change the tempo?
- Pose the challenge: “What if we want to play the song faster or slower?” Use this question to lead into a discussion about how changing every single delay value can be tedious, setting the stage for more advanced concepts like variables. Use the final section to guide the conversation.
Reflect
You’ve coded a song, but what if you wanted a remix?
To change the tempo, you need to adjust the delays. Right now, your song uses pauses of 200, 400, and 600 milliseconds.
What if you wanted to play it twice as fast? You’d have to go back and change every single delay block by hand. That sounds like a lot of work! Is there a smarter, more efficient way to control the speed?
How do devices produce sound?
Ever wonder how your phone can blast your favorite tunes? The magic happens in a tiny component called a speaker. Think of it as a device that converts electrical signals into sound waves. A magnet and a coil inside move when electricity passes through them, causing a cone to vibrate. These vibrations create the sound waves that travel through the air to our ears. Our brain interprets these waves as music, voices, or sound effects, allowing us to enjoy a movie or sing along to a song.
Speakers are everywhere!
You can find speakers in all sorts of devices! They’re in your TV, inside your headphones, and of course, in your smartphone. If you’ve ever watched a video or listened to music on your phone, you’ve heard its speakers in action.
Let’s Play a Song
We're going to create a prototype that plays 'Happy Birthday' on the phone. First, let's connect our device.
1
Click on ✙ Add device on the left sidebar.
2
Select the component MusicalKeyboard to play notes on the smartphone.
3
Scan the ▣ QR code with your smartphone or press Open in this window.
Drag the notes!
To build a melody, you need to drag the note blocks into the workspace in the correct sequence.
How to control the duration of a note?
We use delays!
A melody isn’t just about notes; it’s also about rhythm. To control how long a note plays, you need to add a pause before the next one starts.
For example:
- play a note
- wait 400 milliseconds
- play the next note
- wait 200 milliseconds
- … and so on.
Pro Tip: The delay blocks that control these pauses are found in the Timing category. They are essential for creating the rhythm of your song!
What is the sequence of notes and delays?
The main part of “Happy Birthday” has this sequence of notes with their respective delays, measured in milliseconds (ms).
Code Composition
Click on the question mark icon to open the comments that explain the code.
Reflect
You've coded a song, but what if you wanted a remix?
To change the tempo, you need to adjust the delays. Right now, your song uses pauses of 200, 400, and 600 milliseconds.
What if you wanted to play it twice as fast? You’d have to go back and change every single delay block by hand. That sounds like a lot of work! Is there a smarter, more efficient way to control the speed?