KY-012 Active Piezo-Buzzer module

From SensorKit X40 Wiki

Jump to: navigation, search

Pictures

ky-012.jpg

Technical data / Short description

This Buzzer creates a sound with a frequency of 2,5kHz.

The active Buzzer-module doesn't need a square wave, unlike the passiv module (KY-006), to create a sound. If it gets a minimum Voltage of 3.3V at its signal pin, the buzzer will create the square wave by itself.

Pinout

3 G V S.png

Code example Arduino

In this example, you will see how the buzzer will be ON for 4 seconds and then will be OFF for 2 seconds.

int Buzzer = 13;

void setup ()
{
  pinMode (Buzzer, OUTPUT); // Output pin initialization for the buzzer
}

void loop () //Main program loop
{
  digitalWrite (Buzzer, HIGH); // Buzzer will be on
  delay (4000); // Waitmode for 4 seconds
  digitalWrite (Buzzer, LOW); // Buzzer will be off
  delay (2000); // Waitmode for another 2 seconds in which the buzzer will be off
}

Connections Arduino:

Sensor Signal = [Pin 13]
Sensor [N.C] =
Sensor GND = [Pin GND]

Example program download:

KY-006-RPI_PWM

Code example Raspberry Pi

In this example, you will see how, with a defined output pin, the buzzer will be ON for 4 seconds and then will be OFF for 2 seconds.

import RPi.GPIO as GPIO
import time
   
GPIO.setmode(GPIO.BCM)
   
# Output pin declaration for the Buzzer.
Buzzer_PIN = 24
GPIO.setup(Buzzer_PIN, GPIO.OUT, initial= GPIO.LOW)
   
print ("Buzzer-test [press ctrl+c to end the test]")
  
# Main program loop
try:
        while True:
            print("Buzzer will be on for 4 seconds")
            GPIO.output(Buzzer_PIN,GPIO.HIGH) #Buzzer will be switched on
            time.sleep(4) #Waitmode for 4 seconds
            print("Buzzer wil be off for 4 seconds") 
            GPIO.output(Buzzer_PIN,GPIO.LOW) #Buzzer will be switched off 
            time.sleep(2) #Waitmode for another 2 seconds in which the buzzer will be off
   
# Scavenging work after the end of the program
except KeyboardInterrupt:
        GPIO.cleanup()

Connections Raspberry Pi:

Sensor Signal = GPIO24 [Pin 18]
Sensor [+V] = 3.3V [Pin 1]
Sensor GND = GND [Pin 6]

Example program download

KY-012_Buzzer_RPi

To start, enter the command:

sudo python KY-012_Buzzer_RPi.py