Raspberry Pi w/ Buzzer

Rpi buzzer

Simple Breadboard setup –

a) Place a passive buzzer anywhere on breadboard with both buzzer pins in same column (e above), mark the side with (+) sign.

b) Take a wire and hook one side of wire to same row as + buzzer pin, hook the other side of wire to GPIO 22 (its 8th pin from top)

c) Take another wire and hook one side of wire to same row as other buzzer pin, hook the other side of wire to any GND pin (3rd pin from top in above setup)

 

Code Setup –

pi@vinu-ras1:~/raspython $ touch simplebuzz.py

pi@vinu-ras1:~/raspython $ nano simplebuzz.py
 #!/usr/bin/python

import os
from time import sleep
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)
GPIO.setup(22,GPIO.OUT)

loop_count = 0

# define a function
 def buzz ():
         pitch = float(8000)
         duration = 1
         period = 1.0/pitch
         delay = period/2
         cycles=int(duration*pitch)
         for i in range(cycles):
                GPIO.output(22,True)
                sleep(delay)
                GPIO.output(22,False)
                sleep(delay)
         GPIO.cleanup()

os.system('clear')
print "Begin"

buzz()

Run python script to get buzzed…

pi@vinu-ras1:~/raspython $ python simplebuzz.py

Leave a Reply

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