Lilypad - Buzzer


buzzer.jpg
Lilypad Buzzer (

Description:

Outputs sound. Can be used to play a tune or a single note. Sounds like an early mobile phone ring-tone.

Connecting:

1. Connect the negative petal on the Buzzer to the negative petal on the Lilypad Main Board.
2. Connect the positive petal on the Buzzer to one of the digital I/O pins e.g. 8.

NB: If you are using alligator leads to prototype then make sure that the teeth of your clips make good contact with the metal parts of the sensor petals. If not, you will get inconsistent results.

Controlling:

The key function for creating a sound using the buzzer is the tone function. This function lets you specify the pin the buzzer is connected to, the pitch of the tone and the duration that it lasts for. The simple sketch below will let you generate a single tone with a 1 second delay between loops if the buzzer is connected to pin 8. Play around with the values in the pitch and duration section till you understand how they work. Try pitch values between 0 and 5000.

singletone.gif
Generate a single tone using the Buzzer


For more complex examples using the buzzer see the arduino example tone sketches under File > Examples > Digital. There are three examples here. One plays a melody just once as soon as the sketch is loaded (toneMelody). Another uses three touch sensors to play back tones a bit like a keyboard (toneKeyboard). The other maps the input from any analog sensor (e.g. a light sensor) to a tone (tonePitchFollower). All three use an associated file called pitches.h that translates frequencies into more recognizable note values. You could use this file to help you compose your own melody.


pitches.gif
Pitch values mapped to note values


Links: