Synchronize LED and Speaker

Step 1 - Build the Project

This code takes two outputs that use different commands and places them side-by-side to make their effect occur at the same time.

Step 2 - Upload the Code

/* * Synchronize a speaker and an LED to turn on and off at the same time. */ void setup(){ pinMode(13,OUTPUT); //LED pinMode(A5,OUTPUT); //Speaker } void loop(){ digitalWrite(13,HIGH); //turn the LED on by making the voltage HIGH tone(A5,540); //send the speaker a tone of 540 hertz delay(1000); //wait one second (1000 milliseconds) & turn everything off digitalWrite(13, LOW); noTone(A5); delay(1000); //wait one second before starting the loop over again } // Reverse the code so that when the speaker is on, the light is off // (c) 2017 Let's Start Coding. License:

Step 3 - Read the Walkthrough

The code is read through from top to bottom and the different commands don’t interfere with each other, so this code is similar to turning two LEDs on at once with a few syntax differences.

After both of the pins are set as OUTPUTs, they are ready to receive power to control their output. Next, you command each output individually. After the one second delay, use each output’s command to turn off each component using noTone and digitalWrite. Wait one second and start through the code again!