How to wire a buzzer to an Arduino Nano
To wire a buzzer to an Arduino Nano, connect 1 to pin 8 and 2 to GND. A small passive piezo draws a few milliamps, so it runs straight from the pin with its other leg on ground. The sketch below uses no library beyond what the board includes. It plays a four-note phrase and repeats it, printing Playing once and Again after each phrase.
- 5 V logic
- Library: none
- 2 wires
Buzzer to Arduino Nano wiring table
Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.
| Buzzer pin | Arduino Nano pin | Wire color | Why |
|---|---|---|---|
| Pin 1 | pin 8 | amber | tone() puts a square wave at the note’s frequency on this pin. |
| Pin 2 | GND | blue | Ground. A passive piezo has no polarity. |
Power and logic levels for buzzer and Arduino Nano
Logic level
The Arduino Nano’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.
This pair
A small passive piezo draws a few milliamps and runs straight from the pin. On the ATmega328P, tone() takes Timer2, so PWM on pins 3 and 11 pauses while a note plays.
Pins to leave alone
A6 and A7 are analog only: pinMode(A6, OUTPUT) does nothing and digitalRead(A7) is not there to call. D0 and D1 are the USB serial port.
The working code for the Arduino Nano
Library: none, the sketch makes the note with tone(). This is the sketch the circuit above runs.
const int BUZZER_PIN = 8; // pin 8
// C, E, G, C: an arpeggio, a quarter second a note.
const int NOTES[] = {523, 659, 784, 1047};
void setup() {
Serial.begin(9600);
Serial.println("Playing");
}
void loop() {
for (int i = 0; i < 4; i++) {
tone(BUZZER_PIN, NOTES[i], 200); // returns at once; the note plays on
delay(250);
}
noTone(BUZZER_PIN);
Serial.println("Again");
delay(500);
}
What you should see
The buzzer plays a short four-note phrase and then plays it again. The serial monitor, at 9600 baud, prints Playing at the start and Again after each phrase.
A buzzer that clicks once but never sounds a note is an active buzzer: it ignores tone() and needs only a HIGH level.
The serial monitor prints this, recorded from the circuit above running for two seconds:
Playing
AgainCommon mistakes wiring a buzzer to an Arduino Nano
An active buzzer
An active buzzer has its own oscillator and beeps at one pitch whenever it has power, so tone() cannot change its note. For melodies you need a passive one; the two look the same, but the active kind usually has a sticker on top.
No delay between notes
tone() does not wait for the note to finish. Call it twice in a row and only the second note plays. Wait at least as long as the note, as the sketch does.
Picking A6 or A7
A6 and A7 look like the other analog pins but are inputs to the ADC and nothing else. the buzzer on either of them never sees a digital level. Any of D2 to D13 or A0 to A5 works.
Build your own buzzer project
Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.