Little Bird Curriculum / code littlebird.com.au
_08_Buzzer2.ino Arduino (C/C++) 14 lines · 2 views ✦ Open in English IDE Raw Download Embed view

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);
}

Embed this snippet

As an iframe:

Or drop it inline with a script tag (injects the highlighted block where included):

Shared from Little Bird Electronics curriculum.

Copied to clipboard