Piezo

This was a fun little thing to try.

All it required was an old piezo from a computer case, an arduino and a few lines of code. This little code only makes a beep every second, where the pitch can be adjusted by changing “val = 130” up or down. Changing it up will result in a deeper noise because it defines the delay between high and low.

int piezoPin = 11;

void beep()
{
  for(int i=0; i < 500; i++)
  {
    int val = 130;
    digitalWrite(piezoPin, HIGH);
    delayMicroseconds(val);
    digitalWrite(piezoPin, LOW);
    delayMicroseconds(val);
  }
}

void setup()
{
  pinMode(piezoPin, OUTPUT);
}

void loop()
{
  beep();
  delay(1000);
}

Leave a Reply