ESP32 C3 Super Mini - Buzzer
Learn how to program your ESP32 C3 Super Mini to control a 12V active buzzer and generate loud, attention-grabbing sounds perfect for alarms and notifications. This beginner-friendly tutorial walks you through everything you need to create a working buzzer project.
In this tutorial, you'll learn:
- What a 12V active buzzer is and why it needs a relay
- How to wire the buzzer to ESP32 C3 Super Mini using a relay module
- How to write code to control the buzzer ON/OFF timing
- How to create loud alarm sounds for your projects

Note: If you want to control 5V active/passive buzzer, check out this ESP32 C3 Super Mini 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 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 is an electronic buzzer that produces a loud, high-decibel sound suitable for alarm systems and attention alerts.
Key features:
- Operates at 12V DC power supply
- Produces loud sound (much louder than standard 5V buzzers)
- "Active" means it has built-in oscillator - just apply power to make sound
- Perfect for security alarms, notification systems, and warning signals
- Requires external power supply (cannot be powered directly by ESP32)
- Must be controlled through a relay module for safe operation
Why use a 12V buzzer?
- Significantly louder than 5V buzzers
- Better for outdoor or noisy environments
- Ideal for alarm and alert systems where sound needs to carry
Pinout
The 12V Active Buzzer pinout is simple with only two connection points.

- Negative (-) pin (black): Connect to GND of 12V DC power supply
- Positive (+) pin (red): Connect to 12V positive of DC power supply
How to Control 12V Active Buzzer
The ESP32 C3 Super Mini outputs only 3.3V, which is not enough to power a 12V buzzer directly.
Control method:
- Use a relay module as a switch between ESP32 and the buzzer
- ESP32 C3 Super Mini controls the relay with a digital pin
- Relay switches the 12V power supply to the buzzer ON or OFF
- This keeps your ESP32 safe while controlling high-voltage devices
Important: If you're new to relays, check out the ESP32 C3 Super Mini - Relay tutorial to understand pinout, operation, and programming basics.
The MOSFET module is the second choice. The pins, the inside and the code of the module are explained in the ESP32 C3 Super Mini - 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 ESP32 C3 Super Mini | 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
Follow this wiring diagram to connect your ESP32 C3 Super Mini to the 12V active buzzer through a relay module.

This image is created using Fritzing. Click to enlarge image
The diagram below shows the same connections without a breadboard:

This image is created using Fritzing. Click to enlarge image
Safety notes:
- Note: Double-check 12V power supply polarity before connecting - reversed polarity can damage the buzzer
- Note: Keep 12V wiring separate from ESP32 signal wires to avoid electrical interference
| Component Pin | Connection Point |
|---|---|
| ESP32 Pin 2 | Relay Signal Pin (IN) |
| ESP32 GND | Relay GND |
| ESP32 5V | Relay VCC |
| Relay COM | 12V Power Supply (+) |
| Relay NO | Buzzer (+) Red Wire |
| Buzzer (-) Black Wire | 12V Power Supply GND (-) |
ESP32 C3 Super Mini Code
Here's the code to control your 12V active buzzer - it turns the buzzer ON for 1 second, then OFF for 2 seconds in a repeating pattern.
What this code does:
- Sets up GPIO pin 2 to control the relay
- Turns the buzzer ON for 1 second (relay activated)
- Turns the buzzer OFF for 2 seconds (relay deactivated)
- Repeats the pattern continuously for alarm-like beeping
- Uses simple digitalWrite commands for easy customization
Detailed Instructions
- New to Arduino? Start with our ESP32 C3 Super Mini Getting Started guide first.
- Setup environment: If this is your first time using ESP32 C3 Super Mini, follow the Arduino IDE setup guide
- Connect hardware: Wire the ESP32 C3 Super Mini, relay, buzzer, and 12V power supply according to the wiring diagram above
- Connect to PC: Plug your ESP32 C3 Super Mini into your computer using the USB Type-C cable
- Open Arduino IDE: Launch the Arduino IDE and select the correct board and port
- Upload code: Copy the code above, paste it into Arduino IDE, and click the Upload button
- Test buzzer: Listen for the buzzer to beep ON for 1 second, OFF for 2 seconds repeatedly
- Verify operation: The relay LED should also blink in sync with the buzzer sound
- Pro Tip: Adjust the delay() values in the code to create different beep patterns - shorter delays make rapid alarm sounds, longer delays create slow warning beeps
Code Explanation
The code comments explain each line in detail - read through them to understand how the buzzer control works!
Key functions used:
- pinMode() - Configures GPIO pin 2 as an output to control the relay
- digitalWrite(HIGH) - Activates relay, connecting 12V to buzzer (sound ON)
- digitalWrite(LOW) - Deactivates relay, disconnecting power (sound OFF)
- delay() - Pauses program execution to control timing
Applications and Project Ideas
Use your ESP32 C3 Super Mini 12V active buzzer setup in these practical projects:
- Security alarm system: Trigger loud alerts when motion sensors detect intrusion
- Timer notifications: Create kitchen timers or workout interval buzzers
- Door/window alerts: Sound alarm when doors or windows open unexpectedly
- Water leak detector: Connect with moisture sensor to alert for leaks
- Temperature warnings: Pair with temperature sensor for overheat alarms
- Reminder system: Build medication or appointment reminder device
- IoT alarm system: Combine with WiFi to create remote-controlled security alerts
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 |
|---|---|
| ESP32 C3 Super Mini GPIO4 | MOSFET module PWM |
| ESP32 C3 Super Mini 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 − |
The 3.3V signal of the ESP32 C3 Super Mini is enough, because the LED in the optocoupler needs only a small current.
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 −.
ESP32 C3 Super Mini 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 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 ESP32 C3 Super Mini.
- 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 ESP32 C3 Super Mini Piezo Buzzer tutorial. For an AC buzzer or siren, use the relay.
Video Tutorial
Watch the video below for a visual walkthrough of this project.
Challenge Yourself
Take your buzzer project to the next level with these challenges:
- Easy: Modify the code to create an SOS pattern (3 short beeps, 3 long beeps, 3 short beeps)
- Easy: Add a button to manually trigger the buzzer ON/OFF
- Medium: Create a melody by programming different beep durations and pauses
- Medium: Use a motion sensor to trigger the alarm only when movement is detected
- Advanced: Build a smartphone-controlled alarm using ESP32 WiFi and Blynk app
- Advanced: Create a multi-zone alarm system with multiple buzzers controlled independently