Alarm & Flashing Light
Who doesn't love a good alarm sound? Annoy practically everyone with this classic invention. We'll even include a flashing light for extra effect.
Play VideoStart by watching this video
Step 1
Let’s build this!

Connections
Buzzer
The +LEG is the longer leg.
RGB LED
Use wires to join these.
The -LEG is the LONGEST.
Step 2
Code some chaos!
Don’t forget to select your port!
Open the ‘Tools’ menu and select the option that says ‘Arduino/Genuino Uno’.
Copy and paste the sample code
int buzzer = 11;
int redPin = 3;
int bluePin = 5;
int beepLength = 500;
void setup() {
pinMode(buzzer, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(bluePin, OUTPUT);
} // close setup
void loop() {
analogWrite(buzzer, 255);
analogWrite(redPin, 50);
analogWrite(bluePin, 0);
delay(beepLength);
analogWrite(buzzer, 0);
analogWrite(bluePin, 50);
analogWrite(redPin, 0);
delay(beepLength);
}
Upload the code and test it out
Step 3
Modify the Madness!
Change the volume level of the alarm
For once, this change isn’t all that exciting. Since the volume of the alarm is already maxed out, the only way the volume can be changed is by bringing it down. But still, if the beeping is a little too loud, then this might be helpful. Line 14 is where the buzzer’s volume is set. Let’s take a look.
analogWrite(buzzer, 255);
The volume here is set with a value anywhere between 0 and 255, where 0 is completely off and 255 is maximum volume. Try a few different values to see what they do to the program.
Change how long each beep goes for
In line 5, you can see that we have set ‘beepLength’ to equal ‘500’. This is what’s called a variable, but more on that later. Changing this number will alter the length and space between each beep.
int beepLength = 500;
The beepLength is used in the program to control the amount of time that the beep stays on for and also the time that it is off for. This is done with a delay on lines 17 and 21 of the code.
delay(beepLength);
You always have to use a number for a delay to work properly, but because beepLength was given a number (500) earlier on in the code, that is how many milliseconds the delay will go for.
What is cool is that when we change beepLength in line 5 of the code to something else, like 750, the delay time on lines 17 and 21 will change to 750 milliseconds with it.