Passive Buzzer Module code
Feb 6, 2021
it can be used as a detector for security issue, adding in fridge inside when user forgot to close fridge door, the buzz sound will remind user.
int buzzer = 8; // set the buzzer control digital IO pin
void setup() {
pinMode(buzzer, OUTPUT); // set pin 8 as output
}
void loop() {
for (int i = 0; i < 80; i++) { // make a sound
digitalWrite(buzzer, HIGH); // send high signal to buzzer
delay(1); // delay 1ms
digitalWrite(buzzer, LOW); // send low signal to buzzer
delay(1);
}
delay(50);
for (int j = 0; j < 100; j++) { //make another sound
digitalWrite(buzzer, HIGH);
delay(2); // delay 2ms
digitalWrite(buzzer, LOW);
delay(2);
}
delay(100);
}