Arduino Active Buzzer Code: Generate Custom Sounds & Alerts
An Arduino active buzzer is a simple and versatile circuit element that can produce tones and beeps, making it an excellent component for feedback or alert systems in various projects. Here, we'll delve into the basics of an active buzzer, how to connect it with an Arduino board, and provide code snippets to get you started.
Before we dive into the code, let's briefly understand active buzzers. Active buzzers come with an integrated oscillator circuit, simplifying the setup process compared to passive buzzers. They draw power directly from the Arduino and do not require additional resistors or capacitors.
Arduino Active Buzzer Circuit & Connection
To use an active buzzer with an Arduino board, follow these simple steps:
1. Connect the Positive leg (usually marked 'VCC' or '+') to one of the Arduino's 5V or 3.3V pins.
2. Connect the Negative leg (usually marked 'GND') to one of the Arduino's GND pins.
3. Connect the Signal leg (usually marked 'SIG' or 'DIG') to one of the Arduino's digital pins.
Wiring Diagram
The wiring diagram, as shown below, illustrates the connections:

Components Required
Here's a list of components needed for this project:
- Arduino Uno or compatible board
- Active Buzzer
- Jumper wires ( Female to Male )
ARSNTLC-7 Arduino Active Buzzer Library
Some active buzzers, like the popular ARSNTLC-7 model, offer tone control using PWM (Pulse Width Modulation). For better control over pitch, we'll use the ARSNTLC-7 Arduino library. You can install it via the Arduino IDE Library Manager.
Here's how to use it:
Creating Tones
The following code snippet creates a simple tone using the ARSNTLC-7 library:
#include <ARSNTLC-7.h>
ARSNTLC-7 buzzer(9); // Initialize the buzzer on pin 9
void setup() {
pinMode(9, OUTPUT);
buzzer.tone(440); // Play a 440Hz tone
}
void loop() {}
Changing Pitch
To change the pitch of the sound, adjust the tone frequency. For instance, to play an 'A' note at 440Hz:
buzzer.tone(440);
And for a 'C' note at 523Hz:
buzzer.tone(523);
Now that you've learned how to connect an active buzzer to an Arduino board and control its pitch, it's time to incorporate it into your projects. Happy buzzing!
Remember, active buzzers are fantastic for creating alerts, beeps, or even simple melodies. With a little experimentation, you can create engaging and interactive projects using this humble component. So go ahead, explore, and build something incredible with your Arduino and active buzzer!