Sensing with the Finch (Snap!)

Following the Light

In the first lesson, you learned to use the Finch outputs: the motors, lights, and buzzer on the Finch. The Finch also has sensors that provide input to the robot. A sensor makes measurements and sends them to the program that the Finch is running. The program can use the sensor information to set outputs or make a decision. The Finch has two light sensors, an acceleration sensor (accelerometer), two obstacle sensors, and a temperature sensor.

For an introduction to the sensing blocks available in Snap!, watch Snap! Level 4 Programming: Inputs. The Sensing menu in Snap! contains the blocks for the Finch sensors. The Finch Left Light Sensor and the Finch Right Light Sensor blocks can be used to measure the values of the two light sensors. Each of these blocks has a value from 0 (no light) to 100 (maximum light).

Exercise: Drag a light sensor block into the Scripts area. Click on the block to see the current value of the sensor. Next, cover the light sensor with your hand and click on the block again. You should see the value of the light sensor change. What is the value of the block when you shine a flashlight on the sensor?

You can use the sensor blocks to make the robot respond to its environment. For example, you can make the speed of the robot depend upon the value of the light sensors using the block shown below.

This block will set the speed of the robot using the values of the light sensors. However, this will only happen once. If you want the speed of the robot to change when the sensor value changes, you need to use a loop. Use a flashlight to try out the program shown below.

Did your Finch move too slow or too fast? You can use math to change that!

Using Math with the Finch

In the Operators menu, Snap! contains blocks that you can use to do arithmetic.

You can use the multiplication block to make the robot move twice as fast.

Exercise: Try out the arithmetic blocks to make your robot follow the flashlight as quickly as possible. The Finch should not move when the flashlight is not shining on it.

Exercise: Why is the speed of the left motor controlled by the right sensor? What happens when the speed of the motor is controlled by the sensor on the same side?

Tip: You can also place arithmetic blocks inside one another. When you do this, the operation in the innermost block will be performed first. In the expression below, the 2 and 4 will be added together first, and then the result will be multiplied by 10. What will be value of this expression be? Make a hypothesis and then test it in Snap!. Remember, you can click on a block to find the value of the block.

Exercise: Program your Finch to avoid light instead of following it. This behavior is shown in the video below, which was taken at Towns County High School, Hiawassee, GA.

Temperature Sensor

There are also two Finch blocks that can be used for measuring temperature. What is the temperature in your room in Celsius and in Fahrenheit? Can you raise the temperature reading of the sensor?

Exercise: Use the temperature sensor to set the color of the Finch’s beak.

Accelerometer

The last blocks that we will use in this lesson measure acceleration. These blocks measure how much the Finch is tilted. When the Finch is sitting on a flat surface, these blocks will not change.

There are three different blocks because the Finch can measure tilt in three different directions. The value of each block is a decimal number between -1.5 and 1.5.

Exercise: Create three variables. Use the program below to continually change these variables to the values of the acceleration blocks. Tilt the Finch in different directions. What type of tilt makes each variable change?

Exercise: Use one of the acceleration blocks (or one of your variables) to move the sprite on the screen. You will need to use a move block with the acceleration block inside it. You may also want to use the arithmetic blocks.