Built-in project · Arduino Uno R3

Active buzzer module on pin 3, on an Arduino Uno

An active buzzer on pin 3 beeps on and off every second: HIGH sounds it, LOW stops it. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Beginner About 5 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $30. On Mokxi they're free.

The circuit runs here once the page has loaded.

What you'll learn

  • Active versus passive buzzers
  • Switching a part with digitalWrite
  • Timing a pattern with delay
  • Difficulty: Beginner
  • Time: About 5 minutes
  • Board: Arduino Uno R3
  • Parts: 3

How it works

An active buzzer has its own tiny oscillator inside, so it makes a tone whenever it gets power. The Uno does not have to make the sound, only switch it on and off.

Pin 3 goes to the buzzer and the other side goes to ground. The sketch sets pin 3 HIGH for one second, so it beeps, then LOW for one second of silence, and repeats.

Parts list

3 parts, plus the jumper wires. They retail for about $30; on Mokxi they're free.

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
Buzzer pin 2Arduino Uno R3 pin GND
Buzzer pin 1Arduino Uno R3 pin 3

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// An active buzzer on pin 3: one second on, one second off.
//
//   module S -> pin 3   + -> 5V   - -> GND
//
// An active buzzer has its own oscillator, so a steady HIGH is enough.

const int BUZZER = 3;

void setup() {
  pinMode(BUZZER, OUTPUT);
  Serial.begin(9600);
  Serial.println("Mokxi Uno: active buzzer on pin 3");
}

void loop() {
  digitalWrite(BUZZER, HIGH);
  delay(1000);
  digitalWrite(BUZZER, LOW);
  delay(1000);
}

Code walkthrough

The key functions of the sketch, and what each one does.

setup sketch.ino

Sets BUZZER (pin 3) as an output and starts serial at 9600 with a hello message.

void setup() {
  pinMode(BUZZER, OUTPUT);
  Serial.begin(9600);
  Serial.println("Mokxi Uno: active buzzer on pin 3");
}

loop sketch.ino

Writes HIGH to the buzzer and waits 1000 ms, then writes LOW and waits 1000 ms. A steady HIGH is enough, because the buzzer makes its own tone.

void loop() {
  digitalWrite(BUZZER, HIGH);
  delay(1000);
  digitalWrite(BUZZER, LOW);
  delay(1000);
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The buzzer stays silent. This project
    Check the polarity: pin 1 of the buzzer goes to Arduino pin 3, and pin 2 goes to GND.
  • The buzzer makes a constant tone, or you cannot change its pitch. Buzzer
    An active buzzer has its own oscillator, so it only beeps on and off. A passive buzzer needs tone() to set pitch. Check which type you have.
  • The buzzer is silent or very quiet. Buzzer
    Check polarity: the plus mark goes to the pin or supply. For loud buzzers, drive them through a transistor instead of straight from a pin.
  • Upload fails or nothing runs after wiring pins 0 and 1 to a module. Arduino Uno R3
    Pins 0 and 1 are the USB serial port. Move the module to other pins, or unplug it while uploading. Also check the right board is selected.
  • Pins misbehave or the board resets when you power motors or servos from it. Arduino Uno R3
    Each I/O pin gives about 20 mA, 40 mA max. Power motors and servos from their own supply and join its ground to the Uno's GND.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.