How to Use a Piezo to Produce Tone : Basics
by Anshu AR in Circuits > Arduino
14590 Views, 69 Favorites, 0 Comments
How to Use a Piezo to Produce Tone : Basics
Hello everyone, In this instructable, We will be using a Piezo buzzer to produce tone.
What is a Piezo buzzer?
- A Piezo is a electronic device that can be used both to produce as well as detect sound.
Applications:
- You can use the same circuit to play a musical note by switching the Piezo on and off several times.
- The experience can be further improved by changing the loudness of the Buzzer using Arduino PWM pins.
We will be starting from basics and will produce a simple Beeping tone using Piezo.
Gather the Parts
For this project we will need:
- An Arduino UNO
- A 5V Piezo Buzzer
- Jumper wires
Don't we need a resistor to limit the current through the buzzer?
No, if you are using a small 5V Piezo.
As it derives or uses very small amount of current so can be used without a resistor in series.
Wiring
Hookup all the components according to the circuit shown above.
Polarity of the buzzer:
Before connecting the Piezo to Arduino, note that a Piezo buzzer has polarity.
- The positive lead of the Piezo has Red wire.
- But, If you have got a Breadboard mountable Piezo then the Positive terminal of the Piezo has a longer lead than negative terminal.
Arduino Sketch
Once you have wired up everything, Upload the following to Arduino:
void setup() {
pinMode(9, OUTPUT); // declare pin 9 to be an output: }
void loop(){
analogWrite(9, 20); // Any value can be used except 0 and 255
delay(300); // wait for 3 ms
analogWrite(9, 0); // turns it off
delay(300); // wait for 3 ms
}
Downloads
Done
Once done power the Arduino to hear the beep.
Troubleshooting:
No sound
- Check that the buzzer is connected to the arduino properly.
Have you inserted the buzzer to the correct pin?
- Pay attention on the Polarity of the Piezo buzzer. That is, Positive lead of the buzzer should go to PIN 9 and negative to GND on the Arduino respectively.
If you still can't hear Re-upload the sketch.
Or, Write in comments below.
Thanks for viewing.