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 angles of the servomotor.
102 CLASS 2 Tongs robot Applications Applying the uses of the tongs robot Make a program that moves the tongs robot towards the tire and moves it back with the tire. Put the tire 10 cm away from the robot. Make the program pay attention to the distance between the robot and tire. Using the flowchart, write down which movements it should have and code them in Scratch.
S C R A T C H S C R A T C H C O D Logic boost CDS SENSOR LESSON 9 I N G C O D I N G K I K I T T
104 CLASS 2 Introducing the sensor What is the brightness sensor? (CDS sensor) Now let’s find out the brightness sensor which is one of the robotory input sensors. The brightness sensor measures the amount of light. It’s also known as a light sensor. The value changes depending on the amount of light that goes into the sensor. We can produce different movements using the changing values on the light sensor. Side Above is the robotory brightness sensor. Look for one in the robotory materials.
S C R A T C H C O D I N G Connecting to the main cell Connecting the brightness sensor (CDS sensor) Now, we have learned about the brightness sensor. Let’s learn how to connect it to the main cell. Use the 3-pin connector like you see below. “S” = White “+” = Red “-” = black ※ If you don’t connect with the right cable colors, the sensor won’t work, so be careful! Connect the sensor to the main cell’s slot 7.
106 CLASS 2 Experiencing the Brightness sensor coding Using the brightness sensor Now, let’s see how Scratch shows the information that the sensor gives. Cover and uncover the connected sensor. If the brightness sensor is still, ‘Digital2’ will show ‘true’ If the sensor was covered, ‘digital 2’ will show ‘false’. If digital 2 is true, it means the light is shining through. If it is false, it means it’s dark with no light shining through.
S C R A T C H C O D I N G How to Make a Robot Using the brightness sensor Now, we are going to find out how to apply the brightness sensor to the program. First, let’s make our old friend, the windmill. You must be really quick in making the windmill now.
108 CLASS 2 Experiencing the Brightness sensor coding Usinig the brightness sensor with the windmill We are going to use the brightness sensor to operate the windmill. First, we need a way to bring ‘true’ and ‘false’ of the brightness sensor to Scratch. To do this, go to the ‘movement’ tab and drag in ‘is the sensor digital 2 pressed?’ to the script.
S C R A T C H C O D I N G Experiencing the Brightness sensor coding Coding the windmill with the brightness sensor The button sensor ‘is the sensor digital 2 pressed?’ was used earlier as the condition to operate the windmill. For the button sensor, the first value was ‘false’ and it turned ‘true’ when the button was pressed. But, the brightness sensor shows ‘true’ from the beginning. Therefore, we need an opposite condition to correctly operate the windmill.
110 CLASS 2 Experiencing the Brightness sensor coding The flowchart looks the same except the condition in! ga A k ec Ch True Motor on Start the program Is the brightness Ch ec kA ga in! False sensor true or Motor off false? STOP If you press the brightness sensor, the motor will turn on.
S C R A T C H C O D I N G How to Make a Robot Streetlight Make a streetlight model using the brightness sensor.
112 How to Make a Robot CLASS 2 Streetlight 1 2 x1 x4 x2 x1 x2 3 4 Combine x1 figure 1 and x2 figure 2 x1 5 x1 x3 x1 x1 x1
S C R A T C H C O D I N G Experiencing the Brightness sensor coding Turning on the streetlight using the brightness sensor Make a script so that the streetlight turns on when the brightness sensor is covered. Draw an outline below. .
114 CLASS 2 Experiencing the Brightness sensor coding Turning on the streetlight using the brightness sensor Do you remember how we activated LED sensor using the button sensor? It’s easy if you think about it as if we were using the brightness sensor instead of the button sensor. Also, keep in mind that the digital values of the button sensor and brightness sensor are opposite. If you are trying to turn on the LED using the brightness sensor, you should make a script that looks like the one below.
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 Analog 10 LESSON
116 CLASS 2 Intro to Analog What is an analog? We know that ‘true’ and ‘false’ show whether the button/brightness sensor is on/dark or off/bright. This tells us only if it is on or off, so we called it digital output. But in real world, the object is not just ‘bright’ or ‘dark’. There are different amounts of brightness. Now, the brightness sensor can show the ‘analog output’ value. This shows a number to indicate how bright it is instead of just saying ‘true’ or ‘false’.
S C R A T C H C O D I N G Connecting to the main cell Connecting the brightness sensor to the analog port Connect the brightness sensor to the analog port of the main cell. 1 2 3 4 5 6 7 8 B R W 0 1 2 3 4 5 Analog input Check out the value after connecting the brightness sensor! You can see that the value of Analog0 port changes. This is the analog value of the brightness sensor.
118 CLASS 2 Intro to the sensor What is the volume sensor? Let’s learn about analog values more! Not only the brightness sensor shows the analog value, the other sensors also show the analog values. We are going to find out about one of the robotory sensors, the volume sensor. The volume sensor literally controls the analog value like a remote controls the volume of music. A volume sensor can be used with the servo cell. Put the servo cell on the volume sensor.
S C R A T C H C O D I N G Connecting to the main cell Coding the streetlight using the volume sensor Do you remember how you coded the streetlight using the brightness sensor? Now, we are going to use the volume sensor to code the streetlight. Since we learned how to turn on and off the streetlight, now we are going to make a streetlight that changes its brightness depending on the analog value. We used the ‘digital output/off’ block to turn the LED sensor on and off.
120 CLASS 2 Experiencing the volume sensor coding Turning on the streetlight using the volume sensor Let’s start coding the streetlight using what we learned before (first, make the model). The simple part is to make the volume sensor’s analog output value the same as the volume sensor’s analog input value. We just need to combine two coding blocks like below! Do you understand this? Now, let’s code the streetlight using the start block and adding the ‘infinite repetition’ block.
S C R A T C H C O D I N G Operator What is an operator? An operator is used to compare sizes. Go to the calculation tab and find these blocks. 연산 탭으로 연산 탭으로 가서 이 가서 블록들을 이 블록들을 찾아보세요. 찾아보세요. 연산 탭으로 가서 이 블록들을 찾아보세요. 같다 같다 same 같다 Is smaller than 보다 작다 보다 작다 보다 작다 보다 보다 크다 크다 보다 크다 Is bigger than 이 블록들은 이 블록들은 ‘ 보다 작다’ ‘ 보다 , than 작다’ ‘같다’ , ,‘같다’ ‘보다 크다’ ,to’, ‘보다 를 크다’ 나타내요. 를 나타내요. These blocks show ‘__is smaller ___’, ‘equal and ‘___is bigger than___’. 이 블록들은 ‘ 보다 작다’ , ‘같다’ , ‘보다 크다’ 를 나타내요.
122 CLASS 2 Operator Using the operator Using the operator is like the start of artificial intelligence (A.I.) that uses sensors. We are going to make the computer judge analog sensors using the operator. To understand this easily, we are going to make a windmill that is connected to the volume sensor (Refer to the manual before or the homepage-moretips online).
S C R A T C H C O D I N G Operator Using the operator Now, we are going to use the volume sensor with the operator and analog values to activate the motor. Look at the flowchart below and say the program is going to keep repeating. Start the program Turn on the motor is the value of the volume sensor bigger/smaller than the original value? is smaller Turn off the motor is bigger STOP The program will keep checking if the value of the volume sensor is bigger/smaller than the original value.
124 Operator CLASS 2 Using the operator Out code will look like the example below. If the volume sensor value goes below a certain number, the motor will turn on. If it goes over, the motor will turn off. Ths is the same as the volume sensor’s analog value going up when we rotate the sensor counter clockwise. Add the calculation block to the code. Add this block and combine it with the ‘value of analog0 sensor’ block.
S C R A T C H C O D I N G Threshold value Threshold Let’s see what threshold is. Say we are listing every possible number of the volume sensor’s analog value. 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 The numbers that we see, whether we rotate it clockwise or counter clockwise, will be between two different numbers.
126 CLASS 2 Threshold value Threshold To start a program, the value has to be at least near 50. To make it safe, we can set the value somewhere near 100. 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 Threshold value Now your code will look like this The motor will turn on if the volume sensor value goes below 100. If not, then the motor will turn off.
S C R A T C H C O D I N G Threshold value Threshold Try with your motor! You will see the motor stopping when the value of the volume sensor goes below 100. You can set the value anywhere between 60 and 170 if it is smaller than the value you see when you rotate the sensor clockwise. 0 10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 Possible threshold Try making different models and operate them using threshold values that you choose.
128 S C R A T C H C O D I N G K I T Logic CLASS 2 boost Alligator robot LESSON 11
S C R A T C H C O D I N G How to Make a Robot Alligator robot Let’s make a scary alligator robot that opens and closes its mouth. We are going to use the servo motor to do this. (We have to type in the angle for the servomotor when closing its mouth). The robot’s mouth will be open in the beginning and close when the brightness sensor is covered. When the button sensor is pressed, it will open its mouth. Using the volume sensor, we are going to control the angle at which it opens its mouth.
130 How to Make a Robot CLASS 2 Alligator robot Let the brightness sensor’s digital value be the input value to make the robot move with the servomotor.
S C R A T C H How to Make a Robot Alligator robot 1 2 x1 x3 x6 x2 x2 x1 x3 x4 3 4 x1 Combine figure 1 and x1 figure 2 x2 x1 5 Combine figure 3 and 6 x2 x2 figure 4 x2 x4 x1 C O D I N G K I T
132 How to Make a Robot CLASS 2 Alligator robot 7 8 x 1 A 96 x2 x 2 A 23 x2 x2 x2 x2 x2 A 23 9 10 x2 Combine x1 figure 5 and figure 9 Combine figure 6,7,8 11 x1 x1 x1 x1 x1 x6 x1 Complete
S C R A T C H C O D I N G Connecting to the main cell Alligator robot Brightness sensor (CDS sensor) 1 2 3 4 5 Volume sensor (POTENTIONMETER) 6 7 Servo motor 8 11 12 13 14 15 16 B B R R W W button sensor (BUTTON) 17 1 8 sound sensor (SONG GENERATOR) Sound sensor Button sensor Brightness sensor Volume sensor K I T
134 CLASS 2 Experiencing the alligator robot coding Sound sensor and opening the alligator’s mouth First, code an explanation of the settings of the alligator in the beginning. When the script starts, the sound sensor should start playing music and the servo motor has to open the robot’s mouth. Remember what we learned before and make a script. Look at the script below. Carefully set the angle at which the alligator opens its mouth.
S C R A T C H C O D I N G Experiencing the alligator robot coding Brightness sensor and Opening/closing the alligator’s mouth If the brightness sensor is uncovered, the alligator should have an open mouth. If the brightness sensor is covered, the alligator should have a closed mouth. The brightness sensor should be used to close the the robot’s mouth, and the button sensor should be used when to open the robot’s mouth.
136 CLASS 2 Experiencing the alligator robot coding Brightness sensor and Opening/closing the alligator’s mouth To show how the brightness sensor’s input value and the button sensor’s input value act on the servo motor in flowchart, it looks like below. Before, we checked how DC motor works with the windmill, but this time we have to check how the servo motor works.
S C R A T C H C O D I N G Experiencing the alligator robot coding Brightness sensor, volume sensor, and servomotor Now, we are going to make a code that will control the angle of the servomotor using the brightness and volume sensors. When the brightness sensor is covered, the mouth should close and when it’s not covered, it has to set a max angle for the alligator to open its mouth using the volume sensor. Make a script like below! Set an angle in which the alligator closes its mouth.
138 CLASS 2 Experiencing the alligator robot coding Button sensor and the servo motor Now, code for the alligator’s mouth movement when the button sensor is pressed. First, we are going to make the sound sensor produce a short sound whenever the button sensor is pressed. And when the button sensor is pressed, the alligator’s mouth will open until it reaches the angle that was set by the volume sensor.
S C R A T C H C O D I N G Experiencing the alligator robot coding The alligator robot coding If you combine all the scripts, it will look like this! Look at the whole script and see how each coding block carries out the different tasks.
140 CLASS 2 Experiencing the alligator robot coding Using the ‘If’ phrase with the alligator robot We just made the script using a ‘if..or else..’ phrase. Now, let’s make the script using a ‘If’ phrase. It will be simple. Think about how you it would code the ‘or else’ part.
S C R A T C H C O D I N G Experiencing the alligator robot coding Coding ‘If’ with the alligator robot If we controlled the brightness sensor’s servo motor with the ‘if..or else..’ phrase before, we are going to use two ‘if’ phrases to control the servo motor. First, make a script that will close the alligator’s mouth when the brightness sensor’s value is big (when the sensor is covered). The script above makes the alligator close its mouth when the brightness sensor’s value is big.
142 CLASS 2 Experiencing the alligator robot coding Alligator robot Activate the program! Try opening its mouth with the button sensor before it closes due to the covered brightness sensor. A completely closed mouth is when the blocks touch each other. If the mouth closes too fast/slow, change the angle using the volume sensor. Try playing this next game with your friends! Alligator robot game rules 1. The players will cover the brightness sensor to make the robot close its mouth 2.
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 Scorpion root LESSON 12
144 CLASS 2 exercise Scorpion robot Now, you are going to use different motors and sensors to make a model. Try coding its movement using what we have learned about brightness sensors, LED sensors, DC motors, and servo motors. The name of this robot is Scorpion robot. It looks like a scorpion, and it can move its tongs up and down using the servo motor. Combine one input sensor (brightness sensor), one output sensor (LED sensor), two DC motors, and one servomotor to make the robot.
S C R A T C H C O D I N G exercise Scorpion robot Brightness sensor (CDS sensor) Make the scorpion robot.
146 exercise CLASS 2 1 1-1 x2 Figure 1-1 1-2 1 x4 2 2 2 x1 x3 Assemble figure 1 with four of the cells with 8 bumps 2 inside 2-1 x2 outside x1 A 45 x1 A 64 A 45 A 64 x2 A 64 A 45 A 45 A 45 x4 A 45 A 45 A 45 x3 A 45 ※ Careful with the locations of rods 2-2 inside x2 x1 outside A 45 A 45 A 45 x1 A 64 x2 A 45 A 45 A 45 A 64 x4 A 45 A 64 A 45 x3 A 45 ※ Careful with the locations of rods 3 3-1 3-2 Figure 2-1 x2 x4 Figure 1-2 Figure 2-2
S C R A T C H C O D I N G exercise 3-3 3 Figure 3-1 Figure 3-2 x4 Figure 3-2 4 4-1 x2 4-2 Figure 3-3 Figure 4-1 x2 45 degree angle 5 5-1 (A) (B) 5-2 Figure 4-2 Figure 5-1 (A) x4 x2 Figure 5-1 (B) x2 x2 6-1 6 Assemble in 45 degree angle 6-2 2 x2 x1 x3 x1 x2 x2 x1 1 1 x2 x3 1 K I T
148 exercise CLASS 2 6 6-3 6-4 Figure 6-3 Figure 6-1 Figure 5-2 Figure 6-2 6-5 6-6 x1 x1 x1 x1 x3 x1 7 7-1 7-2 A 64 x2 x1 x1 1 x1 A 64 2 x1 x2 x2 x2 x2 1 x1 Careful with the directions 7-3 7-4 Figure 7-2 x1 Figure 7-1 x4 x2 Assemble at a 45 degree angle
S C R A T C H C O D I N G exercise 7 7-5 7-6 Figure 7-3 Figure 7-5 Figure 7-4 Assemble figure 7-3 and figure 7-4 Complete Figure 6-5 K I T
150 CLASS 2 exercise Coding the scorpion robot Try coding the robot by yourself. When the brightness sensor is covered, the tongs should go up and the LED sensor should light up. DC motor has to be controlled with the keyboard arrow keys. When the brightness sensor is not covered, the tongs have to move down and hte LED sensor should turn off. Use an ‘If..or else..
S C R A T C H C O D I N G exercise Using the keyboard to control the scorpion robot Code so that the scorpion robot will move with the DC motor when arrow keys are pressed. Do you remember the lizard robot from level 1? Consider the scorpion robot moving front/back and right/left to make a script. If you don’t remember well, refer to the scripts below.
152 exercise CLASS 2 Scorpion robot Look at the flowchart below. When the program is started, the servo motor should lift up the tongs and turn on the digital output (LED sensor) as the brightness sensor gets covered.
S C R A T C H C O D I N G exercise Scorpion root Let’s make the servo motor lift up the catchbot whenever the brightness sensor is pressed. Refer to the alligator robot script. The script above operates the servo motor whenever the brightness sensor is pressed. Set an angle for the servo motor when lifting and setting down the catchbot. Let’s add the digital output on/off now. Now, the scorpion robot will lift the catchbot up and turn on the LED when the brightness sensor is pressed.
154 CLASS 2 exercise Using the ‘if’phrase with the scorpion robot We just made a script using the ‘if..or else..’ phrase. Now, make a script using the ‘if’ phrase only. It’s going to be simple. Think about how you will make the ‘Or else..’ part. Make a script below.
S C R A T C H C O D I N G exercise Coding the scorpion robot with an ‘if’ phrase Since we controlled the servo motor and LED sensor with ‘if ..or else..’, we are now going to use two ‘if’ phrases to control the servo motor and LED sensor. First, make a script that will lift the tongs up and turn the LED sensor on when the brightness sensor value is big (when it’s covered). The script above will lift the tongs up and turn on the LED sensor when the value of the brightness sensor is big.
156 CLASS 2 exercise Changing the digital output of the scorpion robot We just made the LED sensor turn on when the tongs are lifted and turn off when they’re down. Now, we are going to fix the script to make the LED sensor flash when the tongs are lifted and turn off when they are put down. Do you remember the script we made to make the LED sensor flash? Make a script on the space below.
S C R A T C H C O D I N G exercise Changing the digital output of the scorpion robot Do you remember how to make a script that makes the LED sensor flash? The script that will make it flash every second looks like below. Compare this with yours. Instead of keeping the LED sensor on when the tongs are lifted, make it flash every second. If you connect the whole script, it will look like the one below! Start the script and try again if it doesn’t work well. The whole script can be found at http://www.
158 CLASS 2 S C R A T C H MEMO C O D I N G
K I T MEMO
160 CLASS 2 MEMO
FCC Information to User This equipment has been tested and found to comply with the limits for a Class B digital device, pursuant to Part 15 of the FCC Rules. These limits are designed to provide reasonable protection against harmful interference in a residential installation. This equipment generates, uses and can radiate radio frequency energy and, if not installed and used in accordance with the instructions, may cause harmful interference to radio communications.