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.

KY-006 Passive Buzzer Module image
KY-006 · PWM
PWM
Interface
3pins
Connections
3.3-5V
Supply
1.5-2.5kHz
Frequency
$1
Typical price
On this page

KY-006 pinout

3 pins · PWM

The KY-006 is a 3-pin passive piezoelectric buzzer module:

View:
KY-006 Passive Buzzer Module pinout
PinTypeDescriptionNotes
Pin (S)CommunicationPWM signal inputRequires PWM for tone generation
Pin (+)PowerPower supply3.3V or 5V
Pin (-)PowerGround connection
  • Interface: PWM (Pulse Width Modulation) input

  • Type: Passive piezoelectric buzzer (requires external signal)

  • Frequency: 1.5 kHz to 2.5 kHz range

  • Power: 3.3V or 5V operation

  • Size: 18.5mm × 15mm compact design

  • Applications: Custom tones, melodies, alarms, audio notifications

Wiring the KY-006 to ESP32

3 connections · all required

To interface the KY-006 with an ESP32 for PWM-driven tones:

KY-006 Passive Buzzer Module wiring with ESP32
KY-006 pinESP32 pinPurpose
Pin (S)GPIO18PWM signal (any PWM-capable GPIO)
Pin (+)3.3V or 5VPower supply
Pin (-)GNDGround
  • PWM Pins: Use any PWM-capable GPIO, GPIO18 is just an example

  • Voltage: Use 3.3V or 5V depending on desired volume

  • Frequency Control: Adjust PWM frequency to create different tones

  • Melodies: Can play custom melodies by changing frequencies

KY-006 code examples

5 platforms
Platform:

KY-006 Arduino example

Copy
#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.

KY-006 ESP-IDF example

Copy
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/ledc.h"

#define BUZZER_GPIO 18 // KY-006 signal pin, matches the wiring above

void app_main(void)
{
    // A passive buzzer needs a PWM tone - the LEDC peripheral provides it
    ledc_timer_config_t timer = {
        .speed_mode = LEDC_LOW_SPEED_MODE,
        .timer_num = LEDC_TIMER_0,
        .duty_resolution = LEDC_TIMER_10_BIT,
        .freq_hz = 2000, // 2 kHz tone
        .clk_cfg = LEDC_AUTO_CLK,
    };
    ledc_timer_config(&timer);

    ledc_channel_config_t channel = {
        .speed_mode = LEDC_LOW_SPEED_MODE,
        .channel = LEDC_CHANNEL_0,
        .timer_sel = LEDC_TIMER_0,
        .gpio_num = BUZZER_GPIO,
        .duty = 0,
        .hpoint = 0,
    };
    ledc_channel_config(&channel);

    while (1) {
        // Tone on: 50% duty at the timer frequency
        ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 512);
        ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0);
        vTaskDelay(pdMS_TO_TICKS(500));

        // Tone off
        ledc_set_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0, 0);
        ledc_update_duty(LEDC_LOW_SPEED_MODE, LEDC_CHANNEL_0);
        vTaskDelay(pdMS_TO_TICKS(500));

        // Change the pitch with ledc_set_freq()
        // ledc_set_freq(LEDC_LOW_SPEED_MODE, LEDC_TIMER_0, 1000);
    }
}

A passive buzzer needs an audio-frequency PWM signal, which the ESP32's LEDC peripheral generates in hardware: the timer sets the tone frequency (2 kHz here) and the loop toggles between 50% duty (tone on) and 0% (silence) every half second. Change the pitch at runtime with ledc_set_freq() - each frequency is one musical note.

KY-006 ESPHome example

Copy
output:
  - platform: ledc
    pin: GPIO18
    id: buzzer_pwm

switch:
  - platform: template
    name: "KY-006 Buzzer"
    optimistic: true
    turn_on_action:
      - output.ledc.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%

A passive buzzer needs a PWM signal, so the KY-006 sits on a ledc output. The template switch starts a 2 kHz tone with output.ledc.set_frequency plus a 50% duty level, and stops it by setting the level to zero. Change the frequency action to play different notes; the rtttl component can even play ringtones through the same output.

KY-006 PlatformIO example

Copy
[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino
src/main.cppCopy
#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.

KY-006 MicroPython example

Copy
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.

KY-006 specifications

From the datasheet
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

About the KY-006

The KY-006 is a passive piezo disc, not a self-contained beeper: there’s no oscillator onboard, so a steady HIGH signal on the module produces silence, not a tone. It needs a PWM square wave on the signal pin to make any sound at all, with a usable range loosely centered around 1.5-2.5 kHz where the disc actually resonates - tone() on Arduino or ledc PWM on ESP-IDF/Arduino-ESP32 both work, and the pitch tracks whatever frequency it’s driven at rather than just getting louder or quieter.

That extra bit of code is also the whole difference from an active buzzer: the KY-012 needs only a HIGH/LOW to buzz at its own fixed tone around 2.5 kHz, while the KY-006 can play actual melodies and varying pitches at the cost of a slightly more involved sketch - useful for anything beyond a single alert beep.

KY-006 troubleshooting

2 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.

Where to buy the KY-006

KY-006 Passive Buzzer Module
KY-006 Passive Buzzer Module
$1per unit, typical
Amazon and AliExpress links are affiliate links - buying through them supports the site at no extra cost to you.

Resources