It plays a sound of a specific frequency on a speaker connected to a pin, creating a tone or note.
Click to reveal answer
beginner
How do you stop a tone that is playing on a pin?
Use the noTone(pin) function to stop the sound on that pin.
Click to reveal answer
beginner
What are the three parameters of tone()?
1. The pin number where the speaker is connected. 2. The frequency of the tone in Hertz. 3. (Optional) The duration in milliseconds to play the tone.
Click to reveal answer
intermediate
Why do we use arrays when playing melodies with tone()?
Arrays store sequences of notes and their durations so the program can play melodies by looping through them.
Click to reveal answer
intermediate
What happens if you call tone() on a pin that is already playing a tone?
The new tone replaces the old one immediately on that pin.
Click to reveal answer
Which function stops a tone playing on a pin?
Atone(pin, 0)
BstopTone(pin)
CnoTone(pin)
DendTone(pin)
✗ Incorrect
The correct function to stop a tone is noTone(pin).
What does the second parameter of tone(pin, frequency) represent?
AFrequency in Hertz
BDuration in milliseconds
CPin number
DVolume level
✗ Incorrect
The second parameter is the frequency of the tone in Hertz.
How can you play a melody using tone()?
ABy using <code>noTone()</code> repeatedly
BBy calling <code>tone()</code> once with all notes
CBy connecting multiple speakers to different pins
DBy using arrays to store notes and durations and looping through them
✗ Incorrect
Melodies are played by looping through arrays of notes and durations, calling tone() for each.
What happens if you omit the duration parameter in tone()?
AThe tone plays forever until <code>noTone()</code> is called
BThe tone plays for 1 second
CThe tone does not play
DThe tone plays for 100 milliseconds
✗ Incorrect
If duration is omitted, the tone plays continuously until stopped.
Which Arduino pin type is required to use tone()?
AAnalog input pins
BDigital output pins
CPower pins
DGround pins
✗ Incorrect
tone() works on digital output pins connected to a speaker or buzzer.
Explain how you would use the tone() function to play a simple melody on an Arduino.
Think about storing notes and durations, then playing each note one by one.
You got /4 concepts.
Describe the role of the frequency and duration parameters in the tone() function.
Frequency is like the musical note, duration is how long you hear it.
You got /4 concepts.
Practice
(1/5)
1. What does the tone() function do in Arduino?
easy
A. It reads the value from a sensor.
B. It controls the brightness of an LED.
C. It plays a sound at a specific frequency on a speaker.
D. It sends data over the serial port.
Solution
Step 1: Understand the purpose of tone()
The tone() function generates a square wave of the specified frequency on a pin, producing sound through a speaker.
Step 2: Compare options with function behavior
Only It plays a sound at a specific frequency on a speaker. describes playing sound at a frequency, which matches tone() usage.
Final Answer:
It plays a sound at a specific frequency on a speaker. -> Option C
Quick Check:
tone() = plays sound [OK]
Hint: Remember: tone() controls sound frequency, not LEDs or sensors [OK]
Common Mistakes:
Confusing tone() with analogWrite() for LEDs
Thinking tone() reads sensor data
Assuming tone() sends serial data
2. Which of the following is the correct syntax to play a 440 Hz tone on pin 8 for 500 milliseconds?
easy
A. tone(8, 440); delay(500);
B. tone(440, 8, 500);
C. tone(8, 500, 440);
D. tone(8, 440, 500);
Solution
Step 1: Recall tone() function parameters
The correct order is tone(pin, frequency, duration). So pin 8, frequency 440 Hz, duration 500 ms.
Step 2: Check each option's parameter order
tone(8, 440, 500); matches the correct order. tone(8, 440); delay(500); plays tone without duration, relying on delay, which is valid but not the asked syntax.
A. The delay() calls are too short to hear the notes.
B. The second tone replaces the first (which continues until replaced), resulting in sequential notes without overlap.
C. noTone() is called too early, stopping the melody immediately.
D. tone() requires a duration parameter to work correctly.
Solution
Step 1: Understand tone() without duration
Calling tone(pin, freq) plays the tone continuously until stopped or replaced by another tone() on the same pin.
Step 2: Analyze timing of tones and delays
The first tone starts and plays for 500 ms during delay(). The second tone replaces it immediately, playing the new frequency for the next 500 ms. No overlap occurs.
Final Answer:
The second tone replaces the first (which continues until replaced), resulting in sequential notes without overlap. -> Option B
Quick Check:
tone without duration replaced by next tone() = sequential notes [OK]
Hint: tone() without duration continues until next tone() or noTone() [OK]
Common Mistakes:
Assuming tone() stops automatically after delay
Thinking tone() calls on same pin cause overlap
Believing delay controls tone length without duration
5. You want to play a melody of 3 notes (262 Hz, 294 Hz, 330 Hz) each lasting 300 ms on pin 10 with 100 ms pause between notes. Which code snippet correctly achieves this?
hard
A. for (int i = 0; i < 3; i++) {
int notes[] = {262, 294, 330};
tone(10, notes[i], 300);
delay(400);
}
noTone(10);
B. int notes[] = {262, 294, 330};
for (int i = 0; i < 3; i++) {
tone(10, notes[i]);
delay(250);
noTone(10);
delay(100);
}
C. int notes[] = {262, 294, 330};
for (int i = 0; i < 3; i++) {
tone(10, notes[i], 300);
delay(250);
noTone(10);
delay(100);
}
D. int notes[] = {262, 294, 330};
for (int i = 0; i < 3; i++) {
tone(10, notes[i]);
delay(400);
}
noTone(10);
Solution
Step 1: Understand timing requirements
Each note plays 300 ms, plus 100 ms pause, total 400 ms delay between notes.
Step 2: Check code for correct tone duration and delay
for (int i = 0; i < 3; i++) {
int notes[] = {262, 294, 330};
tone(10, notes[i], 300);
delay(400);
}
noTone(10); uses tone with duration 300 ms and delay 400 ms, matching timing. noTone(10) after loop stops sound.
Step 3: Verify other options
int notes[] = {262, 294, 330};
for (int i = 0; i < 3; i++) {
tone(10, notes[i]);
delay(250);
noTone(10);
delay(100);
} calls noTone inside loop, cutting notes short. int notes[] = {262, 294, 330};
for (int i = 0; i < 3; i++) {
tone(10, notes[i], 300);
delay(250);
noTone(10);
delay(100);
} delays only 250 ms, missing pause. int notes[] = {262, 294, 330};
for (int i = 0; i < 3; i++) {
tone(10, notes[i]);
delay(400);
}
noTone(10); plays tone without duration, causing overlap.
Final Answer:
for (int i = 0; i < 3; i++) {
int notes[] = {262, 294, 330};
tone(10, notes[i], 300);
delay(400);
}
noTone(10); -> Option A
Quick Check:
tone(duration) + delay(total note+pause) = for (int i = 0; i < 3; i++) {
int notes[] = {262, 294, 330};
tone(10, notes[i], 300);
delay(400);
}
noTone(10); [OK]
Hint: Use tone(duration) plus delay(total note+pause) for melody timing [OK]
Common Mistakes:
Calling noTone() inside loop too early
Using delay shorter than note+pause
Omitting duration causing overlapping notes
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.