Arduino MKR WiFi 1010 - Buzzer
Welcome to this guide on controlling a 12V active buzzer with your Arduino MKR WiFi 1010! Learn how to create loud, attention-grabbing alarm sounds perfect for security systems, emergency alerts, and industrial applications.
What You'll Learn:
- Understanding 12V active buzzer operation and capabilities
- Why a relay is required (and how it works)
- Proper wiring for high-voltage buzzer control
- Programming the Arduino to create alarm patterns
12V Buzzer vs 5V Piezo Buzzer - Which to Use?
- 12V Active Buzzer (this tutorial):
- Volume: Very loud (90-110 dB)
- Power: Requires 12V external supply
- Control: Needs relay switching
- Best for: Alarms, security systems, outdoor warnings, industrial alerts
- Sound: Single fixed frequency, very piercing
- 5V Piezo Buzzer (see this tutorial):
- Volume: Moderate (70-85 dB)
- Power: Works directly from Arduino
- Control: Direct connection, no relay needed
- Best for: Button feedback, simple alerts, indoor notifications
- Sound: Can play tones and melodies
- High volume: Typically 90-110 decibels (comparable to a car horn or chainsaw)
- Fixed frequency: Built-in oscillator produces one tone (cannot play melodies)
- 12V operation: Requires external power supply
- High current: Typically 30-100mA (too much for Arduino pins)
- Immediate response: Sound starts instantly when powered
- Security alarms: Intruder detection, door/window alerts
- Fire alarms: Smoke detector audible warnings
- Industrial safety: Equipment malfunction alerts
- Emergency signals: Panic buttons, evacuation warnings
- Vehicle alarms: Backup warnings, horn systems
- Positive (+) pin (red wire): Connects to the +12V output of your DC power supply. This is where the power flows in.
- Negative (-) pin (black wire): Connects to the ground (GND) of your DC power supply. This completes the circuit.
- Low-power side: Arduino controls the relay with a 3.3V signal (low current)
- High-power side: Relay switches the 12V power to the buzzer (high current)
- Arduino sends LOW signal to relay → Relay opens → Buzzer OFF
- Arduino sends HIGH signal to relay → Relay closes → Buzzer ON
- Relay control: Arduino digital pin → Relay IN (signal) pin
- Relay power: Arduino 5V → Relay VCC, Arduino GND → Relay GND
- Buzzer circuit: 12V power supply (+) → Relay COM terminal
- Buzzer connection: Relay NO (Normally Open) → Buzzer (+) red wire
- Return path: Buzzer (-) black wire → 12V power supply GND
- Common ground: Connect Arduino GND and 12V supply GND together
- Assemble the circuit - Connect all components following the wiring diagram above. Triple-check power connections before applying power!
- Connect to computer - Use a Micro USB cable to connect the Arduino MKR WiFi 1010 to your computer.
- Open Arduino IDE - Launch the Arduino IDE application.
- Select board and port - Choose Arduino MKR WiFi 1010 and select the appropriate COM port.
- Load the code - Copy the complete code above and paste it into the Arduino IDE.
- Upload - Click the Upload button to transfer the code.
- Test the buzzer - The buzzer should start beeping loudly in the programmed pattern. Warning: It's LOUD! Have your fingers ready to disconnect power if needed in a quiet environment.
- Setup: Configure the relay control pin as OUTPUT
- Loop:
- Change timing for different alarm patterns (rapid beep: 100ms on, 100ms off)
- Add button control to activate/deactivate the alarm
- Combine with sensors (motion, door, temperature) for automatic triggering
- Create Morse code patterns by varying on/off durations
- Implement different patterns for different alert types
- Do the same setup as in the Quick Steps of the relay part above.
- Wire the buzzer and the MOSFET module as shown in the diagram. Keep the 12V adapter unplugged.
- Upload the code above to the Arduino MKR WiFi 1010.
- Plug in the 12V adapter.
- Open the Serial Monitor at 9600 baud.
- Listen to the buzzer: you hear the fast beeps with no relay click.
Rule of Thumb: Need to wake someone across the house or outdoors? Use 12V. Need simple UI feedback? Use 5V piezo.
There are two ways to drive the 12V buzzer. A relay is simple, but it clicks every time it switches. A MOSFET module does the same job with no sound, and it can switch very fast. This is good for alarm beeps. We will try both ways in this tutorial.
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of 12V Active Buzzer
A 12V active buzzer is a high-power audio output device designed for applications requiring loud, attention-grabbing sound. The term "active" means it has internal oscillator circuitry—you simply apply power, and it produces a loud, continuous tone at a fixed frequency.
Key Characteristics:
Common Applications:
Pinout

The 12V active buzzer has two clearly marked terminals:
Polarity Matters: Unlike passive buzzers, active buzzers require correct polarity. Reversing the connections can damage the internal electronics. Always double-check: red to +12V, black to GND!
How to Control 12V Active Buzzer
The Challenge: The buzzer requires 12V and substantial current (30-100mA). Arduino pins provide only 3.3V and a maximum of 15mA. Direct connection is impossible and would damage your Arduino!
The Solution: Use a relay as an electronic switch. The relay acts as a bridge:
How It Works:
The relay physically separates the low-voltage Arduino circuit from the high-voltage buzzer circuit, ensuring safety.
New to Relays? If you're unfamiliar with relay operation, pinout, and programming, start with our comprehensive Arduino MKR WiFi 1010 - Relay tutorial. Understanding relays is essential for this project!
The MOSFET module is the second choice. The pins, the inside and the code of the module are explained in the Arduino MKR WiFi 1010 - MOSFET Module tutorial.
Relay vs MOSFET Module for a 12V Buzzer
| Relay | MOSFET Module | |
|---|---|---|
| What it can do | turn the buzzer on or off | turn the buzzer on or off |
| Noise when switching | a click every time, mixed with the beep | no sound, you hear only the beep |
| How fast it switches | slow, a few milliseconds | very fast |
| Fast beeps | the relay clicks loudly and wears out fast | no problem |
| Life | the contacts wear out after many switches | nothing moves, so it lasts long |
| Type of power | AC or DC | DC only |
| Buzzer power supply | any voltage the relay is rated for | about 6V or more |
| Isolation from the Arduino | yes, between coil and contacts | yes, by the PC817 optocoupler |
| Good for | slow ON/OFF, like ON for a few seconds | alarm patterns with many short beeps |
If the buzzer beeps slowly, the relay is fine. If you want an alarm with many short beeps, the MOSFET module is the better pick.
Wiring Diagram
Carefully follow this wiring diagram. Pay special attention to the power connections—mixing up 12V and 3.3V connections can damage components!

This image is created using Fritzing. Click to enlarge image
No breadboard? The same circuit can be wired without one, as shown below:

This image is created using Fritzing. Click to enlarge image
Critical Wiring Points:
Safety Reminder: Never connect the 12V supply directly to Arduino pins! The relay isolates the high-voltage buzzer circuit from the low-voltage Arduino.
Arduino MKR WiFi 1010 Code
This program creates a repeating alarm pattern: the buzzer sounds for one second, then stays silent for two seconds. This on-off pattern continues indefinitely.
Pattern: BEEP (1s) - silence (2s) - BEEP (1s) - silence (2s) - repeat...
This timing pattern is easily customizable—adjust the delay values to create different alarm patterns (rapid beeping, slow pulses, etc.).
Detailed Instructions
New to Arduino MKR WiFi 1010? Start with our Getting Started with Arduino MKR WiFi 1010 tutorial for board setup.
Follow these steps:
Safety Note: The 12V buzzer is significantly louder than phone or computer speakers. Test in an appropriate environment and protect your hearing during initial testing!
Code Explanation
The code is well-commented, but here's the logic flow:
- Send HIGH to relay (buzzer turns ON)
- Wait 1000ms (buzzer sounds for 1 second)
- Send LOW to relay (buzzer turns OFF)
- Wait 2000ms (silence for 2 seconds)
- Repeat forever
Customization Ideas:
How to Make Alarm Beeps with MOSFET Module
Now let's replace the relay with a MOSFET module. The buzzer works the same, but there is no click, so it can beep fast like a real alarm.
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
| From | To |
|---|---|
| Arduino MKR WiFi 1010 pin 6 | MOSFET module PWM |
| Arduino MKR WiFi 1010 GND | MOSFET module GND |
| 12V adapter + | MOSFET module + |
| Buzzer red wire (+) | MOSFET module + (same terminal as the adapter +) |
| Buzzer black wire (−) | MOSFET module LOAD |
| 12V adapter − | MOSFET module − |
Most 12V active buzzers have a small circuit inside and do not need a flyback diode. If your buzzer is a magnetic type (it has a coil inside), add a 1N4007 or 1N5819 diode across it. The side with the stripe (cathode) goes to the buzzer +, the other side goes to the buzzer −.
The Arduino MKR WiFi 1010 pin gives only 3.3V, but this is enough for the MOSFET module. No level shifter is needed. Never connect the 12V to any pin of the Arduino MKR WiFi 1010.
Arduino MKR WiFi 1010 Code
What the buzzer does: it beeps 10 times fast, then makes one long beep, then stays quiet for 3 seconds. Then it starts again.
An active buzzer makes its own sound. Only turn it fully ON or fully OFF with digitalWrite(). Do not use analogWrite() (PWM) to change the volume, because the sound will be weak or strange.
Detailed Instructions
※ NOTE THAT:
The MOSFET module works with DC only, and the buzzer power supply must be about 6V or more. For a 5V buzzer, see the Arduino MKR WiFi 1010 - Piezo Buzzer tutorial. For an AC buzzer or siren, use the relay.