A lightweight ESP32 library for controlling passive buzzers with both simple and RTOS-based classes.
- Simple buzzer control using blocking functions
- Advanced non-blocking buzzer control with FreeRTOS
- Support for tone, pulse, and beep generation
- Designed for embedded and industrial applications
Download or clone this repository into your Arduino libraries folder, or install via PlatformIO.
#include "initBuzzer.h"
Buzzer buzzer(12); // GPIO pin
void setup() {
buzzer.begin();
buzzer.beep(200); // Beep for 200ms
}#include "initBuzzer.h"
RtosBuzzer buzzer(12); // GPIO pin
void setup() {
buzzer.begin();
buzzer.tone(1000, 300); // Non-blocking tone at 1kHz for 300ms
}| Method | Description |
|---|---|
begin() |
Initializes the buzzer pin |
write(bool) |
Turns buzzer ON or OFF |
tone(freq, duration) |
Generates a tone at given frequency and duration |
pulse(freq, duration) |
Wrapper for tone with input validation |
beep(time) |
Beep at 1kHz for specified time |
| Method | Description |
|---|---|
begin() |
Initializes buzzer and creates RTOS queue |
tone(freq, duration) |
Sends tone data to queue for non-blocking execution |
tone(duration) |
Shortcut for 3kHz tone |
pulse(freq, duration) |
Same as tone() with validation |
See the examples/ folder for ready-to-run sketches:
SimpleBeep: Basic buzzer controlRtosBeep: RTOS-based multitasking buzzer
- ESP32 board
- Arduino core for ESP32
- FreeRTOS (included in ESP32 core)
This project is licensed under the MIT License – see LICENSE for details.
Milad Nikpendar
GitHub: milad-nikpendar/initBuzzer
Email: milad82nikpendar@gmail.com