KY-012 Active Buzzer Module
The KY-012 is an active piezoelectric buzzer module that emits a 2.5 kHz tone when powered. It operates within a voltage range of 3.3V to 5V and is ideal for applications requiring audible alerts.

On this page
KY-012 pinout
The KY-012 is a 3-pin active piezoelectric buzzer module:
| Pin | Type | Description | Notes |
|---|---|---|---|
| Pin (-) | Power | Ground connection | |
| Pin (middle) | Control | Not connected | Leave unconnected (NC) |
| Pin (S) | Communication | Signal/power input | Apply 3.3V or 5V to activate buzzer |
Interface: Digital output (simple HIGH/LOW control)
Type: Active buzzer (built-in oscillator)
Frequency: Fixed 2.5 kHz tone
Power: 3.3V to 5V, 30mA max current
Volume: Minimum 85 dB output
Applications: Alarms, alerts, notifications, simple audio feedback
Wiring the KY-012 to ESP32
To interface the KY-012 with an ESP32 for simple buzzer alerts:
| KY-012 pin | ESP32 pin | Purpose |
|---|---|---|
| Pin (-) | GND | Ground |
| Pin (S) | GPIO15 | Digital output (any GPIO) |
| Pin (middle) | N/C | Not connected · optional |
Simple Control: Just set GPIO HIGH to activate, LOW to stop
GPIO Selection: Any digital GPIO pin works, GPIO15 is just an example
Voltage: Use 3.3V GPIO output for ESP32 (sufficient for activation)
Fixed Tone: Cannot change frequency (use KY-006 passive buzzer for variable tones)
KY-012 code examples
KY-012 Arduino example
Copyint buzzer = 13;
void setup() {
pinMode(buzzer, OUTPUT); // Initialize the buzzer pin as an output
}
void loop() {
digitalWrite(buzzer, HIGH); // Turn the buzzer on
delay(4000); // Wait for 4 seconds
digitalWrite(buzzer, LOW); // Turn the buzzer off
delay(2000); // Wait for 2 seconds
}This Arduino code alternates the KY-012 buzzer on and off. The buzzer is connected to pin 13, which is set as an output. The buzzer is turned on for 4 seconds and then off for 2 seconds in a continuous loop.
KY-012 ESP-IDF example
Copy#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#define BUZZER_PIN GPIO_NUM_15
void app_main(void) {
gpio_config_t io_conf = {
.pin_bit_mask = (1ULL << BUZZER_PIN),
.mode = GPIO_MODE_OUTPUT,
.pull_up_en = GPIO_PULLUP_DISABLE,
.pull_down_en = GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTR_DISABLE
};
gpio_config(&io_conf);
while (1) {
gpio_set_level(BUZZER_PIN, 1); // Turn the buzzer on
vTaskDelay(pdMS_TO_TICKS(4000)); // Wait for 4 seconds
gpio_set_level(BUZZER_PIN, 0); // Turn the buzzer off
vTaskDelay(pdMS_TO_TICKS(2000)); // Wait for 2 seconds
}
}This ESP-IDF code configures GPIO15 as an output to control the KY-012 active buzzer. The buzzer is turned on for 4 seconds and then off for 2 seconds in a loop.
KY-012 ESPHome example
Copyswitch:
- platform: gpio
pin: GPIO15 # KY-012 signal pin
name: "KY-012 Active Buzzer"The KY-012 is an active buzzer - it only needs power to sound - so a plain GPIO switch on GPIO15 is the whole configuration. Toggle it from Home Assistant or automations; for beep patterns, wrap it in a script with delays.
KY-012 PlatformIO example
Copy[env:esp32]
platform = espressif32
board = esp32dev
framework = arduino#include <Arduino.h>
#define BUZZER_PIN 15
void setup() {
pinMode(BUZZER_PIN, OUTPUT);
}
void loop() {
digitalWrite(BUZZER_PIN, HIGH); // Turn buzzer on
delay(4000);
digitalWrite(BUZZER_PIN, LOW); // Turn buzzer off
delay(2000);
}This PlatformIO code configures GPIO15 as an output to control the KY-012 active buzzer. The buzzer is turned on for 4 seconds and off for 2 seconds in an alternating cycle.
KY-012 MicroPython example
Copyimport machine
import time
BUZZER_PIN = machine.Pin(15, machine.Pin.OUT)
while True:
BUZZER_PIN.value(1) # Turn buzzer on
time.sleep(4) # Wait for 4 seconds
BUZZER_PIN.value(0) # Turn buzzer off
time.sleep(2) # Wait for 2 secondsThis MicroPython script configures GPIO15 as an output for the KY-012 active buzzer. It alternates the buzzer on and off in a cycle of 4 seconds on and 2 seconds off.
KY-012 specifications
About the KY-012
The KY-012 is an active buzzer: the oscillator is built into the piezo element itself, so a steady HIGH on the signal pin is enough to make it sound at its own fixed tone, around 2.5 kHz - no PWM square wave needed, unlike the passive KY-006. That simplicity is also the ceiling: there’s no way to change the pitch or play a melody, only switch the one tone on and off, so it fits alerts and notifications rather than anything musical.
It draws up to about 30 mA at 3.3-5V and puts out a minimum 85 dB, loud enough to notice from across a room, and any digital GPIO can drive it directly since it just needs a logic HIGH rather than a specific current or frequency. The middle pin on most of these boards is unconnected - only the outer ground and signal pins matter for wiring.
KY-012 troubleshooting
No Sound Emitted
›
Issue: The buzzer does not produce any sound when expected.
Solutions:
- Ensure the module is properly connected to the microcontroller, with the correct pins assigned.
- Verify that the signal pin is receiving the appropriate voltage (at least 3.3V).
- Check for any soldering issues or loose connections on the module.
Continuous Sound
›
Issue: The buzzer emits a continuous sound when it shouldn't.
Solutions:
- Ensure that the signal pin is not inadvertently set to HIGH in the code.
- Check for any short circuits or unintended connections that might cause the signal pin to remain HIGH.
Where to buy the KY-012

Resources
Similar sensors





