Wiring the Passive & Active Buzzer with Raspberry Pi
Another illustration that demonstrate how to use the buzzer both passive and active. The difference between an active and passive is. The active buzzer has a built in oscillating source that will make a sound when amplifying a power compare to passive buzzer does not have such a source so it means that no beep or sound will generate when it plug to the power source on this case you need to use a square wave frequency to make a sound between 2k and 5k. As you can see diagram below there are two option to wire up the buzzer.
The active buzzer has onboard oscillating source it will beep as long as it is wired up but it can only beep with fixed frequency.
Required Component
Raspberry Pi / Banana Pi / Orange Pi (If your using Banana Pi or Orange Pi See first the GPIO Pins)
Buzzer Active / Passive Module
Solder Less Breadboard
Jumper Wire / DuPont Wire
Wiring Manually
10k Resistor /
NPN Transistor (2N222)
External Battery (5~9v)
Wiring Diagram
Uploading the Code
WiringPi Code for Active Buzzer
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <wiringPi.h>
#include <stdio.h>
#define BuzzPin 7
intmain(void)
{
if(wiringPiSetup()==-1){// When wiringpi initialization failed printf "WiringPi Failed"
File “/home/pi/SmartHome/passive_buzzer.py”, line 34, in
GPIO.setup(BuzzerPin, GPIO.OUT) # Set pins’ mode is output
RuntimeError: Please set pin numbering mode using GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM)
We use cookie to provide you the best possible experience, this site uses cookies and by continuing to use the site you agree that we can save them on your device. Cookies are small text files which are placed on your computer and which remember your preference / some details of your visit. Our cookies don’t collect any personal information. For information, please read our Privacy Statement and Cookie Policy , which also explains how to disable this option in your browser. Cookie SettingsACCEPT
Privacy & Cookies Policy
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are as essential for the working of basic functionalit...
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
File “/home/pi/SmartHome/passive_buzzer.py”, line 34, in
GPIO.setup(BuzzerPin, GPIO.OUT) # Set pins’ mode is output
RuntimeError: Please set pin numbering mode using GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM)
Python: had to copy setup and setmode commands before the “setup()”. Absolutely no indentation for some reason.