click here to enter

Piezo Buzzer - Kingston hackSpace

Kingston hackSpace

Piezo buzzer

Piezo buzzers are used for making beeps, tones and alerts. The once we have in hackSpace are little but loud! Drive it with 3-30V peak-to-peak square waves. To use, connect one pin to ground (either one) and the other pin to a square wave out from a timer or microcontroller. For the loudest tones, stay around 4 KHz, but they do work quite well from 2KHz to 10KHz.

Wiring the buzzer is very simple you only have a positive and negative. The positive would be connected to one of the digital pins on your Arduino, the tone values will be transmitted though the buzzer.


/*
http://kingstonhack.space

piezo buzzer digital trumpet

*/

int freqs[] = {1915,1700,1519,1432,1275,1136,1014,956}

void setup() {
  // put your setup code here, to run once:
   pinMode(11,OUTPUT);
   pinMode(3,INPUT);//first valve
   pinMode(4,INPUT);//second valve
   pinMode(5,INPUT);//third valve
   pinMode(6,INPUT);//extra button for embrasure
}

void loop() {
  // put your main code here, to run repeatedly:

  //====================C
  if(digitalRead(3)==LOW&&digitalRead(4)==LOW&&digitalRead(5)==LOW&&digitalRead(6)==LOW){
       tone(0);
    }
  //====================D
  if(digitalRead(3)==HIGH&&digitalRead(4)==LOW&&digitalRead(5)==HIGH&&digitalRead(6)==LOW){
       tone(1);
    }
  //====================E
  if(digitalRead(3)==HIGH&&digitalRead(4)==HIGH&&digitalRead(5)==LOW&&digitalRead(6)==LOW){
       tone(2);
    }
  //====================F
  if(digitalRead(3)==HIGH&&digitalRead(4)==LOW&&digitalRead(5)==LOW&&digitalRead(6)==LOW){
       tone(3);
    }
  //====================G
  if(digitalRead(3)==HIGH&&digitalRead(4)==LOW&&digitalRead(5)==HIGH&&digitalRead(6)==HIGH){
       tone(4);
    }
  //====================A
  if(digitalRead(3)==HIGH&&digitalRead(4)==HIGH&&digitalRead(5)==LOW&&digitalRead(6)==HIGH){
       tone(5);
    }
    //====================B
  if(digitalRead(3)==HIGH&&digitalRead(4)==HIGH&&digitalRead(5)==LOW&&digitalRead(6)==HIGH){
       tone(6);
    }
    //====================C
  if(digitalRead(3)==LOW&&digitalRead(4)==LOW&&digitalRead(5)==LOW&&digitalRead(6)==HIGH){
       tone(7);
    }

  }

  void tone(int frequency){
       digitalWrite(11,HIGH);
       delayMicroseconds(frqs[frequency]);
       digitalWrite(11,LOW);
       delayMicroseconds(frqs[frequency]);
    }