ESP32 KY-006 Passive Buzzer Module
Overview
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.
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. 🚀
Where to Buy
Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
Technical Specifications
Pinout Configuration
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.
Troubleshooting Guide
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.
Debugging Tips
🔍 Serial Monitor
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
⚡ Voltage Checks
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
Code Examples
Arduino Example
#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.
ESP-IDF Example
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.
ESPHome Example
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.
PlatformIO Example
platformio.ini
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
PlatformIO Example Code
#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.
MicroPython Example
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.
Conclusion
The ESP32 KY-006 Passive Buzzer Module is a powerful KY-0xx module sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.