Arduino UNO R4 - Buzzer
In this guide, we will learn to program the Arduino UNO R4 to make a 12V active buzzer sound loudly. If you need to manage a 5V active or passive buzzer, you can read our Arduino UNO R4 Piezo Buzzer tutorial.
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 STEM V4 IoT Starter Kit (Arduino included) | |
| 1 | × | DIYables STEM V4B IoT Starter Kit (Arduino included) | |
| 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
The 12V Active Buzzer makes a loud noise, good for alarm systems.
Pinout

A 12V active buzzer typically has two pins.
- Connect the negative (-) pin (black) to the GND of the DC power supply.
- Connect the positive (+) pin (red) to the 12V of the DC power supply.
How to Control 12V Active Buzzer
When a 12V active buzzer uses a 12V power supply, it produces a sound. To operate a 12V active buzzer with an Arduino UNO R4, connect a relay between them. The Arduino UNO R4 can control the buzzer through this relay. If you are unfamiliar with relays (their pinout, function, or programming), refer to the relay tutorial for Arduino UNO R4 here.
The MOSFET module is the second choice. The pins, the inside and the code of the module are explained in the Arduino UNO R4 - 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

This image is created using Fritzing. Click to enlarge image
Jumper wires are good for a quick test, but not for a final build. In this case, use a Proto Screw Terminal Block Shield or a Screw Shield V2. It plugs into the Arduino UNO R4 and gives each pin a screw terminal. This is how it looks with the Screw Shield V2:

This image is created using Fritzing. Click to enlarge image
Arduino UNO R4 Code
The code makes the 12V buzzer turn ON for two seconds and OFF for five seconds repeatedly.
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
- Wire the components according to the provided diagram.
- Connect the Arduino Uno R4 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
- Copy the provided code into the Arduino IDE
- Press the Upload button in the Arduino IDE to transfer the code to your Arduino UNO R4
- Listen to the sound generated by the 12V active buzzer
Code Explanation
You can find the explanation in the comments section of the Arduino code above.
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 UNO R4 pin 9 | MOSFET module PWM |
| Arduino UNO R4 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 − |
Do you want the wiring to stay in place? The Arduino UNO R4 works with both the Proto Screw Terminal Block Shield and the Screw Shield V2. Both turn the header pins into screw terminals. See the diagram below for the screw shield version.

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Uno R4 and other components.
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 −.
Arduino UNO R4 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
- 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 UNO R4.
- 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.
※ 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 UNO R4 Piezo Buzzer tutorial. For an AC buzzer or siren, use the relay.