[No.17] A Frog That Talks for You, Ribbit!

Programming and Making

Summer vacation is almost over! We're still wearing masks in public places, and it's a little sad that we can't see each other's mouths when we talk. Let's build a device that flaps its mouth along with your voice to keep the conversation fun and cheerful!! Some of you might even just make it in time for your summer vacation project!?

Elementary School ~ Intermed. 80 min
Here's the "Frog That Talks for You!" we'll build this time. It's fun to make it as another animal, too!

What You Need & Getting Ready

Top row, from left: SPACEBLOCK Standard Package, mic sensor module. Bottom row, from left: 180° micro servo motor, jumper wires

Connect the Expansion Parts to SPACEBLOCK

First, let's connect the mic sensor and the servo motor to SPACEBLOCK.


The whole setup

Check the details of the connections in the next picture.

Watch the pin socket positions when you connect

The device we're building reacts to the sound of talking and flaps the frog's mouth. The mic sensor is the input device that measures how loud the voice is, and the servo motor is the output device that moves the frog's mouth.

Craft a Frog That Moves with a Servo Motor

First, let's make the frog craft. A servo motor can turn anywhere from 0° to 180°. This time, we planned a way for the servo to open the mouth by turning it between 0° and 90°.

Put the frog together for a test fit

First, let's look at what it will look like, test-fitted without any decorations. The servo motor moves the lower jaw part.

The lower jaw is designed to move with the servo motor between 0° and 90°

Let's go through it step by step.

For the mouth, make the parts from cardboard as shown in the next picture. Glue a straw or something similar onto the servo horn to make it longer. Attach the servo motor body and the servo horn to their own parts. When you test-fit, it's best to hold things together with tape that peels off easily.

The mouth is made of 3 parts

Put the parts together as shown in the next picture and fix them in place to make the mouth. Prepare a separate face-shaped part.

Check carefully where to glue

Attach the mouth to the face-shaped part so it stands straight out. When the servo motor is at 0°, the mouth is closed. At 90°, the mouth is open the widest.

Be careful: if there aren't gaps in the right places, it won't move smoothly

That finishes the test fit. Check that the lower jaw moves smoothly with the servo without catching on anything. If you program and test it while it's test-fitted, you can fine-tune the craft even more.

Here, we'll keep going and finish the craft.

Decorate and finish the craft

Take the test-fitted parts apart, decorate them, and put everything together for real. We glued colored construction paper that suits each part.

Just adding bright construction paper makes it look much more like a frog

Fix the mouth parts in order, then glue them onto the face.

Now the craft is finished! Attach a string or something similar to the back so you can hang it on a wall.
If you hide the SPACEBLOCK board and other parts inside your craft, be careful not to cover the microphone on the mic sensor

Now let's get to the most important part: the program!

How to Use the Mic Sensor and Check Its Values

In the program, the mic sensor first measures how loud the sound is. How to use the mic sensor is explained in detail in "[No.11] A Party Light That Moves with the Music!!," so here's a quick review.

The louder the sound, the bigger the mic sensor value. The quieter the sound, the smaller the value. You can adjust the microphone's sensitivity by turning the potentiometer on the sensor with a screwdriver.

When adjusting the sensitivity, only turn it as far as it moves easily

You can check the mic sensor value with the [Read analog voltage of (A0)] block in the "Input" category. Check how loud a sound gives what number.

This time, we tested by actually talking from a comfortable distance, and adjusted the sensitivity so it doesn't react too much to small noises and mostly gives values from about 0 to 180.These values change depending on where you are, so write down how high the values go, starting from 0.

A Program That Sets the Servo Angle Based on the Volume

Once you've checked how the mic sensor works, let's build the program. Here's the program for this project. It's really short!
The finished program

Let's go through the program from the top.

First, set the servo motor's starting angle to 0°. At 0°, the mouth is closed. Run just this part of the program to set the servo to 0°, then attach the lower jaw part to the servo motor so the mouth is closed.

Next, add a variable named "sound".
Inside the [Repeat] block, make a program that puts the mic sensor value into the variable "sound".
Next, set the servo motor's angle. Calculate the angle from the mic sensor value stored in the variable "sound", so the louder the sound, the wider the mouth opens. When we tested the mic sensor earlier, we adjusted it to give values from 0 to 180. The servo motor that moves the lower jaw moves between 0° and 90°.Half of the mic sensor value fits the servo motor angle perfectly, so set the servo angle to the variable "sound" multiplied by 0.5.

That finishes the program! It keeps reading the mic sensor value and changing the servo motor angle over and over, so while the power is on, the mouth always moves with sound.

By the way, when you tested the mic sensor values, many of you probably couldn't adjust the range to 0–180. If so, check out the "Challenge!" below. You just need to change the calculation a little!

Challenge!
This time, we converted mic sensor values of 0–180 into servo angles of 0°–90° with a calculation. As a diagram, it looks like this.
In this case, it was easy to see that we just had to halve it, but it's not always that simple. For example, if the mic sensor values went from 0 to 350, how would you calculate the servo angle?
That's when the next formula comes in handy. We won't explain it in detail here, but once you learn about "ratios" in math class, you'll understand why this calculation works. If you want to know the secret of the formula, ask someone who's good at math!
Built with program blocks, it looks like the next picture. Just build the right side of the formula above (the part to the right of "=") and put it where you set the servo angle. Remember, the mic sensor value is stored in the variable "sound."
With this formula, the whole program looks like the next picture.
When you write a program, it's best to make it work even if the conditions change a little. With this program, you can quickly adjust it to match the values your mic sensor gives.Show the mic sensor values in the console and fine-tune while checking them.
QR code for project
Once you've written the program to SPACEBLOCK, start talking!The frog flaps its mouth with the timing and loudness of your voice, which is really fun.
Watch the video!
A person is talking, but it looks like the frog's movements are in sync!
It's also fun to say lines as if the frog is the one talking!
If you leave it switched on in your room, fun conversations become even more fun. And even when you're talking in a bit of a bad mood, one look at the frog will make you think, "Oh well, never mind." Now talking with masks on, when nobody can see your mouth, is more fun too!!!