Lesson 9 – Dial + Sound Sensors

Hummingbird Components

1 Dial Sensor, 1 Sound Sensor, 1 Single Color LED, 1 Tri-Color LED, 1 Position Servo, 1 Rotation Servo

Python Concepts

None

Teacher Materials

Get Access

So far, you have used sensors to control Hummingbird outputs with if-else statements and while loops. In this lesson, you will learn to use the dial sensor to control Hummingbird outputs directly while practicing while loops with the sound sensor. Start by connecting the dial sensor to port 1, the sound sensor to port 2, and a single color LED to port 1.

Use the getDial() method to find the value of the dial sensor, and the getSound() method to find the value of the sound sensor. Just like the other sensor methods you have used, both of these methods require one parameter, the port to which the sensor is connected (1-3). The getDial() method returns a value from 0-100 that represents the position of the dial. The getSound() method returns a value from 0 to roughly 100 that represents the magnitude of the sound around the sensor in arbitrary units.

Note: If your Hummingbird contains a micro:bit V2, you can also use the sound sensor in the micro:bit by calling getSound(“microbit”). Using the “microbit” parameter will result in an error if your Hummingbird does not have a micro:bit V2.

Exercise 1

Try out this code. The LED should stay on until you clap your hands or make another loud sound. Then modify this code to blink the LED quickly until you clap your hands.

Since getDial() returns a number from 0-100, you can call this method inside a Hummingbird method that requires a parameter from 0-100. For example, you can call getDial() inside the setLED() method.

Exercise 2

Try out this code. By turning the dial back and forth, you should be able to adjust the brightness of the single color LED. Then clap to end the program. Next, modify this code to use the dial sensor to change the speed of a rotation servo.

Exercise 3

Write a program to use the dial to move the position servo from 0° to 180°.

Exercise 4

Write a program to use the dial to gradually change the tri-color LED from red to blue.

Exercise 5

Write a program to use the dial to control the rotation servo. When the dial value is 0, the speed of the rotation servo should be -100. When the dial value is 100, the speed of the rotation servo should be 100. Hint: You will need to find a linear equation of the form speed = slope*dial + intercept.

Extra Challenge

Write a program that uses the sound sensor to control the color of the tri-color LED.

Back to Top