[No.6] Add an Output Part: An "Okaeri" Device That Plays Sounds

Programming and Making

With SPACEBLOCK, the tiny computer for making things, you can add all kinds of parts and create your own features. This time, let's add one output part and make a device that plays sounds. We'll upgrade the "okaeri" (welcome home) display you made in [No.5].

Elementary School ~ Beginner 20 min

SPACEBLOCK Has Lots of Add-On Parts!

Add-on parts made just for SPACEBLOCK are going on sale one after another. Here are some of them, including ones coming soon... Look how many there are!
Some of the add-on parts made for SPACEBLOCK

There are parts you can use as all kinds of input and output devices, which makes things even more exciting. For example, you could use an "Ambient Light Sensor Module" as an input to make a device that reacts to brightness, or use a "180° Micro Servo Motor" as an output to make something that turns.

You can buy SPACEBLOCK and its add-on parts on the SPACEBLOCK website, so take a look. This time, we'll use two parts that are already on sale: the "8×8 RGB LED Matrix Panel" (LED panel) and the "Piezoelectric Speaker".

What You Need & Getting Ready

Top left: SPACEBLOCK Standard Package. Top right: LED panel. Bottom left: piezo speaker. Bottom right: jumper wires

Connect the Add-On Parts to SPACEBLOCK

First, let's connect the LED panel and the piezo speaker we're using this time to SPACEBLOCK.
How everything is connected

For the details, look at the next picture. You can plug the LED panel straight into the sideways pin socket, but this time we'll use jumper wires to make it easier to handle. Be careful to connect the 3 wires exactly as shown. For the piezo speaker, check the colors of the red and black wires and plug them into the blue pin socket as shown.

Pay attention to the jumper wire colors and the pin socket positions when you connect them
Fun Fact
Each end of a jumper wire is either a "pin header" or a "pin socket." There are 3 kinds depending on what's on each end, so choose the one that fits where you want to use it. SPACEBLOCK's "20 cm Jumper Wire Set" comes with 40 of each of the 3 kinds.

How Do You Program the Piezo Speaker?

The blocks for programming the piezo speaker are in the [Output] category. Let's try the [Play (Middle C) on (A0 (T2)) for (1000) milliseconds] block.
Sound blocks are in the "Output" category

Click the pin socket name on the block to see a list, with 4 pin sockets highlighted. To use the piezo speaker, connect the red jumper wire to one of these 4 pin sockets, and the black wire to a pin socket labeled "GND."

Check the names and positions of the pin sockets you can connect to

This time we'll use "GND" and "A0 (T2)" on the blue pin socket. Choose "A0 (T2)" in the [Play (Middle C) on (A0 (T2)) for (1000) milliseconds] block.

Choose the name of the pin socket you plugged the jumper wire into
Fun Fact
"GND" stands for "ground." When you connect an add-on part, always connect one jumper wire to "GND." Electricity flows from plus to minus, and "GND" is the minus side. It's needed to make a path for the electricity. It doesn't matter which "GND" you use, and you don't choose it in the program blocks.
If you program it as in the next picture, it plays C, D, and E (do, re, mi) for 1 second each. The [Play (Middle C) on (A0 (T2)) for (1000) milliseconds] block plays the sound for the time you set, and moves on to the next block only after the sound ends. So you don't need to put a pause between sounds when you play them in a row.
A program that plays C, D, and E for 1 second each
Try It!
Leave the black jumper wire in "GND," move the red wire to "B0 (T3)" on the yellow pin socket, change the program to [Play (Middle C) on (B0 (T3)) for (1000) milliseconds], and run it. It works exactly the same way.

Add Sound to the "Okaeri" LED Sign

Now let's upgrade the program for the "okaeri" LED sign you made in [No.5]. The next picture shows last time's program, which shows "okaeri" when you press the button.
A program that shows characters on the LEDs when you press the button

Let's add to the program so a sound plays with each character. As in the next picture, after each [RGB LED (A10): light up] block that shows a character, add a block that plays E, C, D, or G (mi, do, re, sol) for 1000 milliseconds. A character appears, the sound finishes, and then it moves on to the next character.

The program with sound effects added

Now you have an LED sign that plays sounds. Let's watch it in the video. We added a sound effect that sounds like a door chime.

QR code for project
By adding sound to the LED display, the output got a little livelier. But now we want the device to start with some other trigger instead of a button press... Next time, let's add an input part and upgrade it even more!