[No.19] I Want to Use Lots of Sensors and LEDs!

Programming and Making

This time, we'll level up a bit and take on making a quick-press game! Until now, we've only used one LED panel or sensor at a time, but now we'll use more of them, and the program gets a little more advanced too. In this lesson, you'll learn how to connect lots of sensors and other parts to SPACEBLOCK at the same time, and we'll go all the way to building the game machine! The game program is in the next lesson, so check it out.

Elementary School ~ Advanced 105 min
Here's the quick-press game we'll make this time. Can you press the button that matches the color shown on the panel? Take the challenge!!

What You Need & Getting Ready

*Breadboards aren't sold on the official SPACEBLOCK website, but you can buy them at many shops as electronics crafting supplies.

Top row, from left: SPACEBLOCK Standard Package, LED panel. Bottom row, from left: obstacle avoidance sensor, piezo speaker, breadboard

Connect the Expansion Parts to SPACEBLOCK

First, let's connect 3 obstacle avoidance sensors, 2 LED panels and 1 piezo speaker to SPACEBLOCK. Each part has several jumper wires that need to be connected. Let's check how many wires there are and what each one does.
All jumper wires except the piezo speaker's can be detached, so the wire colors depend on which ones you choose
  • LED panel (3 wires): 5V power / GND / signal
  • Obstacle avoidance sensor (3 wires): 3–5V power / GND / signal
  • Piezo speaker (2 wires): GND / signal

*GND (ground) is the minus side, where electricity flows to after coming from the plus side. It's needed to make a path for electricity.
*The piezo speaker is powered through the same wire it uses for signals.

Each part has wires that need to be connected, but SPACEBLOCK only has a limited number of GND and power (5V, 3.3V) pin sockets.Let's check what each of SPACEBLOCK's pin sockets is for

.
There are 3 GND sockets, 2 5V sockets and 1 3.3V socket. The pin sockets starting with A, B and C are used for signals and similar jobs.

As it is, we can't connect all the parts. So we'll use a breadboard to add more pin sockets to connect to. A breadboard is a tool for building circuits easily in electronics projects. This time, we'll use it to add more 5V power and GND connections.

A breadboard. You'll use 1. This time, we use the plus and minus rows inside the red frame on the left. The parts shown in green on the right are connected to each other inside.

First, use jumper wires to connect SPACEBLOCK's "5V" pin socket to the breadboard's "+" row, and the "GND" pin socket to the "−" row. Now every hole in the breadboard's "+" row works as a "5V" pin socket, and every hole in the "−" row works as a "GND" pin socket.

SPACEBLOCK connected to the breadboard. Only the top 2 rows of the breadboard are used

Next, connect the parts that can go straight into SPACEBLOCK. Connect 1 LED panel and the piezo speaker.

1 LED panel and the piezo speaker connect straight to SPACEBLOCK

Next, connect the other LED panel and the 3 obstacle avoidance sensors.Connect the GND and power jumper wires to the breadboard, and the signal wires to SPACEBLOCK's pin sockets.

Diagram with all the parts connected. The wires going into the breadboard can be packed to the left with no gaps

It looks neat in the diagram, but here's a photo of the real connections. It's pretty messy, so it might surprise you a little! But if you check each wire one by one like in the diagram above, you'll be fine.

The whole setup. The jumper wires are extended to make the machine easier to build. Write down which pin socket each wire goes into
Close-up of SPACEBLOCK and the breadboard. The wires come out easily, so we reinforced them with masking tape where needed

Check That the Expansion Parts Work

Once you've gotten this far, check that the LED panels, piezo speaker and obstacle avoidance sensors work to make sure everything is connected correctly.

Check the numbers of the pin sockets where each part's signal wire is connected, and run a test program for the connections.

LED panels

  • LED panel ❶ → A10
  • LED panel ❷ → B10

[Test program example]

A program where pressing SPACEBLOCK's buttons PA8 and PA9 lights up each LED panel

Piezo speaker

  • Piezo speaker → A0

[Test program example]

A program where pressing SPACEBLOCK's button PA8 plays a sound from the speaker for 1 second

Obstacle avoidance sensors

  • Obstacle avoidance sensor ❶ → A1
  • Obstacle avoidance sensor ❷ → A2
  • Obstacle avoidance sensor ❸ → A3

[Test program example]

A program where holding your hand over an obstacle avoidance sensor lights LED panel ❶ in that sensor's color

Check the link below for how the obstacle avoidance sensor works and how to adjust its detection distance.


Here's how the "obstacle avoidance sensor" works and how to adjust it!

If something doesn't work, a connection is wrong somewhere. Before building the game machine or programming, make sure everything is connected correctly.

Materials and How the Game Machine Works

Next, let's build the game machine. You'll need a sturdy box such as a cardboard box, plastic cups, split pins, rubber bands, and colored paper (red, green and blue). A box with a lid makes the work easier.
It's OK to use 3 identical clear plastic cups

With these materials, you'll make buttons to press. First, let's explain how they work. As shown in the next picture, cut holes in the cardboard box that are a little smaller than the plastic cups, and use split pins and rubber bands to hold each cup so it's pulled up from below.Put an obstacle avoidance sensor inside the box. When you push a button in, the edge of the cup reaches the sensor's detection range and the sensor reacts.

How the buttons work. Craft buttons you can push in, and use the sensors to check whether they've been pushed

Build the Game Machine: The Craft Part

Make 4 holes in each cup...
Thread rubber bands through them.
Adjust the length of each rubber band and tie a knot so it doesn't slip out...
Cut a round hole in the box, just wide enough for a plastic cup to sink in about halfway. Put 4 split pins around the circle.
Hold a plastic cup with rubber bands against the hole from inside the box, and pull the ends of the rubber bands out to the top side.
Stick colored paper on the bottom of each plastic cup. Even clear plastic cups are fine, because this is where they get their color.
Hook the ends of the rubber bands on the top of the box onto the split pins. Adjust the length of the rubber bands so the cup is pulled up with just the right springiness.
Make all 3 colors the same way, and your 3 colored buttons are done!
Push them with your hand like this to check they have the right springiness.
Watch the video to see how the buttons move.

Build the Game Machine: Set Up SPACEBLOCK

Up to here it's a regular craft, but now it's time to build SPACEBLOCK into it. Put the SPACEBLOCK, with all the parts already connected, inside the box, and stand the obstacle avoidance sensors up where the 3 buttons get pushed in, and fix them in place.
The obstacle avoidance sensors face up

If anything is near the sensor part of an obstacle avoidance sensor, it will react, so be careful where you put them

Adjust the height of the obstacle avoidance sensors to match the height of the box and how far the plastic cups sink in.Adjust the detection distance so the sensor doesn't react when the button isn't pressed, and only reacts when it's pushed in.

 Here's how the "obstacle avoidance sensor" works and how to adjust it!


When adjusting the distance, only turn it as far as it moves easily. If the sensor is connected to SPACEBLOCK and the power is on, you can tell whether it's detecting an obstacle by the light

Then put the LED panels outside the box by sticking them onto a board.

That finishes the game machine.

Check How It Works with a Test Program!

Let's test the finished machine with the program below.Press the red button and LED panel ❶ lights up red. Press the blue button and it lights up blue. Press the green button and it lights up green. A sound plays each time.
QR code for project
Watch the video of the test.
Now we've finished a machine with colored buttons, LED panels and a speaker that you can control with a program.Just seeing the color you pressed light up feels kind of great, doesn't it? Next time, we'll finally make the game program!