Arduino Project: Generating Sound with a Passive Buzzer
In this Arduino project, we will be using a passive buzzer to generate sound. Similar to the active buzzer example, you will need to connect the buzzer to the Arduino.
The buzzer has a positive “+” pole, which can be connected using a red wire (a good habit to follow). Connect the negative “-“ wire to the GND on the Arduino and the “+” wire to a digital output pin. In this case, we will be using pin #8.
For generating sound, the Arduino language provides a function called tone()
, which is perfect for working with a passive buzzer. It allows us to play a specific frequency on the buzzer pin for a specified duration.
Here is an example of generating sounds using tone()
:
1 | int duration = 500; |
You can even play actual songs using tone()
by combining different frequencies. Here is an example of a program that plays a melody using the pitches.h
library:
1 | /* |
By utilizing multiple buzzers, you can create melodies with multiple notes. You can also combine sound generation with user input to create interactive projects, such as a toy keyboard with different sounds.
tags: [“Arduino”, “passive buzzer”, “sound generation”, “tone()”, “melodies”, “user input”, “interactive projects”]