docs

a slatepencil documentail site

View on GitHub

Buzzer Passive

buzzer beeping in different frequence

hardware

wire

code

const int buzzerPin = 7;
int fre;  // set the vairalbe tow store the frequence value

void setup() {
  // put your setup code here, to run once:
  pinMode(buzzerPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  for (int i = 200; i <= 800; i++) {  // frequence loop from 200 to 800
    tone(7, i);                       // in pin 7 generate a tone, it frequence is i
    delay(5);                         // wait for 5 milliseconds
  }
  delay(4000);
  for (int i = 800; i >= 200; i--) {  // frequence loop from 800 down to 200
    tone(7, i);
    delay(10);  // delay 10ms
  }
}