S C R A T C H C O D I N G Experiencing the LED SENSOR ‘If’ phrase Make the script below With this code, the led sensor will turn on if you close the left button sensor. The led sensor will turn off if you close the right button sensor. Is the left Yes button sensor Yes, turn off LED pressed? wait 1 sec No Is the right button sensor pressed? Yes Yes, turn off LED wait 1 sec If you cover both of the sensors, the led sensor will start flashing.
52 S C R A T C H C O D I N G K Logic CLASS 2 boost Sound sensor SONG GENERATOR LESSON 5 I T
S C R A T C H C O D I N G Introduction What is the sound sensor (song generator)? The piezo buzzer is a small speaker that makes sound using a piezo effect. The piezo effect is also known as the piezoelectric effect and uses characteristics of crystal or ceramic. When pressure is applied, it causes changes and voltage occurs on the surface. And in opposition, it condenses or increases if voltage is given. And if a think board is placed on it, the vibration makes the sound we hear.
54 CLASS 2 Connecting to the main cell What is the sound sensor? Using the sound sensor, we can produce a sound that robots make. W R B “S” = White “+” = Red “-” = black Connect the sound sensor to port 12 (digital output port 11).
S C R A T C H C O D I N G Experiencing the sound sensor coding Turning the Sound Sensor On/Off The sound sensor is controlled by the main cell that sends digital signs. Drag the ‘Digital output on’ and ‘Digital output off’ blocks to the script and change Digital 13 to 11 (Digital output port 11 is used as the output port).
56 CLASS 2 Experiencing the sound sensor coding Making an alarm You are going to use what you have learned to make the sound sensor turn on the saved music and turn off every 5 seconds. Draw an outline of how to make the Scratch code. Start the code! Did the alarm work? If it didn’t, check the code below and find out what was wrong.
S C R A T C H S C R A T C H C O D I N G C O D I N G K I K I T T Logic boost Pelicana robot LESSON 6
58 CLASS 2 exercise Pelicana robot Make a model using the button and the sound sensor we learned about before. The name of this model is Pelicana robot. It looks like a pelican, and it can move its wings up and down using a DC motor. Though, it can’t really fly. We are going to make it move by combining a input sensor-button sensor, a output sensor-sound sensor, and a DC motor. Let’s make the wings flap and play music from the sound sensor whenever the button sensor is pressed.
S C R A T C H C O D I N G exercise Pelicana robot Make the pelicana robot.
60 exercise CLASS 2 1 1-1 1-2 2 1 x1 x2 3 2 1 2 x2 x2 3 x2 x2 1-3 Make two of these.
S C R A T C H C O D I N G exercise 2 Assemble at a 45 degree 2-3 2 Figure 2-3 x1 A 64 x2 1 x2 1 1 1 x2 3-1 A 45 x1 A 45 3-2 x2 x2 A 45 x1 A 45 x1 Figure 3-1 Figure 2-4 x1 4 A 64 x2 x4 3 2-4 2 4-1 4-2 2 1 2 x1 x1 4-3 x2 x1 Figure 4-1 x1 4-4 x1 x1 Figure 4-3 A 23 x1 x2 x2 A 23 x2 Figure 4-2 K I T
62 exercise CLASS 2 4 4-6 4-5 Figure 4-4 Figure 4-4 Figure 3-2 Figure 3-2 5 5-2 5-1 1 2 x1 x1 x1 x1 x1 5-3 5-4 A 45 x1 Figure 5-3 1 x1 x1 Assemble location x1 A 45 Figure 5-1 5-5 x1 2 x1 1 x1 Figure 5-2 2 x1 x1 x1 Figure 5-4
S C R A T C H C O D I N G exercise 6 6-1 6-2 x1 x1 2 1 x1 x1 x1 x1 6-3 6-4 A 45 Figure 6-2 1 x1 Figure 6-1 2 x4 x1 7 x1 x1 Figure 6-3 x1 A 45 7-1 7-2 Figure 4-6 x2 x1 1 2 Figure 6-4 x1 7-3 Figure 7-1 Figure 5-5 7-4 x4 Figure 7-1 Figure 5-5 Figure 7-2 Figure 4-6 K I T
64 exercise CLASS 2 8 8-1 8-2 2 x2 x2 x1 x1 x2 x1 x1 x1 x2 8-3 1 1 8-4 x2 x2 Figure 8-1 Figure 8-2 Repeat the same step twice on the opposite side 8-5 8-6 Figure 7-4 Figure 8-4 9 9-1 x1 x1 x1 x3 x1
S C R A T C H exercise Complete Think Box 9-1 C O D I N G K I T
66 CLASS 2 exercise Coding Pelicana robot Try coding the robot by yourself. When you press the button sensor, DC motor and sound sensor have to operate. If you don’t press the button sensor, it stops moving. Make a script using the ‘If..or else..’, sensor output, and DC motor activation blocks.
S C R A T C H C O D I N G Explanations Pelicana robot Look at the flowchart. When the program starts, the DC motor has to operate and the digital output should be turned on when the button sensor is pressed. The program should keep checking if the switch was pressed or not. Start the program Turn on motor 4 Yes No Turn off motor 4 Is the button sensor pressed? Turn on digital Yes No 10 output Turn off digital 10 output Do you remember what we learned in using the button sensor? First, ‘if..
68 CLASS 2 Explanations Pelicana robot Let’s make a script that makes the DC motor turn on whenever the button sensor is pressed. Refer to the boxing robot script! The script above will activate the DC motor when the button sensor is pressed. Now, should we add ‘digital output on/off’ here? Pelicana will move its wings and make a noise when the button sensor is pressed. Furthermore, it can make various movements using the output sensor! Let’s make some changes in its movement. Go to the next page.
S C R A T C H C O D I N G Explanations Coding the Pelicana robot Let’s change the robot’s movement. Before, it started moving its wings when the button sensor was pressed. Now, we are going to make the DC motor rotate clockwise when the button is not pressed and counter-clockwise when the button sensor is pressed.
70 CLASS 2 Explanations Pelicana robot Were you able to make the script? If it didn’t work very well, check out the script below. When the button sensor is not pressed, the DC motor rotates clockwise and the digital 10 output should be off. When the button sensor is pressed, the DC motor rotates counter-clockwise and digital 10 output should turn on. Now, code the robot so that it moves in any way that you want! Try using different blocks to produce different movements.
S C R A T C H S C R A T C H C O D Logic boost Servo Motor LESSON 7 I N G C O D I N G K I K I T T
72 CLASS 2 Motor intro Introduction to a servomotor In this lesson, we will learn how to use a servomotor Compared to the DC motor we have been using, a servomotor moves at an exact angle. Let’s see how they are more different. As you know, the DC motor is an electric motor that provides energy by rotating. On the other hand, a servomotor acts like a human hand, making small movements. It is used to carry out detailed tasks.
S C R A T C H C O D I N G Connecting the Servomotor Connecting the Servomotor Before using the servomotor, connect it to the main cell using a 3-pin connector. B R W B R W Connect the servomotor with the cable like above. Conncect it so that the white cable is the closest to the servomotor’s white bump. For the servomotor to work correctly, a special cell called servo cell has to be connected to the motor.
74 CLASS 2 Exercise servomotor coding Activating the servomotor Let’s go to Scratch and activate the servomotor. Click the ‘movement’ tab and drag the block (shown below) to the script. This block is to control the servomotor. As mentioned before, servomotor moves in a certain angle. The servomotor will move at a 180 degree angle when the block is clicked. 0 180 You will see the red servo cell rotate when the block is clicked. The servo motor moves at a 180 degree angle.
S C R A T C H C O D I N G Exercise servomotor coding Activating the servomotor Using these blocks, we can see the direction of the servomotor. Like you see above, let the pointer of the servomotor point at a 0 degree angle. If you can’t do it, take off the red cell and put it back so that it can point at a 0 degree angle. Let’s make a simple program using the servomotor. This program lets the servomotor start at a 0 degree angle and go back to 0 after moving at certain different angles.
76 Exercise servomotor coding CLASS 2 Activating the servomotor You can see the servomotor move like the picture 0 90 90 0 180 180
S C R A T C H C O D I N G How to Make a Robot Making catchbot We will learn about the servomotor by making a catchbot that uses it. Tip: Set the servomotor angle to 180 degrees. It would be easier to make the robot since the tongs will be opened.
78 How to Make a Robot CLASS 2 Making catchbot 1 2 x1 x2 x2 x1 Figure 1 3 4 x1 x1 x1 x1 x1 x1 x1 5 x1 Figure 3 x1 Figure 4 6 Figure 4 Figure 5
S C R A T C H How to Make a Robot Making catchbot 7 8 x1 x2 x1 x1 x2 x4 x2 x2 9 x1 x1 x1 x1 x1 x2 10 x1 x1 x1 x1 11 Figure 10 Figure 9 Figure 8 Figure 7 C O D I N G K I T
80 CLASS 2 How to Make a Robot Making catchbot 12 12 13 13 1Figure 1 11번모형 Figure 6 x1 x1 x1 6번모형 x1 x2 완성 Complete I have tongs too! 저도 집게가 있어요! x2
S C R A T C H C O D I N G Experiencing catchbot coding Coding Catchbot Code so that the catchbot can hold an object. The catchbot you just made can open and close its tongs. Let’s see how the catchbot program will work by looking at the flowchart below.
82 CLASS 2 Experiencing catchbot coding Coding Catchbot When the blocks are connected, it will look like the ones shown below. 12 13 11번모형 완성 x1 6번모형 x1 Check out how the angles change. Depending on the user, the angles can be different. x2 Keep activating the program. You will see the tongs you made open and close! Using the catchbot, try holding an object like a tire from the robotory coding class kit.
S C R A T C H C O D I N G Experiencing catchbot coding Application of catchbot Add blocks to slightly change the program. Remember the angles are different for different users. Play a game with your friends. Draw a circle and try to move some objects into the circle. The winner is the one who does this the fastest without dropping any. After the game, change the start block so that you can control the catchbot using the keyboard. Refer to the example below.
84 S C R A T C H C O D Logic CLASS 2 boost DEBUGGING LESSON 8 I N G K I T
S C R A T C H C O D I N G Intro to debugging What is debugging? Debugging is important in learning a program. Debugging fixes program errors like fixing mistakes in a class project. Sometimes, a computer might not recognize the code you made and the program won’t start at all. Debugging finds the errors of a program and fixes them so the program will start correctly. 50 years ago, a computer was big enough to fill up a whole room! The word ‘debugging’ was made by Grace Hopper in US navy.
86 How to Make a Robot CLASS 2 Tongs robot Now you will learn how to debug using the tongs robot. First, let’s make the robot. Before starting, set the servomotor angle to 180 degrees. It’s due to the same reason with the catchbot before. Materials needed for tongs robot.
S C R A T C H C O D I N G How to Make a Robot Making the tongs robot 1 Make two of these. 2 x2 Figure 1 x2 x2 x2 Figure 1 3 Make two of these.
88 CLASS 2 How to Make a Robot Making the tongs robot 7 8 x1 x1 x1 x1 x1 x1 9 10 x6 x1 x3 x1 x1 x2 11 12 Figure 11 Figure 9 Figure 10 Figure 8
S C R A T C H How to Make a Robot Making the tongs robot 13 14 Figure 6 Figure 12 Complete x1 x1 x2 Figure 5 Figure 13 C O D I N G K I T
90 Coding the tongs robot CLASS 2 Understanding the tongs robot code It’s important to imagine how you will operate the program after looking at this code. Check out the code below. close tongs Wait 2 sec Open tongs Wait 2 sec Move forward Wait 1 sec This program lets the tongs robot open and close the tongs. Learn what each block Stop Program finish represents looking at the flowchart.
S C R A T C H C O D I N G Coding the tongs robot Understanding the tongs robot code Make the program below. This time you can fill out what each block does in the flowchart. Before starting the program, fill out the blanks to the left. What does each block do? Wait 2 sec Wait 1 sec Wait 1 sec Did it work? If it did, move onto the next page. If it didn’t, check the code again and think about how you can operate the code differently.
92 CLASS 2 Coding the tongs robot Understanding the tongs robot code Make the program below. Fill in the blanks of the flowchart, too. Wait 1 sec Wait 1 sec Wait 2 sec Did it work? If it did, move onto the next page. If it didn’t, check out the code and think about how you might be able to operate the code.
S C R A T C H C O D I N G Coding the tongs robot Understanding the tongs robot code Make the program below. Fill in the blanks of the flowchart too. The last block might be a bit hard. Wait 2 sec Wait 1 sec Wait 1 sec Did it work? If it did, move onto the next page. If it didn’t, check out the code again and think about how you might be able to operate this code.
94 CLASS 2 Tongs robot and Debugging Debugging the tongs robot If you understood how the code works before, let’s see a code with some errors. The flowchart is made with correct orders in sequence. Open tongs But, the code below has some errors. Read it through and let’s find out what they are. Wait 2 sec This block opens the tongs Move forward Wait 1 sec The flowchart tells the robot to move forward. But, the code is not telling it to move forward.
S C R A T C H C O D I N G Tongs robot and Debugging Debugging the tongs robot If you understood how the code worked before, let’s see a code with some errors. The flowchart is made with correct orders in sequence. Open tongs But, the code below has some errors. Read it through and let’s find out what they are. Wait 2 sec Move forward This value has to be changed Wait 1 sec Stop Wait 1 sec Type in an angle at which the tongs are Close tongs Program finish closed.
96 CLASS 2 Tongs robot and Debugging Debugging the tongs robot Now, try debugging the code by yourself. Make the program you see below and fix the problems by referring to the flowchart on your left. Open tongs Did you find the errors? If you don’t, start the program and see where Wait 2 sec you find the problems. Close tongs Wait 2 sec Open tongs Wait 1 sec Write down what the errors are and how Close tongs Program finish they should be fixed on the next page.
S C R A T C H C O D I N G Tongs robot and Debugging Debugging the tongs robot Program debugging journal K I T
98 Tongs robot and Debugging CLASS 2 Debugging the tongs robot Check out the second example. Make the program you see below and fix the errors by referring to the flowchart on your left. Move backward Did you find the errors? If you didn’t, start the program and see where you Wait 0.5 sec find the problems. Open tongs Wait 0.5 sec Move forward Wait 0.5 sec Write down what are the errors and how they should Stop be fixed on the next page. The whole script can be found at http://www.robotori.
S C R A T C H C O D I N G Tongs robot and Debugging Debugging the tongs robot Fix the program errors in the space to the right. Pay attention to the DC motor’s port numbers.
100 Tongs robot and Debugging CLASS 2 Debugging the tongs robot Check out the third example. Make the program below and fix the errors referring to the flowchart on the left. This one can be a bit tricky. Move forward and open tongs Did you find the errors? If you couldn’t, start the program and see where the problems Wait 1 sec are. Stop Wait 1 sec Move forward and open tongs Wait 1 sec Stop Write down what the errors are and how they should be fixed on the next page.