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

Piezo Speaker

Available Languages
Picture
Picture

Introduction 

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

What you will need - Hardware

For this tutorial you will need:
  • Arduino uno
  • Breadboard
  • Buzzer/piezo speaker
  • 100 Ohm resistor
Picture

The Circuit

Picture
The connections are pretty easy, see the image above with breadboard circuit schematic.
Gearbest Flash Sale: Up to 80% Off promotion
Flash Sale: Up to 80% Off

The coder

Here's the "Tone" code.
How it works? It's simple, tone(buzzer, 1000) sends a 1KHz sound signal to pin 9, delay(1000) pause the program for one second and noTone(buzzer) stops the signal sound. The loop() routine will make this run again and again making a short beeping sound.
(you can also use tone(pin, frequency, duration) function)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
/* Arduino tutorial - Buzzer / Piezo Speaker
   More info and circuit: http://www.ardumotive.com/how-to-use-a-buzzer-en.html
   Dev: Michalis Vasilakis // Date: 9/6/2015 // www.ardumotive.com */

const int buzzer = 9; //buzzer to arduino pin 9

void setup(){
  pinMode(buzzer, OUTPUT); // Set buzzer - pin 9 as an output
}

void loop(){
  tone(buzzer, 1000); // Send 1KHz sound signal...
  delay(1000);        // ...for 1 sec
  noTone(buzzer);     // Stop sound...
  delay(1000);        // ...for 1sec
}
Download the code from here and open it with Arduino IDE.
buzzer_tutorial.zip
File Size: 0 kb
File Type: zip
Download File

You can keep playing with that and start making your own modifications to the code.
For example, try to change sound signal "1000" (1KHz) to "500" (500Hz) or delay time and see how it changes the program.

Well done!

You have successfully completed one more Arduino "How to" tutorial and you learned how to use:
  • buzzer / piezo speaker
  • tone(), noTone() functions
I hope you liked this, let me know in the comments.
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