Fun with Piezo’s

Share on facebook
Share on google
Share on twitter
Share on linkedin
A VPN is an essential component of IT security, whether you’re just starting a business or are already up and running. Most business interactions and transactions happen online and VPN

I’ve created a simple beeping alarm with a Piezo transducer. Connect the Piezo + to pin 9, and the Piezo – to Gnd. Run the following sketch. Next version will be using the tone() command to build a Morse Code trainer.

 This example shows how to run a Piezo Buzzer on pin 9
 using the analogWrite() function.
 It beeps 3 times fast at startup, waits a second then beeps continuously
 at a slower pace

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

void loop() {

void beep(unsigned char delayms){
analogWrite(9, 20); // Almost any value can be used except 0 and 255
// experiment to get the best tone
delay(delayms); // wait for a delayms ms
analogWrite(9, 0); // 0 turns it off
delay(delayms); // wait for a delayms ms

Steve Spence

Steve Spence

Leave a Reply

Leave a Comment

Your email address will not be published. Required fields are marked *