0% found this document useful (0 votes)
230 views15 pages

KY-012 Active Buzzer Module ENG

This document provides instructions for setting up and using an AZ-Delivery KY-012 Active Buzzer Module with an Arduino or Raspberry Pi. It includes specifications for the buzzer, pinout diagrams for connecting it, examples of Arduino and Python code to control the buzzer, and information on where to find other examples and support materials. The goal is to introduce the user to using this buzzer module and encourage them to create their own projects.

Uploaded by

eduardlopez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
230 views15 pages

KY-012 Active Buzzer Module ENG

This document provides instructions for setting up and using an AZ-Delivery KY-012 Active Buzzer Module with an Arduino or Raspberry Pi. It includes specifications for the buzzer, pinout diagrams for connecting it, examples of Arduino and Python code to control the buzzer, and information on where to find other examples and support materials. The goal is to introduce the user to using this buzzer module and encourage them to create their own projects.

Uploaded by

eduardlopez
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Welcome!

Thank you for purchasing our AZ-Delivery KY-012 Active Buzzer Module. On
the following pages, you will be introduced to how to use and set up this
handy device.

Have fun!
Table of Contents

Introduction......................................................................................................3
Specifications...................................................................................................4
The pinout........................................................................................................4
How to set-up Arduino IDE...............................................................................5
How to set-up the Raspberry Pi and Python....................................................9
Connecting the module with Atmega328p.....................................................10
Sketch example..........................................................................................11
Connecting the module with Raspberry Pi.....................................................12
Python script...............................................................................................13

-2-
Introduction

Buzzers come in two varieties, active and passive. The buzzer on-board the
KY-012 module is an active buzzer, and it just outputs a single tone when it is
connected to the power supply.

A passive buzzer is similar to a loudspeaker and needs an analog signal to


make it work.

The active buzzer module has three pins. It creates an audible sound at
2.5kHz without the need for PWM (Pulse Width Modulation) or any additional
complex code. The only requirement to generate sound is to set the signal pin
in the HIGH state.  

-3-
Specifications

» Operating voltage range: from 3.3V to 5V DC


» Operating current: 30mA
» Resonance frequency: 2.5kHz ± 300Hz continuous
» Sound output: 85dB at 100mm
» Storage temperature: from -30°C to 105°C
» Operating temperature: from -20°C to 70°C
» Dimensions: 18 x 15mm [0.71 x 0.6in]

The pinout

The KY-012 active buzzer module has three pins. The pinout diagram is
shown on the following image:

-4-
How to set-up Arduino IDE

If the Arduino IDE is not installed, follow the link and download the installation
file for the operating system of choice.

For Windows users, double click on the downloaded .exe file and follow the
instructions in the installation window.

-5-
For Linux users, download a file with the extension .tar.xz, which has to
be extracted. When it is extracted, go to the extracted directory and open the
terminal in that directory. Two .sh scripts have to be executed, the first called
arduino-linux-setup.sh and the second called install.sh.

To run the first script in the terminal, open the terminal in the extracted
directory and run the following command:
sh arduino-linux-setup.sh user_name
user_name - is the name of a superuser in the Linux operating system. A
password for the superuser has to be entered when the command is started.
Wait for a few minutes for the script to complete everything.

The second script called install.sh script has to be used after installation
of the first script. Run the following command in the terminal (extracted
directory): sh install.sh

After the installation of these scripts, go to the All Apps, where the
Arduino IDE is installed.

-6-
Almost all operating systems come with a text editor preinstalled (for
example, Windows comes with Notepad, Linux Ubuntu comes with
Gedit, Linux Raspbian comes with Leafpad, etc.). All of these text
editors are perfectly fine for the purpose of the eBook.

Next thing is to check if your PC can detect an Atmega328p board. Open


freshly installed Arduino IDE, and go to:
Tools > Board > {your board name here}
{your board name here} should be the Arduino/Genuino Uno, as it
can be seen on the following image:

The port to which the Atmega328p board is connected has to be selected. Go


to: Tools > Port > {port name goes here}
and when the Atmega328p board is connected to the USB port, the port
name can be seen in the drop-down menu on the previous image.

-7-
If the Arduino IDE is used on Windows, port names are as follows:

For Linux users, for example port name is /dev/ttyUSBx, where x


represents integer number between 0 and 9.

-8-
How to set-up the Raspberry Pi and Python

For the Raspberry Pi, first the operating system has to be installed, then
everything has to be set-up so that it can be used in the Headless mode.
The Headless mode enables remote connection to the Raspberry Pi, without
the need for a PC screen Monitor, mouse or keyboard. The only things that
are used in this mode are the Raspberry Pi itself, power supply and internet
connection. All of this is explained minutely in the free eBook:
Raspberry Pi Quick Startup Guide

The Raspbian operating system comes with Python preinstalled.

-9-
Connecting the module with Atmega328p

Connect the KY-012 module with the Atmega328p as shown on the following
connection diagram:

KY-012 pin > Mc Pin


S > D2 Blue wire
- (GND) > GND Black wire
Middle pin (VCC) > 5V Red wire

- 10 -
Sketch example

#define BIZZER_PIN 2

void setup() {
pinMode(BIZZER_PIN, OUTPUT);
}

void loop() {
digitalWrite(BIZZER_PIN, HIGH);
delay(1000);
digitalWrite(BIZZER_PIN, LOW);
delay(1000);
}

- 11 -
Connecting the module with Raspberry Pi

Connect the KY-012 module with the Raspberry Pi as shown on the following
connection diagram:

KY-012 pin > Raspberry Pi pin


S > GPIO2 [pin 15] Blue wire
Middle pin (VCC) > 3V3 [pin 17] Red wire
- (GND) > GND [pin 20] Black wire

- 12 -
Python script

import RPi.GPIO as GPIO


from time import sleep

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

# Pin setup for the module


Buzzer_PIN = 22
GPIO.setup(Buzzer_PIN, GPIO.OUT, initial=GPIO.LOW)

print('[Press CTRL + C to end the script!]')


try: # Main program loop
while True:
print('Buzzer will be on for 3 seconds')
GPIO.output(Buzzer_PIN, GPIO.HIGH) # Buzzer ON
sleep(3) # Wait for 3 seconds
print('Buzzer wil be off for 1 second')
GPIO.output(Buzzer_PIN, GPIO.LOW) # Buzzer OFF
sleep(1) # Wait for a second

# Scavenging work after the end of the program


except KeyboardInterrupt:
print('\nScript end!')

finally:
GPIO.cleanup()

- 13 -
Save the script by the name ActiveBuzzer.py. To run the script open
terminal in the directory where the script is saved and run the following
command:
python3 ActiveBuzzer.py

The result should look like the output on the following image:

To stop the script press CTRL + C on the keyboard.

- 14 -
Now it is the time to learn and make your own projects. You can do that with
the help of many example scripts and other tutorials, which can be found on
the internet.

If you are looking for the high quality microelectronics and accessories,
AZ-Delivery Vertriebs GmbH is the right company to get them from. You
will be provided with numerous application examples, full installation
guides, eBooks, libraries and assistance from our technical experts.

https://az-delivery.de
Have Fun!
Impressum
https://az-delivery.de/pages/about-us

- 15 -

You might also like