[No.11] A Party Light That Moves with the Music!!

Programming and Making

When you have a party at home, playing music sets the mood. But if you want to liven things up even more... how about some light effects? Still, buying a party light you'd only use once in a while doesn't sound great. That's exactly when you should invent one with SPACEBLOCK!

Elementary School ~ Intermed. 45 min
The light changes along with the music

For this invention, we'll use the "Microphone Sensor Module" and the "8×8 RGB LED Matrix Panel." Let's make a party light whose effects change automatically with the music!

What You Need & Getting Ready

Top left: SPACEBLOCK Standard Package. Top right: LED panel. Bottom left: mic sensor. Bottom right: jumper wires

Connect the Add-On Parts to SPACEBLOCK

First, let's connect the LED panel and the mic sensor we're using this time to SPACEBLOCK.


How everything is connected

For the details, look at the next picture. Check carefully where to plug in the 3 jumper wires coming from the mic sensor's "G," "V," and "S."

Pay attention to the pin socket positions when you connect them

What Can the Mic Sensor Do?

The mic sensor can measure how loud a sound is. Silence is 0, and the louder the sound, the bigger the number. Measuring how much of something there is, like loudness, and sending it to the program as a number is called analog input.

The mic sensor raises or lowers the voltage on the pin plugged into SPACEBLOCK depending on how loud the sound is. That voltage is turned into a number from 0 to 1023 and passed to the program.

The mic sensor sends the loudness to the program as a number

Let's Check the Mic Sensor's Values

To use the mic sensor's value in a program, use the [Read analog voltage of (A0)] block in the "Input" category. Combine it with [Repeat] and [Show number (0)] and build the program as in the next picture.
Use the analog read block in your program

Run the program, and the mic sensor's values appear in the console. You can see how the value changes when it's quiet and when music is playing.

When you run this program, values keep appearing in the console

Let's watch it in the video. You can see the value goes up when music plays.

The mic's sensitivity is adjusted by turning a small knob on the mic sensor, called a potentiometer, with a screwdriver. The sensitivity changes what number you get for how loud a sound is. This time, we adjusted it until it showed a steady 0 when no music was playing.
Turn the sensitivity potentiometer gently, only as far as it turns easily

Change the LED Panel's Brightness with the Music!

First, let's make a program that changes the LED panel's brightness with the music. Here's how it works: we use the mic sensor's value to set the LED panel's brightness, so the brightness changes with how loud the sound is.

First, to make the mic sensor's value easier to use in the program, create a "variable." A variable is a container that can hold a value, and you can give it any name you like. Using the next picture as a guide, make a "Number" type variable named "sound."

Create the variable "sound"
Next, use the variable you made to build a program that changes the LED panel's brightness, as in the next picture. It puts the mic sensor's value into the variable "sound," shows "sound" in the console, and sets the LED panel's brightness to "sound."
A program that changes the LED panel's brightness with how loud the sound is

Like the mic sensor's value in this program, when you use the same value two or more times, put it in a variable.

Now the brightness changes with how loud the sound is.

Using the Mic Sensor's Value for the LED Panel's Brightness

You can set the LED panel's brightness from 0 to 100%. If the mic sensor's values are between 0 and about 100, they're a perfect fit for setting the LED panel's brightness.

But the mic sensor's values depend on its sensitivity and on how the music is played. If the values cover a wide range and you mostly get values over 100, you can shrink them by a fixed ratio with a calculation to get numbers that work for brightness.

In the next example, when the mic sensor's value is put into "sound," it's multiplied by 0.5, which cuts it in half.

Let's watch this program running in the video. You can also see the program running on the computer screen.

Make the Effects Even Flashier!

Besides the brightness, let's also change which LEDs light up and what colors they are. Depending on the value of the variable "sound," which holds the mic sensor's value, we'll change what the LED panel shows as in the next picture. It will look like a volume meter going up and down.


Plan what to show for each range of values

Let's build the program. First, here's the same program as before.

The first part of the program. We'll continue from here

Next, we'll build a program that runs different instructions depending on conditions. Use the [if ( ) then ... else ...] block in the "Logic" category.

After "if ( ) then," you can add more conditions with "else if ( ) then"

Use the [if ( ) then ... else ...] block to split the instructions into 5 levels. Put the [(0) (=) (0)] block from the "Logic" category into each condition of the [if ( ) then ... else ...] block, and set the expressions and numbers as in the next picture.

The conditions split the loudness into 5 levels
Add the LED panel display settings after each condition and finish the program as in the next picture.
The party light program, with effects that change with how loud the sound is

It's finished!
Let's run the program.

It works great!
QR code for project

Make It Look Like a Real Light

It looks a little plain like this, so let's transfer the program to SPACEBLOCK in standalone mode and put it in a see-through box so it looks like a real light.

Just put it in any box like this!

A see-through box spreads the light so it looks beautiful. Place the LED panel where it will look the flashiest

You can set your smartphone right on top.


The finished party light. It looks neat and tidy

Let's watch it in the video.

First, in a slightly bright place.

And here it is in the dark!
It lights up in a really flashy way and gets everyone in a party mood.
It lights up so brightly that the whole room glows

Both the brightness and which LEDs light up change with the mic's volume, so it feels really dynamic.


Along with the brightness, the LEDs' colors and positions change

Try lots of songs and see which ones work best. Changing the colors and light patterns gives it a whole different feel. Customize it however you like to match your music and party mood!!

We thought, "It'd be nice to have a party light..." and ended up inventing our very own. Keep taking on making projects that turn the things you "want" into reality!!