An Arduino library for creating recognizable sound patterns through a digital output connected to a simple buzzer. All patterns are based on Morse code timing for distinct, universally recognizable signals.
- 6 preset sound patterns for common application events
- Based on international Morse code timing standards
- Supports both standard Arduino and RTOS (FreeRTOS) environments
- Clean OOP design with abstract base class for easy platform adaptation
Connect a passive buzzer between a digital pin and GND:
Arduino Pin (e.g. D4) ---[Buzzer]--- GND
- Download or clone this repository
- Copy the folder into your Arduino
libraries/directory - Restart the Arduino IDE
- Include the library:
#include <ArduinoBuzzerSoundsRG.h>
#include <ArduinoBuzzerSoundsRG.h>
BuzzerSoundsRgNonRtos buzzer(4); // Buzzer on pin 4
void setup() {
buzzer.playSound(BuzzerSoundsRgBase::SoundType::OK);
}
void loop() {}| SoundType | Morse Pattern | Sound | Recommended Use Case |
|---|---|---|---|
DbReadError |
U (..- ) |
dit-dit-dah | Data/read errors — noticeable but not alarming |
NoAuth |
Custom (.....- ) | 5x dit + dah | Access denied — insistent rapid beeping |
AuthOk |
A (.- ) |
dit-dah | Authentication successful — quick confirmation |
SOS |
SOS (...---...) |
dit-dit-dit dah-dah-dah dit-dit-dit | Critical errors / emergencies |
SMS |
SMS (...--...) |
dit-dit-dit dah-dah dit-dit-dit | Notifications / incoming messages |
OK |
OK (-----.- ) |
dah-dah-dah dah-dit-dah | Successful operation / system ready |
All timings follow the international Morse code standard with a base unit of 100ms:
| Timing | Duration | Description |
|---|---|---|
DitLength |
100ms | Short signal (1 unit) |
DahLength |
300ms | Long signal (3 units) |
DitPause |
100ms | Pause between elements within a letter |
DahPause |
300ms | Pause between letters |
WordPause |
700ms | Pause between words (available for custom use) |
BuzzerSoundsRgBase — Abstract base class. Cannot be instantiated directly.
BuzzerSoundsRgBase(int buzzerPin)— Constructor, sets the pin as OUTPUT.~BuzzerSoundsRgBase()— Virtual destructor, sets pin LOW.void playSound(SoundType sound)— Plays one of the preset sound patterns.
BuzzerSoundsRgNonRtos — Concrete implementation for standard Arduino (uses delay()).
BuzzerSoundsRgNonRtos(int buzzerPin)— Constructor.
BuzzerSoundsRgBase::SoundType— Selects the sound pattern (see table above).BuzzerSoundsRgBase::MorseCodeTiming— Timing constants for Morse code elements.
The library avoids any RTOS dependency. To use it with FreeRTOS, derive your own class and override the pause() method:
#include <ArduinoBuzzerSoundsRG.h>
class BuzzerSoundsRgRtos : public BuzzerSoundsRgBase {
public:
explicit BuzzerSoundsRgRtos(int buzzerPin) : BuzzerSoundsRgBase(buzzerPin) {}
protected:
void pause(BuzzerSoundsRgBase::MorseCodeTiming pause) override {
vTaskDelay(pdMS_TO_TICKS(static_cast<int>(pause)));
}
};MIT License — see LICENSE for details.