Home LearningBasics Piezo Buzzer example

Piezo Buzzer example

by shedboy71

In this example we will connect a Piezo buzzer to our arduino and play some basic sounds, this uses the PWM functionality of the Arduino.

A piezoelectric element may be driven by an oscillating electronic circuit or other audio signal source, driven with a piezoelectric audio amplifier. Sounds commonly used to indicate that a button has been pressed are a click, a ring or a beep.

A piezoelectric buzzer/beeper also depends on acoustic cavity resonance or Helmholtz resonance to produce an audible beep

 

Schematic

piezo schematic

piezo schematic

Layout

piezo layout

piezo layout

 

Code

[codesyntax lang=”cpp”]

void setup()
{
// declare pin 9 to be an output:
pinMode(9, OUTPUT);
}

void loop()
{
beep(500);
}

void beep(unsigned char delayMS)
{
//write a value between 1 and 254 out
//delay, switch off and delay again
analogWrite(9, 220);
delay(delayMS);
analogWrite(9, 0);
delay(delayMS);
}

[/codesyntax]

 

Links
Piezo Electric Buzzer at Amazon US
Piezo Electric Buzzer at Amazon UK

Share

You may also like