Piezo Buzzers with the Hummingbird
Use a piezoelectric buzzer with the Hummingbird.
Any language supported by Hummingbird
4-5, 6-8, 9-12
When the Hummingbird is plugged into the computer, you can use the computer speakers to add sound to your project. Another alternative for adding sound is to use a piezoelectric buzzer, and this tutorial will show you how! This is particularly helpful if you plan to run in Arduino mode (not connected to the computer). We will use the CREATE Lab Visual Programmer here because we want to export our project to Arduino, but the buzzer will work with any of the programming languages you can use with the Hummingbird. Also, this tutorials assumes that you are using a Hummingbird Duo. Only the Hummingbird Duo can run programs in Arduino mode, but the buzzer can also be used with the original Hummingbird.
First, you will need a buzzer. We used one like this, but any buzzer than can accept an input voltage from 0-5 V should be fine. Attach the red buzzer wire to the ‘+’ terminal of a Hummingbird LED port, and attach the black wire to the ‘-’ terminal.
Next, open the CREATE Lab Visual Programmer and select the LED port of your buzzer. You can move the slider bar to change the buzzer’s sound. The buzzer is off when the slider is all the way to the left (0).
We created three expressions: Piezo Low, Piezo High, and Piezo Off. We added some single color LEDs to these expressions as well. We used these expressions to create an alarm controlled by the distance sensor. When someone or something is near the sensor, the buzzer should alternate between Piezo Low and Piezo High. Otherwise, the buzzer should be off. A sequence for this behavior is shown below.
Once you have a sequence that you are happy with, you can use the Export Sequence button to export the sequence to Ardunio code. The main loop for our Arduino code is shown below. From the Arduino software or Codebender, you can put your Hummingbird Duo into Arduino mode and upload your program. More information on exporting to Arduino can be found here.
After testing our program, we made a sign that incorporated the distance sensor, two red LEDs, and the piezo buzzer. The Hummingbird board sits behind the sign on top of the battery pack. Now this portable project can be used to alarm anything!
Let us know what you decide to make with a piezo buzzer! Send us an email or tag us on Twitter (@birdbraintech).
Technical Note: The LED ports on the Hummingbird are actually controlled using pulses of voltage that form a wave (pulse-width modulation). The command to the LED port determines the width of the pulse from 0% to 100% of the wave period. Because the frequency of this wave is faster than our eyes can perceive, we see the brightness of the LED increase as the width of the pulse increases.
Most piezoelectric buzzers are designed to run with a DC voltage. If you turn on a buzzer with batteries, the buzzer always vibrates at the same sound frequency; the voltage of the batteries just determines the volume. When you control the buzzer with a Hummingbird LED port, you can change the pitch of the buzzer by changing the input to the port. This is because the wave output of the LED port is interacting with the frequency at which the buzzer is designed to vibrate. Resonance or interference between these waves changes the sounds that you hear.