Menu Close

Peizo buzzer with Raspberry Pi

This tutorial of Robo India explains how to use buzzer on Raspberry Pi.

Detailed Tutorial

1. Introduction:

A Peizo buzzer is a device that is used to generate beep sound (generally a warning or alert in embedded system). It is a two leg device the longer leg is positive. If voltage is supplied it generates beep sound. Through analog write volume of beep can be controlled.

If a buzzer is switched with different time intervals it generates a melody.

This tutorial is for Raspberry Pi. Please note that the same tutorial can be performed on LUA as well.

1.2 Hardware required

S.No.ItemQuantity
1Raspberry Pi 1
2Pi Wedge B + 1
3Breadboard 1
4Jumper Male to male 2
5Buzzer 1

2. Building Circuit

Schematic Diagram:

Circuit Layout:

3. Programming:

Once the circuit part is done, Raspberryb Pi is needed to be programmed. Here is the code to run this circuit.

You may download this code (Python Code) from here.

import time
import RPi.GPIO as gpio

gpio.setwarnings(False)
gpio.setmode(gpio.BOARD)
gpio.setup(22,gpio.OUT)

try:
    while True:
        	gpio.output(22,0)
        	time.sleep(.3)
        	gpio.output(22,1)
       		 time.sleep(.3)
except KeyboardInterrupt:
            gpio.cleanup()
             exit

4. Output

The buzzer generates beep sound in a loop. Try delay in microseconds to generate melody. Volume is controlled through analogWrite.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply