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

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Relay
1×12V Active Buzzer
1×12V Power Adapter
1×Optionally, DC Power Jack
1×Breadboard
1×Jumper Wires

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
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 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.

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

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.

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!