Skip to content

Buzzer / Piezo · Arduino Uno guide

Controlling Active Buzzer Module with Arduino Uno

A self-oscillating sounder that produces a fixed tone when correctly powered — learn how to identify, select and use active buzzer modules safely.

Updated November 16, 2026 Arduino C++Also forESP32

What is the Active Buzzer?

An active buzzer is the simplest way to make a project beep. Apply its rated voltage and it sounds; remove the voltage and it stops. There is no frequency to generate and no library to install, because the part contains its own oscillator circuit that drives the sound element at a fixed tone, usually around 2.3 kHz. That makes it ideal for alarms, button feedback, timers and "something went wrong" warnings.

The word active refers to that built-in drive circuit. A passive buzzer looks almost identical but has no oscillator: it is just a sound element, and your microcontroller has to switch it on and off thousands of times a second (for example with tone()) to make a sound. Passive buzzers can play melodies; active buzzers play one note, loudly and with almost no code.

Specifications

Type
Magnetic or piezo sounder with a built-in oscillator
Rated voltage
5 V (3 V and 12 V versions also exist)
Operating voltage
About 4–8 V for typical 5 V parts (some are rated 3–7 V)
Current
Up to 30 mA at rated voltage
Sound output
85 dB or more at 10 cm
Tone
Fixed, about 2.3 kHz ± 300 Hz (varies by part)
Size
12 mm diameter, about 9 mm tall
Polarity
Yes: longer lead or + marking is positive
Operating temperature
About −20 to +70 °C

Typical figures for 12 mm 5 V active buzzers from manufacturer datasheets (for example the LTE12-05 and PUI Audio AI-1223-TWT-5V). Check the markings and listing for your part.

Pinout

PinNameDescription
+PositiveLonger lead, or the leg next to the + mark on top. Connect to the supply or the driver.
−NegativeShorter lead. Connect to ground or to the transistor's collector.

Wiring & code

Setting up Active Buzzer with Arduino Uno

In this guide you will connect an active buzzer to an Arduino Uno and make it beep in different patterns: a start-up chirp, a short confirmation beep, a long tone and an alarm, each triggered by typing a letter in the Serial Monitor. You will also see how to drive a bare buzzer safely with a transistor, how to handle modules that beep when the pin is LOW, and how to beep without freezing the rest of your sketch.

What you need

  • Arduino Uno (R3 or R4) and USB cable

    Quantity
    1
    Note
    Any Uno-compatible board works
  • Active buzzer, 5 V

    Quantity
    1
    Note
    Bare 2-lead buzzer or a 3-pin module
  • NPN transistor (2N2222, BC547, 2N3904 or S8050)

    Quantity
    1
    Note
    Only for a bare buzzer
  • 1 kΩ resistor

    Quantity
    1
    Note
    Base resistor for the transistor
  • 1N4148 diode

    Quantity
    1
    Note
    Optional, recommended for magnetic buzzers
  • Breadboard and jumper wires

    Quantity
    -

Option A: three-pin buzzer module

A module already contains a transistor, so you can connect it directly. This is the quickest way to get started.

Wiring: buzzer module

Module pinArduino Uno pinNote
VCC (+)5VModule supply
I/O (S)D8Control signal
GND (−)GNDCommon ground

Option B: bare buzzer with an NPN transistor

A bare buzzer can draw up to 30 mA, more than the 20 mA an Uno pin should supply continuously. A small NPN transistor does the heavy lifting while the pin only supplies about 4 mA through the base resistor.

Wiring: bare buzzer and transistor

Circuit pointConnect toNote
Buzzer +Uno 5VLonger lead / + mark
Buzzer −Transistor collectorThe transistor switches the buzzer's ground side
Transistor emitterUno GND
Transistor baseUno D8 through 1 kΩNever connect the base directly to the pin
1N4148 diodeAcross the buzzerStripe (cathode) to 5V; optional

Tip

Check your transistor's pin order. A 2N2222 or 2N3904 in a TO-92 package reads E, B, C with the flat face towards you, but the BC547 is C, B, E. Look up the part printed on yours before wiring.

  1. 1Open the Arduino IDE (version 2.x recommended). No extra library is needed.
  2. 2Plug in the Uno, then choose Tools → Board → Arduino Uno and select its port under Tools → Port.
  3. 3Paste the sketch below and click Upload.
  4. 4Open Tools → Serial Monitor and set it to 9600 baud.
  5. 5You should hear two short chirps. Type s, l or a and press Enter to hear each pattern.
sketch.ino
// Active buzzer on an Arduino Uno - SolderHub
// Works with a bare buzzer on an NPN driver, or with a 3-pin module.

const int  BUZZER_PIN = 8;
const bool ACTIVE_LOW = false;   // set to true if your module beeps when the pin is LOW

void buzzerOn()  { digitalWrite(BUZZER_PIN, ACTIVE_LOW ? LOW : HIGH); }
void buzzerOff() { digitalWrite(BUZZER_PIN, ACTIVE_LOW ? HIGH : LOW); }

// Beep `count` times: on for onMs, off for offMs.
void beep(unsigned int onMs, unsigned int offMs, byte count) {
  for (byte i = 0; i < count; i++) {
    buzzerOn();
    delay(onMs);
    buzzerOff();
    delay(offMs);
  }
}

void setup() {
  buzzerOff();                 // set the idle level before the pin becomes an output
  pinMode(BUZZER_PIN, OUTPUT);
  buzzerOff();

  Serial.begin(9600);
  beep(100, 100, 2);           // two short "ready" chirps
  Serial.println(F("Buzzer ready. Type s = short, l = long, a = alarm"));
}

void loop() {
  if (Serial.available()) {
    char c = Serial.read();
    if (c == 's') { beep(80, 80, 1);    Serial.println(F("short beep")); }
    if (c == 'l') { beep(600, 100, 1);  Serial.println(F("long beep")); }
    if (c == 'a') { beep(150, 150, 10); Serial.println(F("alarm")); }
  }
}

How the code works

  • BUZZER_PIN is the Uno pin connected to the module's I/O pin or the transistor's base resistor.
  • ACTIVE_LOW handles both kinds of module. NPN-based modules and the transistor circuit sound on HIGH. Many three-pin modules use a PNP transistor and sound on LOW; set this to true for those. buzzerOn() and buzzerOff() hide the difference from the rest of the code.
  • In setup(), buzzerOff() runs before pinMode(). For an active-LOW module this sets the pin HIGH first, so the buzzer does not give a stray beep the moment the pin becomes an output.
  • beep(onMs, offMs, count) turns the buzzer on and off a number of times. Because an active buzzer has its own oscillator, digitalWrite() is all it needs; no tone() call.
  • In loop(), the sketch reads one character from the Serial Monitor and plays the matching pattern. F("...") keeps the text in flash memory instead of the Uno's small RAM.

Expected output

Right after upload you hear two quick chirps and the Serial Monitor shows:

Output
Buzzer ready. Type s = short, l = long, a = alarm

Typing s gives a short beep, l a long tone and a ten fast beeps, each confirmed with a line in the Serial Monitor. If the buzzer sounds continuously from power-up and goes quiet when it should beep, your module is active-LOW: set ACTIVE_LOW to true and upload again.

Going further: beep without blocking

delay() is fine for a demo, but it freezes the Uno while it waits. In a real project you usually want to keep reading sensors or buttons while a beep plays. This version uses millis() to check the time instead, so loop() never stops. It gives a 100 ms beep once a second, the classic "armed" signal of an alarm.

sketch.ino
// Beep without delay(): the rest of loop() keeps running.
const int BUZZER_PIN = 8;
unsigned long lastToggle = 0;
bool buzzing = false;

void setup() {
  pinMode(BUZZER_PIN, OUTPUT);
}

void loop() {
  unsigned long now = millis();
  unsigned long interval = buzzing ? 100 : 900;   // 100 ms beep every second

  if (now - lastToggle >= interval) {
    buzzing = !buzzing;
    digitalWrite(BUZZER_PIN, buzzing ? HIGH : LOW);
    lastToggle = now;
  }

  // read sensors, update a display, check buttons... nothing is blocked
}

Troubleshooting

SymptomLikely causeFix
No sound at allBuzzer reversed, or it is a passive buzzerSwap the leads; a passive buzzer only clicks on 5 V and needs tone()
Beeps nonstop from power-upActive-LOW moduleSet ACTIVE_LOW = true
Transistor circuit silentTransistor pins in the wrong order, or no base resistorCheck E, B, C for your part; use 1 kΩ from D8 to the base
Faint soundSticker still on, or buzzer powered from 3.3VRemove the sticker; use the 5V pin
Nothing in the Serial MonitorWrong baud rate or portSet 9600 baud and pick the Uno's port
Uno resets on each beepSupply dipping when the buzzer startsAdd a 100 µF capacitor across 5V and GND near the buzzer

Projects to build next

  • Door alarm: a reed switch on D2 and a magnet on the door. Sound the alarm pattern when the door opens.
  • Reaction timer: a random beep, then measure how fast a button is pressed and print the time.
  • Parking sensor: read an HC-SR04 and shorten the gap between beeps as the distance falls.
  • Keypad entry feedback: a 30 ms chirp for every key, a long tone for a wrong code.

Keep learning

Related guides & projects