Ardumotive Arduino Greek Playground
  • Home
    • About us
    • Contact
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

How to use a Buzzer

                          20/7/2018
Available Languages
Picture
Picture

Introduction 

Picture
In this tutorial you will learn how to use a buzzer (or piezo speaker) with Raspberry Pi. Buzzers can be found in alarm devices, computers, timers and confirmation of user input such as a mouse click or keystroke.

Let's get started!

What you will need - Hardware

For this tutorial you will need:
  • GPIO Breakout
  • Breadboard
  • Buzzer/piezo speaker
Picture

The Circuit

Picture
The connections are pretty easy, see the image above with breadboard circuit schematic.

Python code

In the program below, the first thing you do is to import the library for GPIO and sleep. The next step is to initialize pin 23 as an output pin with GPIO.setup( ) function.
The While True loop runs over and over again, forever. In the main loop, you make a beep sound with GPIO.output( ) function and "pause" the program for 0.5 second with sleep( ) function.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#Libraries
import RPi.GPIO as GPIO
from time import sleep
#Disable warnings (optional)
GPIO.setwarnings(False)
#Select GPIO mode
GPIO.setmode(GPIO.BCM)
#Set buzzer - pin 23 as output
buzzer=23 
GPIO.setup(buzzer,GPIO.OUT)
#Run forever loop
while True:
    GPIO.output(buzzer,GPIO.HIGH)
    print ("Beep")
    sleep(0.5) # Delay in seconds
    GPIO.output(buzzer,GPIO.LOW)
    print ("No Beep")
    sleep(0.5)
Download the code from here and open it with Thonny Python IDE  or run it from terminal.
buzzertutorial.zip
File Size: 0 kb
File Type: zip
Download File

Well Done

You have successfully completed one more Raspberry Pi "How to" tutorial and you learned how to use a buzzer.
I hope you liked this, let me know in the comments.

Video in Greek language

Picture

Search Engine

Picture

Licence 

Picture

Help us to grow up!

Picture


Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates