ESP32 KY-006 Passive Buzzer Module
The KY-006 is a passive piezoelectric buzzer module that produces sound when driven by a PWM signal. It is ideal for generating various tones and melodies in electronic projects.
π Quick Links
π KY-006 Price
βΉοΈ About KY-006 Passive Buzzer Module
The KY-006 is a piezoelectric passive buzzer module capable of generating tones between 1.5 kHz and 2.5 kHz when driven by a PWM signal. Unlike active buzzers, it requires an external signal, allowing for custom tones and melodies.
β‘ Key Features #
- Customizable Sound Output β Produces tones and melodies via PWM control.
- Frequency Range β Operates between 1.5 kHz and 2.5 kHz.
- Operating Voltage β Compatible with 3.3V to 5V, making it ideal for ESP32, Arduino, and other microcontrollers.
- Compact Design β Measures 18.5mm Γ 15mm, perfect for audio alerts in embedded projects.
With its flexibility and easy integration, the KY-006 is an excellent choice for sound-based notifications, alarms, and interactive projects. π
βοΈ KY-006 Sensor Technical Specifications
Below you can see the KY-006 Passive Buzzer Module Technical Specifications. The sensor is compatible with the ESP32, operating within a voltage range suitable for microcontrollers. For precise details about its features, specifications, and usage, refer to the sensorβs datasheet.
- Type: module
- Protocol: PWM
- Operating Voltage: 3.3V to 5V
- Sound Frequency Range: 1.5 kHz to 2.5 kHz
- Dimensions: 18.5 mm x 15 mm
- Type: Passive Piezoelectric Buzzer
- Control Method: PWM Signal
- Weight: 2g
π KY-006 Sensor Pinout
Below you can see the pinout for the KY-006 Passive Buzzer Module. The VCC
pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND
pin is the ground connection and must be connected to the ground of your ESP32!
Pin (S):
Signal pin, connects to the microcontroller's PWM-capable GPIO pin.Pin (+):
Connects to VCC (3.3V or 5V).Pin (-):
Ground pin, connects to the ground of the circuit.
𧡠KY-006 Wiring with ESP32
Below you can see the wiring for the KY-006 Passive Buzzer Module with the ESP32. Connect the VCC pin of the sensor to the 3.3V pin on the ESP32 or external power supply for power and the GND pin of the sensor to the GND pin of the ESP32. Depending on the communication protocol of the sensor (e.g., I2C, SPI, UART, or analog), connect the appropriate data and clock or signal pins to compatible GPIO pins on the ESP32, as shown below in the wiring diagram.
KY-006 Pin (S):
Connect to an ESP32 PWM-capable GPIO pin (e.g.,GPIO18
).KY-006 Pin (+):
Connect to ESP323.3V
or5V
.KY-006 Pin (-):
Connect to ESP32GND
.
π οΈ KY-006 Passive Buzzer Module Troubleshooting
This guide outlines a systematic approach to troubleshoot and resolve common problems with the . Start by confirming that the hardware connections are correct, as wiring mistakes are the most frequent cause of issues. If you are sure the connections are correct, follow the below steps to debug common issues.
π No Sound from Buzzer
Issue: The buzzer does not produce any sound when expected.
Solutions:
- Ensure that the signal pin is connected to a PWM-capable GPIO pin on the microcontroller.
- Verify that the PWM signal is being generated correctly in the code.
- Check all wiring connections for continuity and correctness.
- Confirm that the supply voltage is within the specified range (3.3V to 5V).
β οΈ Distorted or Unintended Sounds
Issue: The buzzer produces distorted sounds or tones that are not as intended.
Solutions:
- Ensure that the PWM frequency is set within the buzzer's optimal range (1.5 kHz to 2.5 kHz).
- Check for any software conflicts that might affect PWM signal generation.
- Verify that there are no loose connections or interference affecting the signal integrity.
π» Code Examples
Below you can find code examples of KY-006 Passive Buzzer Module with ESP32 in several frameworks:
If you encounter issues while using the KY-006 Passive Buzzer Module, check the Common Issues Troubleshooting Guide.

ESP32 KY-006 Arduino IDE Code Example
Fill in your main
Arduino IDE sketch file with the following code to use the KY-006 Passive Buzzer Module:
#define BUZZER_PIN 8
void setup() {
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
tone(BUZZER_PIN, 1000); // Play tone at 1000 Hz
delay(500);
noTone(BUZZER_PIN); // Stop tone
delay(500);
}
This Arduino code uses the tone()
function to generate a 1000 Hz sound from the KY-006 passive buzzer connected to pin 8. The buzzer plays the tone for 500 milliseconds, then stops for 500 milliseconds, creating a beeping effect.
Connect your ESP32 to your computer via a USB cable, Ensure the correct Board and Port are selected under Tools, Click the "Upload" button in the Arduino IDE to compile and upload the code to your ESP32.

ESP32 KY-006 ESP-IDF Code ExampleExample in Espressif IoT Framework (ESP-IDF)
This ESP-IDF code sets up the KY-006 passive buzzer on GPIO18 using the LEDC PWM module. It generates a 2 kHz tone by setting the duty cycle to 50% (512 out of 1024) and uses a hardware timer to control the frequency. The buzzer will continue to emit the tone until the duty cycle is set to 0 or the program stops.

ESP32 KY-006 ESPHome Code Example
Fill in this configuration in your ESPHome YAML configuration file (example.yml
) to integrate the KY-006 Passive Buzzer Module
output:
- platform: ledc
pin: GPIO18
id: buzzer_pwm
switch:
- platform: template
name: "KY-006 Buzzer"
turn_on_action:
- output.set_frequency:
id: buzzer_pwm
frequency: 2000Hz
- output.set_level:
id: buzzer_pwm
level: 50%
turn_off_action:
- output.set_level:
id: buzzer_pwm
level: 0%
This ESPHome configuration sets up the KY-006 passive buzzer on GPIO18 using the LEDC module for PWM control. The buzzer emits a 2 kHz tone when turned on and stops when turned off.
Upload this code to your ESP32 using the ESPHome dashboard or the esphome run
command.

ESP32 KY-006 PlatformIO Code Example
For PlatformIO, make sure to configure the platformio.ini
file with the appropriate environment and libraries, and then proceed with the code.
Configure platformio.ini
First, your platformio.ini
should look like below. You might need to include some libraries as shown. Make sure to change the board to your ESP32:
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
ESP32 KY-006 PlatformIO Example Code
Write this code in your PlatformIO project under the src/main.cpp
file to use the KY-006 Passive Buzzer Module:
#include <Arduino.h>
#define BUZZER_PIN 18
void setup() {
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
tone(BUZZER_PIN, 2000); // Generate 2 kHz tone
delay(500);
noTone(BUZZER_PIN);
delay(500);
}
This PlatformIO code initializes the KY-006 passive buzzer on GPIO18. It generates a 2 kHz tone for 500ms, then stops for 500ms, creating a beeping effect.
Upload the code to your ESP32 using the PlatformIO "Upload" button in your IDE or the pio run --target upload
command.

ESP32 KY-006 MicroPython Code Example
Fill in this script in your MicroPython main.py file (main.py
) to integrate the KY-006 Passive Buzzer Module with your ESP32.
import machine
import time
BUZZER_PIN = machine.Pin(18, machine.Pin.OUT)
PWM = machine.PWM(BUZZER_PIN)
PWM.freq(2000)
while True:
PWM.duty(512) # 50% duty cycle
time.sleep(0.5)
PWM.duty(0)
time.sleep(0.5)
This MicroPython script configures the KY-006 passive buzzer on GPIO18 using PWM. It sets the frequency to 2 kHz and alternates between 50% duty cycle (sound on) and 0% duty cycle (sound off) every 500ms.
Upload this code to your ESP32 using a MicroPython-compatible IDE, such as Thonny, uPyCraft, or tools like ampy
.
Conclusion
We went through technical specifications of KY-006 Passive Buzzer Module, its pinout, connection with ESP32 and KY-006 Passive Buzzer Module code examples with Arduino IDE, ESP-IDF, ESPHome and PlatformIO.