Some links in this post may be affiliate links. We may get paid if you buy something or take an action after clicking one of these, but without addictional costs for you compared to direct buying.
Raspberry pi Active Buzzer featured image

Use Active Buzzer with Raspberry PI and Python

Check my RPI articles in Best Raspberry PI projects article or peppe8o.com home page. Or subscribe my newsletter (top right in this page) to be notified when new projects are available! Also interested to start 3D printing with a cheap budget? Visit my cheap 3D printers list
5
(1)

Active buzzer is a cheap electronic component able to produce a sound when powered with a DC current.

Active Buzzer

Differently from passive buzzer, this element includes a built-in oscillator. This allow user to make it working by powering on and without the need to simulate an electronic square wave. It includes 2 rear pins. The longer one is positive and must be connected to power signal. The shorter one is ground and must be connected to 0V (ground).

Final result is a semplified programming script to use it.

In this guide I’ll show you how to use an activebuzzer with your Raspberry PI. I will use a Raspberry PI Zero W, but this guide will work also with newer Raspberry PI boards.

What We Need

As usual, I suggest adding from now to your favourite ecommerce shopping chart all needed hardware, so that at the end you will be able to evaluate overall costs and decide if continuing with the project or removing them from shopping chart. So, hardware will be only:

Raspberry PI Zero WH board

Rearding active buzzer, you can also evaluate the cheap Elegoo starter kit, which includes a number of sensors useful for your electronics projects.

Check hardware prices with following links:

Amazon raspberry pi boards box
Amazon raspberry pi Zero W box
Amazon Raspberry PI Power Supply box
Amazon Micro SD box
Amazon Dupont Wiring box
Amazon active buzzer box

Wiring Diagram

Following picture shows wiring diagram adopted:

Raspberry pi Active Buzzer wiring

Following picture shows overall project:

Raspberry pi Active Buzzer picture

Step-by-Step Procedure

An headless installation will be performed. However, also a Desktop installation works, using terminal.

Environment Preparation

This procedure starts from operating system setup installing Raspberry PI OS Lite.

Align your Raspberry PI to latest updates. From terminal:

sudo apt update
sudo apt upgrade

Install RPI GPIO package to manage GPIOs pins from python:

sudo apt install rpi.gpio

Prepare Python Script

Python script becomes really simple with GPIO. You can download it in your Raspberry PI from terminal:

wget https://peppe8o.com/download/python/active_buzzer.py

Below the script description.

Before all, needed libraries are imported:

import sys
import RPi.GPIO as GPIO
import time

Signal PIN (pin where positive cable is connected) is defined in a variable for better management. Be aware to use GPIO BCM naming. In my cabling it is number 14. It is also set to be an output pin:

signalPIN = 14
GPIO.setmode(GPIO.BCM)
GPIO.setup(signalPIN,GPIO.OUT)

At this point our buzzer is ready to work. Our script will set its power output on and wait 5 seconds: this means that buzzer will produce its sound for 5 seconds. Then GPIO PINs are cleaned and script exits:

GPIO.output(signalPIN,1)
time.sleep(5)

GPIO.cleanup()
sys.exit()

Enjoy!

How useful was this post?

Click on a star to rate it anonymously!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Comment

Your email address will not be published. Required fields are marked *

I accept the Privacy Policy