Menu
CoddyTech

Beeps and Silence

Part of the Outputs section of Coddy's Arduino journey. Lesson 11 of 24.

To stop a tone, call noTone(pin). A beep is a tone, a wait, then silence:

tone(8, 1000);
delay(100);
noTone(8);

tone() can also take a third number, a duration in milliseconds. The tone then stops on its own:

tone(8, 1000, 100);  // beep for 100 ms
delay(200);         // the beep, then 100 ms of quiet

Careful: tone() does not wait for the beep to end. The next line runs at once, while the buzzer is still sounding. So a delay() is still needed to space beeps out: without it, two beeps in a row land on top of each other and you hear one.

challenge icon

Challenge

Easy

Make the buzzer on pin 8 beep in pairs, like a phone ringing:

  • a 1000 Hz beep of 100 ms
  • 100 ms of silence
  • a second 100 ms beep
  • one second of silence, then again

Press Run, then Check.

Try it yourself

const int buzzerPin = 8;

void setup() {
}

void loop() {
  // beep, short silence, beep, then a second of silence
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Outputs

Practice on your own: Arduino playground