Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
Bettesworth Construction
Arduino

How to Make an Arduino Buzzer Alarm: Basic, PIR and HC-SR04 Builds

Learn how to wire an Arduino buzzer, test it with tone() and noTone(), and add PIR motion or HC-SR04 distance sensing.

By Bettesworth Construction Team 3 min read

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can make an Arduino buzzer alarm by connecting a buzzer to a digital output and using tone() to sound it. Add a PIR sensor to trigger the alarm when it detects motion, or an HC-SR04 ultrasonic sensor to trigger it when an object comes within a chosen distance. The examples below use an Arduino Uno Rev3 and beginner-friendly breadboard wiring.

Test the buzzer on its own first

Start with the simplest circuit so you can confirm the buzzer and Arduino work before adding a sensor. You need an Arduino Uno Rev3, a buzzer or piezo speaker, jumper wires and a breadboard. A 100 ohm resistor is optional in the cited starter example. Check your buzzer’s type and wiring; the instructions below assume a two-lead part that can be connected between an output pin and ground.

Wiring

  • Connect the buzzer’s positive lead to digital pin 9.
  • Connect its negative lead to an Arduino GND pin.

Arduino Project Hub’s starter example uses pin 9, sets it as an output, plays a 1 kHz tone for one second, and then stops it for one second. See the Arduino Project Hub buzzer example.

Code

const int buzzer = 9;

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

void loop() {
  tone(buzzer, 1000);  // Start a 1 kHz tone
  delay(1000);
  noTone(buzzer);      // Stop the tone
  delay(1000);
}

Upload the sketch. The buzzer should sound for one second, pause for one second, and repeat. tone() starts a frequency-driven signal; noTone() stops it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Shutao 10PCS 5V 12x9.5mm Passive Buzzer 12MMx9.5MM Resistance 5V Common Use Mini Piezo Buzzers Kit 2 Terminals Active 12095 Electronic Alarm Long Continuous Beep Tone Alarm Ringer for Arduino
  • High-volume boosts alerts with a robust 3-decibel output alert; ideal for Arduino, DIY electronics, and safety alarms
  • Alarm pinger 9*5.5mm mini piezo buzzers easy 5V plug & play operation; Works seamlessly with computers and development boards
  • Compact & energy efficient design draws <250mA current for versatile project integration
  • Superior Sensitivity ensures clear audible signals from electronic toys to equipment
  • Mini active piezo buzzer module with 9*5.5mm size, fits snugly in tight spaces without compromising sound quality

Choose a sensor that matches the alarm you want

A PIR sensor and an HC-SR04 do different jobs. A PIR responds to movement; an HC-SR04 measures distance and can trigger when an object is near. The choice affects where you mount the sensor, what causes the alarm, and how much code and wiring are needed.

Sensor What triggers the buzzer Example wiring and behavior Practical considerations
PIR motion sensor Detected movement in its sensing area. The cited Arduino Project Hub burglar-alarm project pairs a PIR with a buzzer and a 16×2 LCD; it specifies a PIR with a stated 7 m range. Its project description says it starts a timer to record when someone entered. Project description. Mount it facing the area where movement matters. Its output depends on motion in its field of view, not a measured distance. The cited project does not establish field-of-view details or controlled false-alarm performance.
HC-SR04 ultrasonic sensor An object measured at or inside a chosen distance. The cited example uses trigger pin 9, echo pin 10 and buzzer pin 8; it sounds when the calculated distance is 50 cm or less. Project details. Point the sensor toward the space to monitor and choose a distance threshold that suits the placement. It needs separate trigger and echo connections and code to time the returning echo. The cited example does not give accuracy or false-alarm benchmarks.

Neither example is a tested security system: the cited project information does not provide independent loudness, detection-accuracy or false-alarm measurements.

Rank #2
Passive Buzzer Module, 5V Piezoelectric Alarm for Arduino, ESP32, Raspberry Pi, 2 Pieces
  • Passive Piezo Buzzer Module (2-Pack) – Generates sound based on input signal frequency, allowing for customizable audio tones and sound effects in DIY projects.
  • Adjustable Frequency Output – Control pitch and tone using PWM signals from your microcontroller—ideal for creating music or alerts.
  • Low Power & Broad Voltage Support – Operates with minimal power and works with 3.3V to 5V systems, including Arduino, ESP32, and Raspberry Pi.
  • Compact & Easy to Use – Small, lightweight design with simple wiring makes it perfect for embedded systems, smart devices, or educational kits.
  • Tutorials Available Online – Search “DIYables passive buzzer module” for example projects using Arduino, ESP32, ESP8266, and Raspberry Pi.

Build an HC-SR04 distance alarm

This option alarms when an object is within 50 cm, using an HC-SR04, a 5 V active buzzer, an Uno Rev3, jumper wires and a breadboard. The cited project uses a 100×160 breadboard. A small change to the threshold in the code adjusts the trigger distance. See the Arduino Project Hub HC-SR04 project.

Pin map

Part Connection
HC-SR04 VCC Arduino 5V
HC-SR04 GND Arduino GND
HC-SR04 TRIG Digital pin 9
HC-SR04 ECHO Digital pin 10
5 V active buzzer positive Digital pin 8
5 V active buzzer negative Arduino GND

All parts must share a common ground. Keep the buzzer on pin 8 and the sensor’s trigger and echo on pins 9 and 10, respectively, to match this sketch.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Passive Buzzer Module, 5V Piezoelectric Alarm for Arduino, ESP32, Raspberry Pi, 5 Pieces
  • Passive Buzzer Module: Generates sound based on input signals, perfect for custom audio alerts in various projects.
  • Frequency Adjustable: Control the tone and pitch by adjusting the input frequency, ideal for creating different sound effects.
  • Low Power Consumption: Operates efficiently with minimal power, compatible with 3.3V to 5V systems.
  • Wide Compatibility: Tutorials for Arduino, ESP32, ESP8266, Raspberry Pi are provided => Search for: DIYables passive buzzer module.
  • Compact and Easy to Use: Small form factor, ideal for integrating into compact designs and quick prototyping.

Code

const int buzzer = 8;
const int trigPin = 9;
const int echoPin = 10;

void setup() {
  pinMode(buzzer, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  long timing = pulseIn(echoPin, HIGH);
  float distance = (timing * 0.034) / 2;

  if (distance <= 50) {
    tone(buzzer, 500);
  } else {
    noTone(buzzer);
  }

  delay(100);
}

The sketch sends a short pulse on TRIG, measures how long ECHO stays high with pulseIn(), and converts that timing into a distance using the example’s formula. It sounds a 500 Hz tone at 50 cm or less and stops it when the measured distance is greater.

Adjust and troubleshoot

  • Change distance <= 50 to another threshold in centimetres if you want the alarm to trigger nearer or farther away.
  • If the buzzer is silent, verify its polarity, the pin 8 and GND connections, and that the component is a compatible 5 V active buzzer.
  • If readings do not trigger as expected, verify the sensor’s VCC and GND, and check that TRIG and ECHO are connected to pins 9 and 10 respectively.
  • pulseIn() waits for an echo pulse. If no echo arrives, it can return zero; this basic example has no explicit timeout or invalid-reading handling. For a more robust build, add a timeout and treat missing echoes as no valid distance rather than as a nearby object.

Build a PIR motion alarm

Use a PIR sensor when the event you care about is movement rather than an object crossing a distance threshold. The cited Arduino Project Hub burglar alarm combines a PIR, buzzer and 16×2 LCD, and specifies a PIR sensor with a stated 7 m range. That range is the project’s stated sensor figure, not an independently verified detection result for every installation. The project description also says it starts a timer to record when someone entered. See the Arduino Project Hub PIR alarm project.

Rank #4
20Pcs 12085 Passive Buzzer 12MM*8.5MM 42R Resistance 3V 5V 9V 12V in Common Use Mini Piezo Buzzers Kit, Active Buzzer Electronic Alarm Magnetic Long Continuous Beep for Arduino
  • Product Name: Electronic Alarm Buzzer; Dimension: 0.47X0.37"/12x8.5mm(Dx H).
  • Application:Suitable for electronic toys, safety equipment, development boards,etc
  • Plastic housing, 3-5V input, 2 terminals, 2000HZ resonance frequency
  • Feature: All multi-chip integrated circuits using gold wire ball bonding, complex production process, long life, stable performance, high rate of qualified products.
  • 20PCS DC 3V Active Buzzer 2 Terminals for Arduino Raspberry Pi,Magnetic Electronic Continous Long Beep Tone Alarm Sounder

For a basic PIR-and-buzzer version, connect the sensor’s power and ground to the supply and common ground specified for your particular module, connect its digital output to an Arduino input pin, and connect the buzzer as in the buzzer-only test. PIR module pin labels and operating requirements can vary, so follow the documentation for the exact module rather than assuming every board uses the same pinout.

In code, read the PIR output with digitalRead(). When the sensor output indicates motion, call tone(buzzerPin, 1000); otherwise call noTone(buzzerPin). This is a basic behavior outline rather than a full project sketch because the cited PIR project information does not state its Arduino input pin or provide its code. A more useful alarm can latch after the first detection, record a start time, or require a disarm action; those behaviors need to be added deliberately.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
20PCS Passive Buzzer, 42R Resistance 3V 5V 9V 12V Mini Piezo Buzzers Kit
  • Passive Buzzer with 2000Hz Core Tone: This is a passive electronic alarm buzzer with a 2000Hz resonance frequency. Unlike active buzzers that produce a single fixed tone, this component requires an external PWM/square wave signal from your microcontroller. By varying the input frequency, you can shift the tone pitch or generate simple melodies — perfect for electronic toys, DIY alarms, and safety equipment where distinct audio feedback is essential.
  • Compact 2-Pin Design: Designed for space-constrained projects, this buzzer measures only 0.47 x 0.37 inches (12 x 8.5mm) . It features a simple 2-terminal pin configuration. Operating on a wide 3-5V DC input, it is lightweight and housed in durable black plastic.
  • Long Lifespan & Stable Performance: Built with premium manufacturing standards, this buzzer utilizes multi-chip integrated circuits with gold wire ball bonding technology. This complex production process ensures superior connection reliability, extended operational life, and stable sound output.
  • NOTE: Do NOT connect directly to DC 3V/5V. This buzzer WILL NOT MAKE SOUND if connected only to positive and negative power. It REQUIRES an external oscillating signal (PWM/Square Wave) typically generated by an Arduino tone() function via a transistor driver circuit.
  • Versatile Applications: This 2-terminal passive buzzer is a universal fit for a wide range of applications: Electronic Toys: Talking dolls, RC car reverse beeps, game buzzers; Development Boards: Sound experiments with Arduino, Raspberry Pi Pico, ESP32 (requires external transistor driver); Safety Equipment: Low-power alarms for smoke detectors, door open alerts, and portable medical device reminders; General PCB Mounting: Standard spacing fits most prototyping PCBs and perfboards.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Make the alarm safer and more useful

These projects are learning prototypes, not certified security systems. A hobby sensor and buzzer do not establish reliable coverage, tamper resistance, backup power, or a guaranteed alarm level. Do not rely on them as the sole protection for a building, people, equipment, or hazardous area.

  • Add a clear disarm control: Use a switch or button input so the alarm can be silenced intentionally, and choose a startup state that does not sound unexpectedly.
  • Control repeated triggers: Add a latch or cooldown if the sensor output flickers or repeated alerts are disruptive. Choose the behavior based on how quickly the area should be checked again.
  • Handle sensor faults: For an HC-SR04, check for missing echo readings; for a PIR, account for its module’s startup and output behavior as specified by its manufacturer.
  • Test placement in the actual space: Check which motion or objects are detected at the installed angle and distance. The cited project examples do not supply controlled performance benchmarks.

Parts to gather

An Arduino UNO R3 starter kit is a convenient starting point because it commonly bundles a board, breadboard and jumper wires; verify the contents before buying, since kit contents vary. For the basic sound test, add a compatible buzzer or piezo speaker. For sensing, choose either an HC-SR04 ultrasonic sensor and 5 V active buzzer for a proximity alarm, or a PIR motion sensor module for movement detection. Arduino’s official tutorial catalog lists “Getting Started with Modulino Buzzer,” “Getting Started with Modulino Distance,” and UNO R3 among supported products, showing that buzzer and distance modules remain in its maintained product ecosystem: Arduino tutorials.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

More from the Site Office

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.