How to Hook Up > Buzzers
Buzzers allow for simple audio output. Running them at different speeds allow for a variety of tones. This post details how to hook one up to an Arduino.
- 2 Jumper Wires (yellow & black)
- USB cable (A to B)
- A typical (piezo) buzzer has 2 leads. To no surprise, 1 is positive and 1 is negative. These should be labeled on and/or under the buzzer.
- Place it on you breadboard and place a (yellow) wire from the positive lead to a digital pin (4).
- Place a (black) wire from the negative lead to a ground pin.
- Connect the Arduino to your computer using the USB cable (A to B).
- The code below will repeatedly turn the buzzer on HIGH and LOW (on and off) with 2000 microseconds intervals, which is 2 milliseconds or 0.002 seconds. Upload it to your board and enjoy the constant low tone.
int buzzPin = 2;
Turning the buzzer on and off rapidly causes the buzzer to vibrate and make sound. While the above code is looping infinitely, using a for loop will give you more control over the duration. You’ll want to loop it at least a couple dozen times for a brief (1-2 second) sound.