ESP32 S3 UNO - Buzzer

This ESP32 S3 Uno buzzer tutorial shows you how to make a loud 12V active buzzer beep with the ESP32 S3 Uno form board and a relay. The board cannot power a 12V buzzer by itself, so a relay does the switching while your code decides when the alarm sounds. If you want to use a small 5V active or passive buzzer instead, see the ESP32 S3 Uno 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.

In this tutorial, you will:

  1. Learn how a 12V active buzzer works and why it needs a relay
  2. Wire the relay, the 12V power adapter and the buzzer to the ESP32 S3 Uno
  3. Write Arduino code that turns the loud buzzer on and off
  4. Upload the code with the Arduino IDE and test your alarm
ESP32 S3 Uno buzzer

Overview of 12V Active Buzzer

A 12V active buzzer is much louder than the tiny buzzers you often find in starter kits. That makes it a good choice for alarms, warning signals and doorbells that people must hear from another room.

"Active" means the buzzer has its own oscillator inside. You do not need to send a tone or a PWM signal. Give it 12V and it beeps; take the 12V away and it stops.

Pinout

ESP32 S3 Uno 12V Active Buzzer Pinout

Most 12V active buzzers have just two wires, so the wiring is easy.

Negative (-) pin

This is usually the black wire. Connect it to the GND (minus) of the 12V DC power supply.

Positive (+) pin

This is usually the red wire. Connect it to the 12V (plus) of the DC power supply, through the relay in this project.

How to Control 12V Active Buzzer

The ESP32 S3 Uno works with 3.3V logic, and its pins give only a small current. A 12V buzzer needs a higher voltage and more current, so you can never connect it straight to a GPIO pin.

A relay solves this problem. The ESP32 S3 Uno drives the relay's input pin, and the relay's contacts open or close the 12V circuit of the buzzer. When the relay closes, the buzzer gets 12V and sounds. When it opens, the buzzer goes quiet.

If you have not used a relay before, read the ESP32 S3 Uno relay tutorial to learn about its pinout and how to program it.

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

ESP32 S3 Uno Pinout

The image below shows the pinout of the ESP32 S3 Uno form board. Use it to find the Uno header pin D3 and its GPIO number when you wire the relay.

ESP32 S3 Uno pinout diagram

Wiring Diagram

The ESP32 S3 Uno controls the relay, and the relay switches the 12V power to the buzzer. Keep the 12V circuit fully separate from the board's pins.

The wiring diagram between ESP32 S3 Uno 12V Active Buzzer

This image is created using Fritzing. Click to enlarge image

A screw terminal keeps each wire tight, even when the board shakes. Put a Screw Shield V2 or a Proto Screw Terminal Block Shield on top of the ESP32 S3 Uno, then tighten each wire under a screw. See the diagram below for the screw shield version.

The wiring diagram between ESP32 S3 Uno 12V Active Buzzer Screw Shield

This image is created using Fritzing. Click to enlarge image

Relay to ESP32 S3 Uno

Relay Pin ESP32 S3 Uno Pin
VCC 5V
GND GND
IN D3 (GPIO17)

12V circuit

From To
12V power adapter (+) Relay COM
Relay NO Buzzer positive (+) red wire
Buzzer negative (-) black wire 12V power adapter (-)

WARNING

Never connect the 12V supply to any ESP32 S3 Uno pin. The ESP32 S3 Uno pins work at 3.3V and are NOT 5V tolerant, so 12V will destroy the board at once. Only the relay contacts (COM and NO) should touch the 12V circuit.

※ NOTE THAT:

Most 5V relay modules switch fine with the 3.3V signal from the ESP32 S3 Uno. If your relay clicks weakly or does not switch at all, use a relay module that accepts a 3.3V input signal.

ESP32 S3 Uno Code

The sketch below turns the 12V buzzer on for two seconds, then off for five seconds, and repeats this forever. It only sets the relay pin HIGH or LOW, because the active buzzer makes its own sound.

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-buzzer */ #define RELAY_PIN 17 // The ESP32 S3 Uno pin (D3 = GPIO17) that controls the buzzer via relay // the setup function runs once when you press reset or power the board void setup() { // initialize GPIO17 (D3) as an output. pinMode(RELAY_PIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(RELAY_PIN, HIGH); // turn on buzzer 2 seconds delay(2000); digitalWrite(RELAY_PIN, LOW); // turn off buzzer 5 seconds delay(5000); }

Detailed Instructions

Follow these steps one by one:

  1. New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
  2. Wire it up as shown in the diagram.
  3. Connect the board to your computer with a USB Type-C cable.
  4. Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
  5. Copy the code above and paste it into the Arduino IDE.
  6. Upload the code by clicking the Upload button.
  7. Plug in the 12V adapter and listen: the buzzer beeps for 2 seconds, then stays quiet for 5 seconds.
  8. Tip: The relay clicks each time it switches. If you hear the click but no beep, check the 12V side of the wiring.

Code Explanation

The code is short, and the comments inside it explain each line. In setup(), GPIO17 (D3) becomes an output. In loop(), digitalWrite() sets the pin HIGH to close the relay and start the buzzer, and LOW to open the relay and stop it. The two delay() calls set how long the sound is on and off.

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 Uno 12V active buzzer MOSFET module

This image is created using Fritzing. Click to enlarge image

From To
ESP32 S3 Uno D9 (GPIO46) MOSFET module PWM
ESP32 S3 Uno 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 −

A screw terminal keeps each wire tight, even when the board shakes. A Screw Shield V2 or a Proto Screw Terminal Block Shield solves this. Plug it into the ESP32 S3 Uno and screw the wires in. See the diagram below for the screw shield version.

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

This image is created using Fritzing. Click to enlarge image

The 3.3V output of the ESP32 S3 Uno is enough, because the optocoupler LED needs only a small current. D9 (GPIO46) is a boot strapping pin. The MOSFET module input pulls it gently to LOW, which is safe. If you have trouble uploading, unplug the PWM wire, upload, then plug it back in.

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

/* * This ESP32 S3 Uno code was developed by newbiely.com * * This ESP32 S3 Uno code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3-uno/esp32-s3-uno-buzzer */ const int MOSFET_PIN = 46; // ESP32 S3 Uno pin D9 (GPIO46) 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 Uno.
  • 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 Uno Piezo Buzzer tutorial. For an AC buzzer or siren, use the relay.

Video Tutorial

Watch the video below to see this ESP32 S3 Uno project step by step.

FAQ

Can I connect a 12V buzzer directly to the ESP32 S3 Uno?

No. The ESP32 S3 Uno pins give only 3.3V and a small current, and they are not 5V tolerant. A 12V buzzer needs its own power supply, so you must switch it with a relay or a transistor (MOSFET) circuit.

Which ESP32 S3 Uno pin should I use for the relay?

This tutorial uses D3, which is GPIO17 on the ESP32 S3 Uno. In code you write the GPIO number, so the line is #define RELAY_PIN 17. You can use another free digital pin, but avoid D0 and D1 (USB serial) and the boot strapping pins D6 (GPIO3) and D9 (GPIO46).

Will a 5V relay module work with the 3.3V ESP32 S3 Uno?

Most 5V relay modules work, because their input board accepts 3.3V as HIGH. Power the module from the 5V pin and drive IN from the GPIO. If the relay does not switch reliably, choose a module rated for a 3.3V trigger.

Can I play different tones with a 12V active buzzer?

No. An active buzzer has a fixed tone made by its built-in oscillator, and the relay can only turn it on or off. For melodies, use a passive piezo buzzer with the tone() function, as shown in the ESP32 S3 Uno Piezo Buzzer tutorial.

Is the code different from the UNO R4 version?

The logic is the same. Only the pin number changes: D3 on the ESP32 S3 Uno is GPIO17, so the code uses 17 instead of 3. In the Arduino IDE you also select the ESP32S3 Dev Module board instead of an UNO R4 board.

What if my project needs more pins than the Uno headers give?

The ESP32 S3 Uno has two extra rows of holes with more GPIOs: GPIO15 and GPIO16 (I/O, PWM, analog), GPIO45 and GPIO35 to GPIO42 (I/O, PWM), and GPIO47/GPIO48 (output only, PWM). Solder pin headers to them and write the GPIO number in code. For extra relays or buzzers, GPIO35 to GPIO42 are a good first choice. Be careful with two groups: GPIO47 and GPIO48 may run at 1.8V instead of 3.3V on some modules (especially ones with "V" in the name, like R8V or R16V), so 3.3V devices can be damaged or act strangely. GPIO0, GPIO3 (D6), GPIO45 and GPIO46 (D9) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code. Use the other extra pins first.

Troubleshooting

Problem Possible Cause Solution
No COM port appears in the Arduino IDE Missing USB driver or a charge-only cable Install the CP210x or CH340 driver, use a data USB cable, or hold BOOT while you press RESET
Upload fails or the board does not start Board in the wrong mode or wrong board selected Select ESP32S3 Dev Module, hold BOOT while you press RESET, then upload again
Relay clicks but the buzzer is silent 12V circuit wired wrong or adapter not plugged in Check that 12V (+) goes to COM, NO goes to the buzzer (+), and the buzzer (-) goes to the adapter (-)
Relay does not click at all Relay not powered or IN on the wrong pin Power the relay from 5V and GND, and connect IN to D3 (GPIO17)
Buzzer sounds all the time Buzzer wired to NC instead of NO, or relay is active-low Move the wire from NC to NO, or swap HIGH and LOW in the code
Buzzer is very quiet Supply voltage too low Use a real 12V adapter that can give enough current
Board resets when the relay switches Power dip from the relay coil Power the board from a stable USB port and keep the 12V wires away from the board

※ 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!