ESP32 - Buzzer
In this tutorial, we are going to learn how to program ESP32 to control a 12V active buzzer to produce a loud sound. If you want to control 5V active/passive buzzer, please check out this ESP32 Piezo Buzzer tutorial
Hardware Used In This Tutorial
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Introduction to 12V Active Buzzer
The 12V Active Buzzer can produce a loud sound, which is suitable for the alarming system.
Pinout
12V Active Buzzer usually has two pins:
- Negative (-) pin (black): needs to be connected to GND of DC power supply
- Positive (+) pin (red): needs to be connected to 12V of DC power supply
How to Control 12V Active Buzzer
If 12V active buzzer is powered by 12V power supply, it make sound. To control a 12V active buzzer, we need to use a relay in between ESP32 and 12V active buzzer. ESP32 can control the 12V active buzzer via the relay. If you do not know about relay (pinout, how it works, how to program ...), learn about relay in the ESP32 - Relay tutorial
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
If you're unfamiliar with how to supply power to the ESP32 and other components, you can find guidance in the following tutorial: How to Power ESP32.
ESP32 Code
The below code repeatedly turns the 12V active buzzer ON in one seconds and OFF in two seconds,
Quick Instructions
- If this is the first time you use ESP32, see how to setup environment for ESP32 on Arduino IDE
- Connect ESP32 to PC via USB cable
- Open Arduino IDE, select the right board and port
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to ESP32
- See the 12V active buzzer's state
Code Explanation
Read the line-by-line explanation in comment lines of code!
Video Tutorial
Making video is a time-consuming work. If the video tutorial is necessary for your learning, please let us know by subscribing to our YouTube channel , If the demand for video is high, we will make the video tutorial.