PROJECT: Countdown Speaker Alarm
Step 1 - Build the Project

Countdown Speaker Alarm Hookup: 1 speaker on pin A5

Topics Covered:

 

 

This bit of code is an alarm sound from a speaker. The trick to the ‘countdown’ is that the program is delayed by the number of milliseconds inside delay(). The setup code will set the speaker pin as an output, then it will pause for the delay amount of time.

Step 2 - Upload the Code

/* * Set a timer using delay and get an alarm tone when the timer has ended */ void setup(){ pinMode(A5,OUTPUT); //speaker pin delay(5000); //put your delay timer here in milliseconds tone(A5,350); //alarm tone after the delay ends delay(500); tone(A5,550); delay(500); tone(A5,750); delay(500); noTone(A5); } void loop(){ //no loop needed! } // Try to modify the delay for the alarm with serial monitor inputs // (c) 2017 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense
 

Step 3 - Read the Walkthrough

When the pause is over, the program will run whatever code is below the delay. In this case, that’s your alarm! If you put this code inside the loop, it will run again and again, so you could create a repeating alarm every minute delay(60000) or every hour delay(3600000). Delay can only go up to about 4.29 million, so a daily alarm isn’t very easy with this method.