Buzzer Arduino Example Code


I just received a small CEM-1203 buzzer from Spark Fun for an Arduino project with sound output. After writing up a basic function to run it, I decided to generalize and fully comment so that other people could use similar buzzers without having to think through the math each time they wanted to hear a particular sound frequency. All you need to do is tell the function which pin you’d like to use, the frequency you want to hear, and the duration to play that frequency.

My buzzer example function should easily work with other types of sound output devices.

Posted in General
5 comments on “Buzzer Arduino Example Code
  1. nicola says:

    yes but how do you connect it to the arduino ?

  2. faludi says:

    For this example, the buzzer module is connected to digital pin 4 and ground.

  3. I am still confused. Do you connect it directly (neg to ground, pos to pin4) or do you use the recommended transistor/resistors?

  4. Chris says:

    Thanks for the great buzzer example! I created a tutorial expanding upon your efforts. It wouldn’t have been possible without your contribution:

    Best regards,