Tuesday, January 11, 2011

Piezo Buzzer on Arduino

The piezo buzzer has a thin metal membrane. When voltage is applied to the component at a certain frequency, the membrane gets into a vibrating motion which produces soundwaves. With changes in frequency you can control the sound output.

Another great thing is, that you can use the piezo buzzer also as an input device. Audio waves can influence its membrane and can set it into a vibrating motion. When this happens, the output voltage of the component changes and you can detect sound.

There were already some great tutorials on the web, so I only had to change the source code according to pin layout or threshold values. Connecting the buzzer is pretty easy. In most cases you only might need a resistor in your circuit to limit the current, that's all. I simplified my experiments with an Arduino shield from seeedstudio.com which adapts the Arduino pins to connector ports and busses, which can be easily used when connecting to other boards. I also got some mini sensor circuit boards which makes prototyping quite easy. Here you can find the piezo buzzer used in this experiment.

Some simple experiments using the connector shield and the buzzer can be found here.

So first, let's hear the buzzer in action:


When experimenting with the frequencies and duration of the output, you even can produce some melodies. A tutorial of playing some notes can be found on the Arduino tutorial page.

Here is my attempt:


Now, to use the piezo buzzer for detecting sound or vibration you have to experiment with the threshold value in your code, so it won't be triggered by background noise. The Arduino tutorial page provides source code for this experiment as well.

I could have improved my threshold even more, but you can see that it works anyway.


No comments:

Post a Comment