When this sensor is powered, this active buzzer generates a sound with the frequency of 2.5kHz. The active buzzer module, unlike the passive module KY-006 does not require a square wave voltage to generate a tone - if a voltage of min. 3.3V is applied to its signal pin, the required square wave voltage is generated in the buzzer independently.

Technical data

tone frequency 2,5kHz
Generates a square wave voltage independently

Generates a square wave voltage independently

Pin assignment

Code example Arduino

Pin assignment Arduino

Arduino Sensor
Pin 13 Signal
- +V
ground GND

This code example shows how the buzzer can be switched on alternately for four seconds and then switched off for two seconds using a definable output pin.

int Buzzer = 13;
 
void setup ()
{
  pinMode (Buzzer, OUTPUT); // Initialize output pin for the buzzer
}
 
void loop () //main program loop
{
  digitalWrite (Buzzer, HIGH); // Buzzer is switched on
  delay (4000); // wait mode for 4 seconds
  digitalWrite (Buzzer, LOW); // Buzzer is switched off
  delay (2000); // Wait mode for another two seconds in which the LED is then turned off
}

Example program download

KY012-Arduino-ON-OFF

Code example Raspberry Pi

Pin assignment Raspberry Pi

Raspberry Pi Sensor
GPIO 24 [Pin 18] Signal
- +V
Ground [Pin 6] GND

Programming example in Python programming language.

This code example shows how the buzzer can be switched on alternately for four seconds and then switched off for two seconds using a definable output pin.

# Required modules are imported and set up
import RPi.GPIO as GPIO
import time
  
GPIO.setmode(GPIO.BCM)
  
# Here the input pin is declared, to which the sensor is connected.
Buzzer_PIN = 24
GPIO.setup(Buzzer_PIN, GPIO.OUT, initial= GPIO.LOW)
  
print("Buzzer test [press CTRL+C to exit test]")
 
# main program loop
try:
    while True:
        print("Buzzer 4 seconds on")
        GPIO.output(Buzzer_PIN,GPIO.HIGH) #buzzer is switched on
        time.sleep(4)#wait mode for 4 seconds
        print("Buzzer 2 seconds off")
        GPIO.output(Buzzer_PIN,GPIO.LOW) #buzzer is switched off
        time.sleep(2)#wait mode for another two seconds then LED is off
  
#rearrange after the program has been terminated
except KeyboardInterrupt:
        GPIO.cleanup()

Example program download

KY012-RPi-ON-OFF

To start with the command:

sudo python3 KY012.py

Code example Micro:Bit

Pinout Micro:Bit:

Micro:Bit Sensor
Pin 1 Signal
- +V
Ground GND

This is a MakeCode example for Micro:Bit which essentially does the same as the examples of the other two variants. However, this example is closer to the Raspberry Pi example than the Arduino example.