ESP32 S3 - Buzzer

Learn how to program your ESP32 S3 to control a 12V active buzzer and generate loud, attention-grabbing sounds perfect for alarms and notifications. This beginner-friendly tutorial walks you through the wiring, code, and concepts needed to build a fully working buzzer project with the ESP32 S3.

What you'll build:

  1. A relay-controlled 12V active buzzer circuit connected to an ESP32 S3
  2. Firmware that cycles the buzzer ON for 1 second and OFF for 2 seconds in a repeating alarm pattern
  3. A safe, isolated switching design that protects your ESP32 S3 from high-voltage components
  4. A foundation you can extend into real-world security alarms, notification systems, and IoT alert devices
ESP32 S3 - Buzzer

Note: If you want to control a 5V active/passive buzzer, check out this ESP32 S3 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.

Overview of 12V Active Buzzer

The 12V Active Buzzer is an electronic component that produces a loud, high-decibel sound well suited to alarm systems and attention alerts. Unlike passive buzzers that require a PWM signal, an active buzzer contains a built-in oscillator, so it emits sound the moment power is applied — no tone generation needed in your code.

Key Specifications

The buzzer operates on a 12V DC supply and delivers significantly more volume than a standard 5V piezo buzzer, making it ideal for outdoor environments or noisy spaces. Because the ESP32 S3 outputs only 3.3V, the buzzer must be powered by an external 12V supply and switched through a relay module. This design also keeps your ESP32 S3 electrically isolated from the higher-voltage circuit, protecting the microcontroller from damage.

Pinout

The 12V Active Buzzer has just two connection points, making wiring straightforward.

ESP32 S3 12V Active Buzzer Pinout
  1. Negative (-) pin (black): Connect to GND of the 12V DC power supply
  2. Positive (+) pin (red): Connect to the 12V positive rail of the DC power supply (switched through the relay)

How to Control 12V Active Buzzer

The ESP32 S3 outputs only 3.3V logic, which is far below the 12V the buzzer requires and unsafe to connect directly. The solution is to place a relay module between the ESP32 S3 and the buzzer circuit. The ESP32 S3 drives the relay coil with a single digital GPIO pin; the relay then acts as a mechanical switch, connecting or disconnecting the 12V supply to the buzzer on demand.

Important: If you're new to relays, check out the ESP32 S3 - Relay tutorial to understand pinout, operation, and programming basics before proceeding.

The MOSFET module is the second choice. The pins, the inside and the code of the module are explained in the ESP32 S3 - 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 S3 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

Connect your ESP32 S3 to the 12V active buzzer through a relay module using the diagram and table below. Keep the 12V power wiring on one side of the breadboard and the ESP32 S3 signal wires on the other to reduce the risk of interference.

Safety Notes

Always verify the polarity of your 12V power supply before applying power — reversed polarity can permanently damage the buzzer. Route 12V wiring away from ESP32 S3 signal lines to avoid electrical noise that could cause erratic behavior.

The wiring diagram between ESP32 S3 12V Active Buzzer

This image is created using Fritzing. Click to enlarge image

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 (-)

For a project that lasts, screw terminals hold the wires better than jumper wires. In this case, use a Screw Terminal Block for ESP32 S3. The ESP32 S3 plugs into it, and each pin gets a screw terminal. Below is the wiring diagram with the screw terminal board.

The wiring diagram between ESP32 S3 12V Active Buzzer Screw Terminal

This image is created using Fritzing. Click to enlarge image

Prefer pin headers to screws? Plug the ESP32 S3 into a GPIO Breakout Board for ESP32 S3 instead:

The wiring diagram between ESP32 S3 12V Active Buzzer GPIO Breakout Board

This image is created using Fritzing. Click to enlarge image

ESP32 S3 Code

The following sketch controls the 12V active buzzer through the relay by toggling GPIO pin 2 at a fixed interval. It turns the buzzer ON for 1 second and then OFF for 2 seconds, repeating indefinitely to produce a recognizable alarm-style beep pattern. The logic is intentionally simple so you can easily modify the timing to suit your application.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-buzzer */ #define RELAY_PIN 2 // The Arduino Nano ESP32 that connects to relay to control the 12V buzzer // The setup function runs once on reset or power-up void setup() { // initialize digital pin as an output. pinMode(RELAY_PIN, OUTPUT); } void loop() { digitalWrite(RELAY_PIN, HIGH); delay(1000); digitalWrite(RELAY_PIN, LOW); delay(2000); }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Connect hardware: Wire the ESP32 S3, relay, buzzer, and 12V power supply according to the wiring diagram above.
  3. Connect to PC: Plug your ESP32 S3 into your computer using the USB Type-C cable.
  4. Open Arduino IDE: Launch the Arduino IDE and select the correct board and port for your ESP32 S3.
  5. Upload code: Copy the code above, paste it into the Arduino IDE, and click the Upload button.
  6. Test buzzer: Listen for the buzzer to beep ON for 1 second and OFF for 2 seconds repeatedly.
  7. Verify operation: The relay's onboard LED should blink in sync with the buzzer sound, confirming the relay is switching correctly.
  8. Pro Tip: Adjust the delay() values in the code to create different beep patterns — shorter delays produce rapid alarm sounds, while longer delays create slow, deliberate warning beeps.

Code Explanation

The code comments explain each line in detail. Read through them to understand exactly how the buzzer control works and where to make changes for your own projects.

The sketch uses four core Arduino functions: pinMode() configures GPIO 2 as a digital output, digitalWrite(HIGH) energizes the relay coil to connect 12V power to the buzzer, digitalWrite(LOW) releases the relay to cut power and silence the buzzer, and delay() pauses execution to control how long each state lasts.

Applications and Project Ideas

The ESP32 S3 paired with a 12V active buzzer opens the door to a wide range of practical, real-world projects that demand attention-grabbing audio alerts.

  1. Security alarm system: Trigger loud alerts when motion sensors detect intrusion.
  2. Timer notifications: Create kitchen timers or workout interval buzzers that are impossible to ignore.
  3. Door/window alerts: Sound an alarm when doors or windows open unexpectedly.
  4. Water leak detector: Combine with a moisture sensor to provide immediate leak warnings.
  5. Temperature warnings: Pair with a temperature sensor to raise an overheat alarm.
  6. Reminder system: Build a medication or appointment reminder device with a loud, unmissable alert.
  7. IoT alarm system: Use the ESP32 S3's built-in WiFi to create a remotely controlled or monitored security alert.

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

The wiring diagram between ESP32 S3 12V active buzzer MOSFET module

This image is created using Fritzing. Click to enlarge image

From To
ESP32 S3 GPIO47 MOSFET module PWM
ESP32 S3 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? You can plug the ESP32 S3 into a Screw Terminal Block for ESP32 S3 and connect the wires to its screw terminals. See the diagram below for the screw terminal version.

The wiring diagram between ESP32 S3 12V active buzzer MOSFET module Screw Terminal

This image is created using Fritzing. Click to enlarge image

A GPIO Breakout Board for ESP32 S3 works too. Besides one S, 3.3V and GND pin for each GPIO, it has extra 3.3V and 5V pins:

The wiring diagram between ESP32 S3 12V active buzzer MOSFET module GPIO Breakout Board

This image is created using Fritzing. Click to enlarge image

The 3.3V level of the ESP32 S3 is plenty, because the LED in the PC817 optocoupler needs only a few milliamps. On modules with a "V" in the name (such as R8V or R16V), GPIO47 runs at 1.8V, which may be too weak to light the optocoupler. On those boards, pick another free GPIO such as GPIO1, and change the pin number in the code.

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 S3 Code

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-buzzer */ const int MOSFET_PIN = 47; // ESP32 S3 GPIO47 connected to the PWM pin of the MOSFET module void setup() { Serial.begin(9600); pinMode(MOSFET_PIN, OUTPUT); digitalWrite(MOSFET_PIN, LOW); // start with the buzzer OFF } void loop() { // fast alarm beeps: 10 short beeps Serial.println("Alarm: fast beeps"); for (int i = 0; i < 10; i++) { digitalWrite(MOSFET_PIN, HIGH); // turn on buzzer delay(100); digitalWrite(MOSFET_PIN, LOW); // turn off buzzer delay(100); } // one long beep Serial.println("Alarm: long beep"); digitalWrite(MOSFET_PIN, HIGH); delay(1000); digitalWrite(MOSFET_PIN, LOW); // quiet time Serial.println("Quiet"); delay(3000); }

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 S3.
  • 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.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
Alarm: fast beeps Alarm: long beep Quiet Alarm: fast beeps Alarm: long beep Quiet
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

※ 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 S3 Piezo Buzzer tutorial. For an AC buzzer or siren, use the relay.

Video Tutorial

Watch the step-by-step video walkthrough for this ESP32 S3 project below.

Challenge Yourself

Once your basic ESP32 S3 buzzer project is working, push your skills further with these progressively harder challenges.

  1. Beginner: Modify the code to produce an SOS pattern (3 short beeps, 3 long beeps, 3 short beeps).
  2. Beginner: Add a push button so the buzzer only sounds while the button is held down.
  3. Intermediate: Program multiple different beep durations and pauses to create a recognizable melody.
  4. Intermediate: Integrate a PIR motion sensor so the alarm triggers automatically on movement detection.
  5. Advanced: Build a smartphone-controlled alarm using the ESP32 S3's WiFi and the Blynk IoT platform.
  6. Advanced: Design a multi-zone alarm system where each zone has its own buzzer controlled independently by the ESP32 S3.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!