Alternate a low tone and a high tone so the buzzer sounds like an alarm. A drop-in alarm sounder for the design project.
From the unit Crack the Code
· activity PRP 4: Digital output — Buzzer
int lowTone = 400;
int highTone = 600;
const int ALARMSOUNDER = 3; // the buzzer is on pin D3
void setup() {
pinMode(ALARMSOUNDER, OUTPUT);
}
void loop() {
tone(ALARMSOUNDER, lowTone, 500); // low tone for half a second
delay(500);
tone(ALARMSOUNDER, highTone, 500); // high tone for half a second
delay(500);
}
Shared from Little Bird Electronics curriculum.