BuzzerXCR is an advanced Arduino library for controlling passive buzzers with extended sound effects, PWM-based volume control, and built-in LED feedback support. Designed for alarms, games, sound indicators, and musical effects, it provides a rich set of features for sound manipulation.

-
Easy-to-use API for passive buzzers
-
Volume control via PWM (optional)
-
LED feedback support (optional)
-
Sound effects:
- Slow, Normal, Fast Distortion
- Fade In / Fade Out
- Glissando transitions
- Scheduled notes
-
Melody playback from arrays
-
Serial Terminal interaction with commands (e.g.,
BEEP
,FREQ 440
,STOP
) -
Debug output support for development
- Clone or download this repository as a
.zip
- Open Arduino IDE
- Go to Sketch > Include Library > Add .ZIP Library...
- Select the downloaded zip file
#include <BuzzerXCR.h>
BuzzerXCR buzzer(9, 8); // Buzzer pin, LED pin
void setup() {
buzzer.begin(20);
buzzer.setVolume(80);
buzzer.sound(NOTE_C4, 500);
buzzer.fadeIn(NOTE_E4, 1000);
buzzer.distortion(NOTE_C4, NOTE_G4, FAST);
}
void loop() {}
Sets the pause percentage between notes.
Delays for ms
milliseconds at the end of a melody.
Plays a tone of given frequency (note
) and duration (ms).
Starts sound from low volume and increases gradually.
Starts at full volume and decreases to silence.
Creates a sweeping tone between two notes with chosen speed (SLOW
, NORMAL
, FAST
).
Smooth pitch slide between notes.
Plays an array of notes with corresponding durations.
Plays a series of short tones and pauses, simulating vibration.
Schedules a note to play after a specified delay.
Sets the buzzer volume (0–100%) using PWM.
Turns on or off PWM-based volume control.
Sets tone shaping method (e.g., "linear"
).
Prints debug messages over Serial when enabled.
Reads Serial commands like BEEP
, FREQ 440
, STOP
.
Returns a string representation of the current BuzzerXCR object state.
BEEP
- short beepFREQ 440
- plays 440 Hz toneSTOP
- stops current tone
void loop() {
buzzer.serialControl('\n');
delay(10);
}