When we think of user interfaces for electronics, our thoughts generally go to a touchscreen, or perhaps an LED or two in very simple cases. Sometimes, however, audible feedback is best, whether as a tone that can be heard no matter where you’re facing, an alarm to get you up in the morning, or a simple robot greeting that beeps to say “hello.” Additionally, this signaling method can be used to accommodate those with visual impairments.
The good news is that from a hardware standpoint, producing a simple output with a piezo buzzer speaker (seen below) is as easy as hooking up an LED. Code is available in the Arduino IDE under Examples/Digital, where you’ll find four example sketches starting with “tone.” These programs call for the use of an 8-ohm speaker hooked up to a digital output pin, but if you can find that spec on a small piezo speaker, you can simply connect it to see if it works.

Adding Arduino Tone Code

For your first trial, load the simplest example program,“toneMelody”, and hook up the speaker to ground and pin 8. If things are configured correctly, it will play a short song that you’ll recognize, then (conveniently) stop until you hit the reset button. The notes and duration of this program can be modified or integrated as an output method into your program, and this makes a good starting point for audio experimentation.
If you have several speakers available, you can play notes over several outputs using the “toneMultiple” example, one speaker at a time. This would be useful for a machine or robot that needs to get a user’s attention in different places.
Arduino Music User Interface

Making things more interesting, you can add a user interface in the form of an analog input. The “tonePitchFollower” example sets things up to do this easily, and is written to use a photoresistor as the input, with a 4.7 kilohm resistor functioning as a voltage divider. This same code can be used with a potentiometer, though you’ll want to change the analog input range from 400-1000 to 0-1024 to reflect the greater range of this component. When hooked up this way, you can adjust the frequency higher and lower by twisting, reminiscent of tuning a radio.
This, tone, however, will soon get annoying. If you’d like to add a cutoff when the potentiometer is turned nearly to zero, you can add a conditional statement to make things a little more pleasant.
Adding the Arduino Wave Shield
If you’d like to signal someone with the words “stop” or“push the green button”rather than simple beeps and bloops, then you might consider adding a Wave Shield. This device plugs into an Arduino Uno board from an SD card, and features a potentiometer so you can turn the volume up or down, as needed. You might also consider a voice recording module like the ISD1820 or similar that can record a short voice clip and play it back when signaled by a microcontroller or physical button. Finally, other dev boards can work with piezo speakers in a similar manner, so you’re not just restricted to Arduino, but can use an audible signal in a wide variety of situations.
For more popular Arduino Products click here.
See related product

