Loading... Please wait...

Active Piezo Buzzer

Active Piezo Buzzer

This example shows how to play a tone on a passive piezo buzzer.

  • Arduino Board
  • Active Piezo Buzzer

Circuit

To build the circuit, connect one side of the piezo transducer to pin 9 and the other side to GND.

 

piezopassive.png

image developed using Fritzing. For more circuit examples, see the Fritzing project page

 

Code

/*
 Piezo
 
 This example shows how to run a Piezo Buzzer on pin 9
 using the digitalWrite() 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);
  beep(50);
  beep(50);
  beep(50);
  delay(1000);
} 

void loop()  { 
  beep(200); 
}

void beep(unsigned char delayms){
  digitalWrite(9, HIGH);      // Can only be on or off
  delay(delayms);          // wait for a delayms ms
  digitalWrite(9, LOW);       // 0 turns it off
  delay(delayms);          // wait for a delayms ms   
}  
 

What's News

newsletter

Copyright 2019 oddWires. All Rights Reserved.
 Sitemap | oddWires