Home CodeMicropython A Raspberry Pi Pico and KY-012 Active Buzzer

A Raspberry Pi Pico and KY-012 Active Buzzer

by rp2040guy71

In this article, we connect a KY-012 Active Buzzer to a Raspberry Pi Pico, any Rp2040 type board will be suitable. We actually tested this with a Cytron Maker Pi Pico

We will use Micropython for these examples but of course you can use the Arduino IDE as well if you have Raspberry Pi Pico support enabled

The KY-012 active piezo buzzer is a 3-pin module that creates an audible sound at 2.5 kHz without the need for pulse width modulation. The only requirement is to set the signal pin to HIGH.

You only need to connect 2 of the pins.

  • Min/Max Operating Voltage +3.3V to +5V
  • Maximum Current: 30mA
  • Resonance Frequency: 2500Hz ± 300Hz continous
  • Minimum Sound Output 85Db @ 4in (10cm)
  • Storage Temperature: -22°F to  221°F (-30°C to  105°C)
  • Operating Temperature: -4°F to 158°F (-20°C to 70°C)

The sensor looks like this

Parts Required

You can connect to the module using dupont style jumper wire.

Name   Link
Raspberry Pi Pico
37 in one sensor kit
Connecting cables

 

Schematic/Connection

Pico SENSOR
GPIO28 S
GND

 

Code Examples

Basic example

from machine import Pin
from utime import sleep

# Initialization of GPIO28 as output
buzzer = Pin(28, Pin.OUT, value=0)

# Switch on buzzer
print("ON")
buzzer.on()

# Wait 3 seconds
print("Wait for 3 seconds")
sleep(3)

# Switch off buzzer
print("OFF")
buzzer.off()

 

REPL Output

Just for debug

MicroPython v1.17 on 2021-09-02; Raspberry Pi Pico with RP2040
Type “help()” for more information.
>>> %Run -c $EDITOR_CONTENT
ON
Wait for 3 seconds
OFF

Links

https://github.com/getelectronics/rp2040learning/tree/main/Sensor%20Kit/KY-012%20Active%20Buzzer

 

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More