Start by watching the videos shown below.
The first will show you how to attach components to the Hummingbird board, and the second will show you how to connect the Hummingbird to the computer and how to open Scratch when using the Hummingbird.
Before you can build an awesome robot with your Hummingbird, you need to know how to use all the parts.
This lesson will first show you how to use the Hummingbird outputs, the lights and motors. These components are called outputs because programs in Scratch send commands to them to make something happen. Then you will learn how to use the Hummingbird inputs, the sensors that provide information to the robot about its environment.
Start by watching the videos shown below.
The first will show you how to attach components to the Hummingbird board, and the second will show you how to connect the Hummingbird to the computer and how to open Scratch when using the Hummingbird.
This is the Scratch window. It has a few different parts.
To write a program, you will drag blocks from the Blocks area to the Scripts area. In Scratch, programs are also called scripts. You can use Scratch to write scripts that use the Hummingbird or scripts that use cartoon characters called sprites. These lessons will focus on the Hummingbird. To learn more about using sprites to create an animation that runs in the Stage area, please see the Resources section at the end of this lesson.
It is very important to save your work often! Otherwise, you might lose something important.
To save a new project in Scratch, click on File and then Save as (Save Project for Chromebooks using ScratchX). Give your project a name and then click Save. Once your project has a name, you can save it by going to File and then Save.
DO NOT name your Scratch file HummingbirdStart. This will overwrite the blank file that should appear when you open Scratch from the Birdbrain Robot Server.
The HB LED block is used to control a single color LED. This block requires two numbers.The number on the left is the number of the Hummingbird port to which the LED is attached. This will be a number between 1 and 4. In the picture above, the LED is connected to LED port 1.
The second number in the HB LED block is the intensity of the LED. This is a number between 0 and 100. 0 means that the LED is off, and 100 means that the LED is at maximum brightness.
Attach a single color LED to LED port 1. Then drag the HB LED block out into the Scripts area.
This is your first program! Click on this block to run your program. The LED should turn on.
This should make the LED turn off. Change the 0 to 100 and click on the block. This is the maximum brightness of the LED. Try out other numbers between 0 and 100 to explore the different levels of brightness that are possible.
The second block on this menu is when key pressed. Drag this block into your program until it connects to the top of your script.
Notice that the shape of this block shows you that it must be at the top of a script. It can’t be connected below another block.
Now you can run your program by pressing the space bar. Try using the space bar to turn on the LED.
Click on the black triangle in the when key pressed block.
A menu will pop up that will allow you to select other keys. Modify your program so that the LED turns on when you press ‘o.’
You may have already discovered that you can write multiple scripts in the Scripts area. Add a second script that turns the LED off when you press ‘x.’
Connect a second LED to LED port 2. Write a script that turns the first LED on and waits 2 seconds. Then the script should turn the second LED on for 2 seconds. Then the program should turn both LEDs off. Remember to save your work!
When Scratch reaches an HB LED block, it sets the LED and moves immediately to the next block. This means that if you do not have a wait block between two commands for the same LED, you may not see the effects of the first block. For example, you may not see the LED turn on when you run this script. Place a wait block between the HB LED blocks in order to see the LED turn on and then off.
Write a program that turns two LEDs on at different intensities, waits five seconds, and then turns both LEDs off.
It is good programming practice to always turn off your LEDs at the end of the program. They may go off automatically after a few seconds (particularly on Chromebooks), but this can be unpredictable.
A tri-color LED can be attached to one of the two ports labeled “TRI-COLOR” on the Hummingbird board. The four wires of the tri-color LED are red, green, blue, and black. The black wire should be connected to the ‘-’ terminal. The red wire should be connected to the ‘R’ terminal, the green to the ‘G’ terminal, and the blue to the ‘B’ terminal.
The tri-color LED actually has three tiny lights inside it. One is red, one is green, and one is blue. This is important for programming the tri-color LED. The HB triLED block is used to control a tri-color LED. This block requires four numbers. The number on the left is the number of the port to which the tri-color LED is attached (1 or 2). The other numbers are labelled R, G, and B. R controls the amount of red light from 0 (none) to 100 (maximum brightness). G and B control the amount of green and blue light, respectively, from 0 to 100. As an example, this block makes a tri-color LED in port 1 turn green.
Write four scripts to turn the tri-color LED four different colors. Each script should use a when key pressed block and a HB triLED block. For example, the ‘a’ key might make the LED aqua.
Think about how you might turn an LED on and off repeatedly. One way to do this would be to use a long sequence of commands, but it is much simpler to use the forever block in the Control menu. This block is called a loop. A loop is a programming structure that repeats a portion of a program. Look at the Control menu. Which of the other blocks do you think might be loops?
Other blocks can be placed inside the forever block. The forever block repeats the blocks inside it until you press the stop sign to stop the program. The loop shown blinks the tri-color LED from green to blue. The loop repeats the four blocks inside it over and over. After the second wait block, the program immediately goes back to the first block inside the loop, the block that turns the LED green. What happens if you remove the second wait block?
Make a tri-color LED blink on and off in your favorite color at least ten times in five seconds. The tri-color LED should blink evenly – in other words, it should be off for the same amount of time that it is on. Next, add a single color LED. The single color LED should be off when the tri-color is on and on when the tri-color is off.
Write a program that turns both a vibration motor and a single color LED on for four seconds and then off for four seconds. Then place these commands within a loop to repeat them five times.
A servo motor is a motor that moves to a particular angle. The Hummingbird servo motor can rotate to any angle from 0° to 180°.
Important Note: When using the servo motor, you must also use the AC power adapter (or a battery pack). Otherwise, the Hummingbird board will not have enough power to run the motor.
The servo motor has a small plug. This plug should be connected to one of the four sets of pins in the “SERVOS” section of the Hummingbird board. Each set of three pins is one servo port. The black wire should be connected to the ‘-’ pin, the red wire to the ‘+,’ and the yellow wire to the ‘S.’
Write a script that repeatedly moves the servo to five different angles. Make the tri-color LED a different color at each angle.
Before you start building with a servo, always set it to 90°. This will make sure that the servo can move both left and right once it is attached to your robot.
The gear motor can be attached to either of the ports labeled “MOTORS” on the Hummingbird board. It does not matter which wire is attached to ‘+’ and which is attached to ‘-.’ When using the gear motor, you must also use the AC power adapter (or a battery pack).
Important Note: Do not cut the zip ties off your motors. Without the zip tie, the wires may break off the motor.
The HB motor block is used to control the gear motor. This block requires two numbers. The number on the left is the port attached to the motor. The number on the right is labeled “speed.” This number can be any whole number from -100 to 100. As an example, this script turns the motor on for two seconds and then off.
Use a small screwdriver to attach a wheel to the motor so that you can see it move more easily (or just place the wheel on the motor without using a screw). Try several speeds between 0 and 100. Describe how the speed affects the motor. Try several negative speeds. What does it mean for the speed to be negative?
Important Note: You may notice that your motor rotates clockwise for positive numbers, while your neighbor’s rotates counterclockwise for the same number. This just means that you and your neighbor chose ‘+’ and ‘-‘ differently when you connected your motors. Either way is fine!
Write a program that rotates the motor first in one direction, then in the other. Next, use a loop to repeat these actions.
Write a program that uses two speak blocks. What block do you need to place between your speak blocks?
Are you ready to use all the Hummingbird outputs? Write a program that includes at least two scripts that run when you press different keys, at least three LEDs, at least two different kinds of motors, and at least one loop.
The Hummingbird LEDs and motors are output devices. Scripts in Scratch send commands to these devices to make something happen. The Hummingbird sensors, on the other hand, are input devices. They send information to the Scratch program. The Scratch program can use this information to make a decision or control a light or a motor.
The distance sensor measures the distance to the closest object. Attach a distance sensor to the Hummingbird. Drag the HB distance sensor block into the Scripts area away from the other blocks. Make sure that the port number is set to the port attached to the distance sensor. Click on this block to see the current value of the sensor. Then hold something in front of the sensor and click the block again. Is the value of the distance sensor different?
The distance sensor measures the distance to an object in centimeters. The value of the distance sensor is between about 8 cm and 100 cm. The sensor cannot detect objects very close to the sensor or very far from it. It works best in the range of 20 cm to 60 cm.
To see the value of the distance sensor change, it is helpful to create a variable. A variable is just a name that represents a value. You will now create a variable named “distance” that will hold the value of the distance sensor and display that value on the screen.
First, go to the Data menu. Then click Make a Variable.Run the script above and watch the value of the distance variable change as you move an object back and forth in front of the sensor.
The if then else block has spaces in the middle that can hold other Scratch blocks. In addition, the if then else block contains a hexagonal space. This space requires a Boolean block. A Boolean block is a block that can be either true or false.
You can use the distance sensor to create a Boolean block using these two blocks, which are found on the Operators menu. Notice that these blocks match the shape of the space in the if then else block.
Create the Boolean block shown.
This block is true if the value of the distance sensor is greater than 30 cm, and false otherwise. The value that the Boolean block uses to make a decision is called the threshold. In this case, the threshold is 30 cm. Click on the green part of the block with an object in front of the sensor. Is the block false?
Place the Boolean block into the hexagonal space in the if then else block.
When a script reaches an if then else block, it checks the value of the Boolean block inside it. If the value is true, then the script runs the blocks inside the top part of the if then else block. If the value of the Boolean block is false, then the script runs the blocks in the bottom part of the if then else.
Write a program that blinks a red light and moves a servo motor when an object is close to the distance sensor. When nothing is near the distance sensor, the light should be off and the servo should not move.
The Boolean block for the if then else is checked each time the program repeats the decision. However, the Boolean block is not checked during the statements inside the top or the bottom of the if then else block. Try out this script. In this script, the motor should be on when something is close to the distance sensor. When you run this program, you will notice that the program does not respond quickly when you move an object toward or away from the distance sensor. How can you modify this program to make it respond more quickly to a change in the value of the distance sensor?
Attach the knob to the Hummingbird board. Declare a variable named “knob” and write a script that uses the set toblock to continually set this variable to the value of the HB rotary block. Then turn the knob all the way to the left. What is the value of the HB rotary block? What is the value of the HB rotary block when the knob is turned all the way to the right?
Write a program that turns on a single color LED when the knob is turned far enough to the left. When the knob is turned far enough to the right, the LED should be off. What will your threshold be for this program? Remember, the threshold is the value that the Boolean block uses to make a decision.
In the previous exercise, you used the rotary knob to decide whether the LED should be on or off. Instead, you could use the knob to determine the brightness of the LED. Because the HB rotaryblock is a number between 0 and 100, you can place it inside the HB LED block to set the intensity of the light. Try out the script shown. The forever loop repeatedly changes the brightness of the LED to match the value of the knob.
Use the knob to control a gear motor and the amount of red in a tri-color LED (the amount of green and blue can be whatever you want). These components should change at the same time.
Don’t forget to set the port in the sensor block to the port on the Hummingbird board that you are actually using! If the value of the sensor is not changing as expected, be sure to check that the sensor block is reading the correct port.
The light sensor measures the amount of light around it. This sensor is very similar to the other sensors that you have learned about. You can use the HB light sensor block to find the value of this sensor. This value will be between 0 and 100. Always remember to make sure that the HB light sensor block is set to the appropriate port.
Attach the light sensor to the Hummingbird board. Use the HB light sensor block to measure the amount of light in your room. Then measure the value of the light sensor when you cover it with your hand. The average of these two values is a good threshold for the light sensor.
Write a script that turns on a vibration motor when the light sensor detects that it is dark. Otherwise, the vibration motor should be off.
You have now practiced using all the Hummingbird motors and lights, as well as three of the sensors. There are other sensors, including a temperature sensor and a sound sensor. These work very similarly to the sensors you have already used. The HB temperature block tells you the temperature in Celsius, and the HB sound block tells you the amount of noise around the Hummingbird on a scale of 0-100.
The last two exercises below will give you some practice using multiple sensors. After you have completed these, you will be ready to create many exciting, unique Hummingbird robots!
Write a program that uses the knob sensor to control the color of a tri-color LED. However, the LED should only be on when an object is less than 30 cm from the distance sensor. Otherwise, the LED should be off.
Write a program that sends the servo to four different angles based on the values of the distance and light sensors. All of the values are shown in the table below.
Distance | Light | Servo Angle |
Greater than 20 cm | Above the threshold | 0° |
Greater than 20 cm | Below the threshold | 60° |
Less than 20 cm | Above the threshold | 120° |
Less than 20 cm | Below the threshold | 180° |
Congratulations! You have completed Hummingbird Scratch training.
Have fun making robots!