2.4 Buzzer Beep

The goal of this example is to introduce you to sound generation using a passive buzzer and the tone() function.
A passive buzzer can produce sounds of different frequencies, meaning you can play tones, melodies, or sound effects.
In this example, your Soldered NULA MINI board will play a short melody when powered on.
In this documentation you will learn:
- How to connect and control a passive buzzer.
- How to generate tones of different frequencies using
tone(). - How to stop the sound using
noTone(). - How to play a simple melody using arrays.
Hardware required
- 1× Soldered NULA MINI board
- 1× Passive buzzer
- 1× Breadboard
- Jumper wires
- USB-C cable

Putting the components together
1. Connect the buzzer
| Buzzer Pin | NULA MINI Pin |
|---|---|
| Positive (+) | IO5 |
| Negative (–) | GND |
Make sure you’re using a passive buzzer, not an active one.
A passive buzzer can produce a range of frequencies, while an active buzzer can only beep at one fixed pitch.

Understanding sound and frequency
Sound is produced by vibrations in the air.
When we rapidly switch a digital pin between HIGH and LOW (creating a square wave) at a certain frequency, the buzzer vibrates and produces a tone.
| Note | Frequency (Hz) |
|---|---|
| C4 | 262 |
| D4 | 294 |
| E4 | 330 |
| F4 | 349 |
| G4 | 392 |
| A4 | 440 |
| B4 | 494 |
| C5 | 523 |
Higher frequency leads to higher pitch while lower frequency leads to a deeper tone.
How it works
- Each note's frequency is stored in the
melody[]array. - The corresponding duration is stored in the
noteDuration[]array. - The loop plays each note in order using
tone(). - At the end of the melody, buzzer is silenced using
noTone().
Code
/*
This is a variable to which we assign the number of the pin that we connected the buzzer to.
In this example, we’ll use IO5 as the output pin. If you want, you can use any other digital pin that has ADC capabilities.
*/
const int BUZZER_PIN = 5;
/*
We will use two arrays — one for note frequencies (in Hertz) and one for note durations.
These define a short melody that the buzzer will play.
*/
int melody[] = { 262, 294, 330, 349, 392, 440, 494, 523 }; // C4 to C5
int noteDuration[] = { 4, 4, 4, 4, 4, 4, 4, 2 }; // Quarter notes (last one is half note)
void setup() {
/*
The tone() function generates a square wave of a given frequency (and duration)
on a specific pin, which makes the buzzer produce sound.
*/
pinMode(BUZZER_PIN, OUTPUT);
Serial.begin(115200);
Serial.println("Playing melody...");
// Loop through the melody and play each note
for (int i = 0; i < 8; i++) {
int duration = 1000 / noteDuration[i]; // Convert duration type to milliseconds
tone(BUZZER_PIN, melody[i], duration); // Play the note
delay(duration * 1.3); // Wait a bit before the next note
}
// Stop tone when done
noTone(BUZZER_PIN);
Serial.println("Melody finished!");
}
void loop() {
// Nothing happens here — melody plays once in setup()
}
Full example

Check out the full example code on the link below:
2.4_Buzzer_Beep.ino
Example that shows how to use the tone() function to play a simple melody on a passive buzzer connected to IO5.