[No.18] Punch the Bear for a KO! A Get-Moving Machine

Programming and Making

Fall is a great season for eating, reading and sports... but lots of people enjoy eating and reading and keep putting off exercise, right? Let's build "Punch the Bear for a KO!", a machine that keeps you motivated so you can stick with a little exercise every day instead of giving up after three days!!

Elementary School ~ Advanced 80 min
Here's the "Punch the Bear for a KO!" machine we'll build this time. Change your punching target to whatever gets you most motivated!

What You Need & Getting Ready

Top row, from left: SPACEBLOCK Standard Package, LED panel. Bottom row, from left: obstacle avoidance sensor, 180° micro servo motor

Connect the Expansion Parts to SPACEBLOCK

First, let's connect the obstacle avoidance sensor, servo motor and LED panel to SPACEBLOCK.
The whole setup

Check the details of the connections in the next picture.

Watch the pin socket positions when you connect

The machine we're building uses the obstacle avoidance sensor as the input device to detect a punching hand coming close. The servo motor and the LED panel are the output devices. The servo motor moves the bear, and the LED panel shows what's happening.

Make the Bear and Other Craft Parts

First, let's get the parts ready. The star of this machine is the bear you knock down with a punch. Cut a bear shape and a grass shape (to hide the front) out of cardboard, and get a long stick to attach to the servo motor.
Decorate them with colored paper. How scary you make it is up to you!
Attach the servo motor to the case that will be the base. There's a hole so the obstacle avoidance sensor can be mounted later, facing out from the inside.
Set it up so the stick falls backward when the servo motor goes from 0° to 90°

Stick the bear on the long stick and the grass on the front of the case, and it really starts to look the part!

At this point, it's easier if you make the program and fine-tune things before moving on, but here we'll keep going and finish the whole machine.

Take the grass decoration off for a moment, and put the SPACEBLOCK and everything else inside the case. Use the photo as a guide to fix the obstacle avoidance sensor and the LED panel on the inside, and pass the servo motor's jumper wires through the hole to the inside.

Close the lid and it looks like this. Hide the servo with the grass part, and you're done.
Now it's finally time to work on the program!

How to Use the Obstacle Avoidance Sensor and Read Its Values

The program uses the obstacle avoidance sensor value. How to use the obstacle avoidance sensor is explained in detail in "[No.10] Invent a Trash Can That Opens by Itself!", but this time we use a different block, so let's do a quick review.

The obstacle avoidance sensor can use infrared light to detect whether there's an obstacle within a certain distance. It only sends two kinds of information, whether there "is" or "isn't" an obstacle, so it's a digital input.

When there's no obstacle, the obstacle avoidance sensor raises the voltage on the pin it's plugged into and sends the value true to the program. When there's an obstacle, it lowers the voltage and sends the value false.True and false are called Boolean values, and they're used in conditions. In the program, use the [Read digital voltage of (A0)] block to get the value.

The obstacle avoidance sensor gives the Boolean values true and false

To set the detection distance, turn the potentiometer on the obstacle avoidance sensor with a screwdriver. We want it to react to a punch, so if the distance is too short, you might end up punching the machine itself by accident. Set it to react from a bit of a distance.

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

A Program That Knocks the Bear Down When a Punch Comes

Using the obstacle avoidance sensor value, let's make a program where a punch knocks the bear down, as shown in the next picture.It keeps checking the obstacle avoidance sensor value, and when it detects a punching hand, it moves the servo motor from 0° to 90° and then back to 0°. The LED is usually blue, and turns red when a punch is detected.
A program where the bear falls down and gets back up when a punch is detected

[if ( ) then … else …] The condition of this block is set to the obstacle avoidance sensor value. The obstacle avoidance sensor value is a Boolean value, true or false. If a Boolean value is true, the condition is met. If it's false, the condition is not met.

Now we have a bear that falls down when you punch it. To get you even more motivated to exercise, let's add a way to count your punches.

Count Your Punches

To count, create a new variable named "count."
Add to the program so that the variable "count" goes up by 1 with every punch. The count is shown in the console.
Add the counting program

If you take the current value out of a variable, add 1, and put it back into the variable, the variable goes up by 1 every time it repeats. This is handy when you program things like counting or keeping score, so remember it!

Now we can count, but showing the count in the console means you can't see it when you're using the "Punch the Bear for a KO!" machine. Let's add one more idea.

A Colorful Break Every 10 Punches

Getting encouraged often is important when you exercise. Let's add an easy-to-see effect every 10 punches. When the count reaches 10, the LED panel shows "10" and then plays a colorful animation.Then the count is reset to 0 so it can start counting from 1 again. The right side of the next picture is the part we added.
Add a program that runs only when the count reaches 10

That finishes "Punch the Bear for a KO!"

Once you've written the program to SPACEBLOCK, start punching! You can enjoy endless exercise with a break every 10 punches. Anything coming close to the sensor works, so it's OK to use high kicks instead of punches. If you put it lower, you can use it for high-knee exercises too!

QR code for project
When you punch, the obstacle avoidance sensor detects your hand and the bear falls down!

When you reach 10, take a short rest during the LED show. The count resets to 0, so keep going with the next 10!

Watch the video. It shows 2 sets of punches. Don't get so excited that you punch the machine itself!!
Just having the bear fall down makes it feel like you're really punching, so exercise becomes lots of fun! Punching and kicking are also a little stress reliever. The break every 10 punches feels just right, so give it a try!