Bird
Raised Fist0
Arduinoprogramming~20 mins

tone() function for frequency generation in Arduino - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Tone Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
1:30remaining
What is the output sound frequency?
Consider this Arduino code snippet using the tone() function. What frequency will the buzzer produce?
Arduino
void setup() {
  tone(8, 1000);
}

void loop() {
  // no code here
}
ANo sound (tone not started)
B500 Hz tone on pin 8
C1000 Hz tone on pin 8
DTone on pin 8 but frequency unknown
Attempts:
2 left
💡 Hint
The second parameter of tone() is the frequency in Hertz.
❓ Predict Output
intermediate
1:30remaining
What happens when duration is specified?
What will happen when this Arduino code runs?
Arduino
void setup() {
  tone(9, 440, 500);
}

void loop() {
  // no code here
}
APin 9 outputs a continuous 440 Hz tone
BPin 9 outputs a 500 Hz tone for 440 milliseconds
CNo tone is produced because duration is too short
DPin 9 outputs a 440 Hz tone for 500 milliseconds, then stops
Attempts:
2 left
💡 Hint
The third parameter of tone() is the duration in milliseconds.
🔧 Debug
advanced
2:00remaining
Why does this code produce no sound?
This Arduino code is supposed to play a 1000 Hz tone on pin 7, but no sound is heard. What is the problem?
Arduino
void setup() {
  tone(7);
}

void loop() {
  // no code here
}
AMissing frequency parameter in tone() call
Btone() requires a duration parameter
Ctone() cannot be called in setup()
DPin 7 is not a PWM pin
Attempts:
2 left
💡 Hint
Check the parameters required by tone().
🧠 Conceptual
advanced
2:00remaining
What happens if tone() is called twice on the same pin?
If you call tone(6, 500); and then immediately call tone(6, 1000);, what will happen?
ABoth tones play simultaneously on pin 6
BThe tone changes to 1000 Hz immediately on pin 6
CThe first tone continues and the second call is ignored
DThe Arduino will crash due to conflict
Attempts:
2 left
💡 Hint
Calling tone() on the same pin replaces the previous tone.
❓ Predict Output
expert
2:30remaining
How many tones are playing after this code runs?
Given this Arduino code, how many pins are producing sound simultaneously?
Arduino
void setup() {
  tone(3, 400);
  tone(5, 600);
  tone(3, 800);
  noTone(5);
}

void loop() {
  // no code here
}
AOne tone on pin 3 at 800 Hz
BTwo tones: pin 3 at 400 Hz and pin 5 at 600 Hz
COne tone on pin 5 at 600 Hz
DNo tones playing
Attempts:
2 left
💡 Hint
Remember that calling tone() on the same pin replaces the previous tone, and noTone() stops the tone on that pin.

Practice

(1/5)
1. What does the tone() function do in Arduino?
easy
A. Generates a sound of a specific frequency on a pin
B. Reads the voltage from a sensor
C. Turns on an LED
D. Sends data over serial communication

Solution

  1. Step 1: Understand the purpose of tone()

    The tone() function is used to create sound by generating a square wave of a specific frequency on a pin.
  2. Step 2: Compare options with function behavior

    Only Generates a sound of a specific frequency on a pin describes generating sound with frequency, which matches tone() usage.
  3. Final Answer:

    Generates a sound of a specific frequency on a pin -> Option A
  4. Quick Check:

    tone() = sound frequency generation [OK]
Hint: Remember: tone() makes sound, not reads or sends data [OK]
Common Mistakes:
  • Confusing tone() with digitalWrite()
  • Thinking tone() reads sensor data
  • Assuming tone() controls LEDs
2. Which of the following is the correct syntax to play a 1000 Hz tone on pin 8 for 500 milliseconds?
easy
A. tone(8, 1000, 500);
B. tone(1000, 8, 500);
C. tone(8, 500, 1000);
D. tone(8, 1000); delay(500);

Solution

  1. Step 1: Recall tone() function parameters

    The correct order is tone(pin, frequency, duration). So pin 8, frequency 1000 Hz, duration 500 ms means tone(8, 1000, 500);.
  2. Step 2: Check each option

    tone(8, 1000, 500); matches the correct order. tone(1000, 8, 500); swaps pin and frequency. tone(8, 500, 1000); swaps frequency and duration. tone(8, 1000); delay(500); starts continuous tone but does not stop after 500 ms, unlike duration parameter.
  3. Final Answer:

    tone(8, 1000, 500); -> Option A
  4. Quick Check:

    tone(pin, freq, duration) = tone(8, 1000, 500) [OK]
Hint: Remember parameter order: pin, frequency, duration [OK]
Common Mistakes:
  • Swapping frequency and pin parameters
  • Confusing duration with frequency
  • Omitting duration when required
3. What will be the output behavior of this Arduino code snippet?
void setup() {
  tone(9, 440, 1000);
  delay(1500);
  noTone(9);
}
void loop() {}
medium
A. Pin 9 outputs a 440 Hz tone for 1.5 seconds, then stops
B. Pin 9 outputs a 440 Hz tone continuously without stopping
C. Pin 9 outputs a 440 Hz tone for 1 second, then stops
D. No sound is produced because noTone() is called immediately

Solution

  1. Step 1: Analyze tone() with duration

    The tone(9, 440, 1000); plays a 440 Hz tone on pin 9 for 1000 milliseconds (1 second).
  2. Step 2: Understand delay and noTone()

    The program waits 1500 ms, which is longer than the tone duration, so the tone stops automatically after 1 second. Then noTone(9); stops any tone if still playing (safe call).
  3. Final Answer:

    Pin 9 outputs a 440 Hz tone for 1 second, then stops -> Option C
  4. Quick Check:

    tone(9, 440, 1000) plays 1s tone [OK]
Hint: Duration in tone() controls length; noTone() stops early [OK]
Common Mistakes:
  • Thinking tone plays for delay length
  • Assuming noTone() stops tone immediately before playing
  • Confusing tone duration with delay time
4. Identify the error in this code snippet that tries to play a 500 Hz tone on pin 7:
void setup() {
  tone(7, 500);
  delay(3000);
  noTone(7);
}
void loop() {
  tone(7, 500, 1000);
}
medium
A. tone() requires frequency before pin number
B. Calling tone() inside loop() with duration causes overlapping tones
C. noTone() should be called before tone() in setup()
D. delay() cannot be used with tone()

Solution

  1. Step 1: Review tone() usage in loop()

    Calling tone(7, 500, 1000); repeatedly in loop() will restart the tone every cycle, causing overlapping or interrupted sounds.
  2. Step 2: Check other options

    noTone() can be called after tone(), tone() parameters order is correct, and delay() can be used with tone(). So only Calling tone() inside loop() with duration causes overlapping tones describes the real problem.
  3. Final Answer:

    Calling tone() inside loop() with duration causes overlapping tones -> Option B
  4. Quick Check:

    Repeated tone() with duration in loop causes overlap [OK]
Hint: Avoid tone() with duration inside loop() to prevent overlap [OK]
Common Mistakes:
  • Calling noTone() before tone() unnecessarily
  • Mixing parameter order in tone()
  • Thinking delay() blocks tone() sound
5. You want to play a melody using tone() on pin 6 with these notes and durations: 262 Hz for 500 ms, 294 Hz for 500 ms, and 330 Hz for 1000 ms. Which code correctly plays this sequence without overlapping tones?
hard
A. void setup() { tone(6, 262, 500); delay(1000); tone(6, 294, 500); delay(1000); tone(6, 330, 1000); delay(1000); } void loop() {}
B. void setup() { tone(6, 262); delay(500); tone(6, 294); delay(500); tone(6, 330); delay(1000); } void loop() {}
C. void setup() { tone(6, 262, 500); tone(6, 294, 500); tone(6, 330, 1000); } void loop() {}
D. void setup() { tone(6, 262, 500); delay(500); tone(6, 294, 500); delay(500); tone(6, 330, 1000); delay(1000); } void loop() {}

Solution

  1. Step 1: Understand tone() with duration and delay

    Using tone(pin, freq, duration) plays the note for the duration. To avoid overlap, delay should match the tone duration before playing the next note.
  2. Step 2: Evaluate each option

    void setup() { tone(6, 262, 500); delay(500); tone(6, 294, 500); delay(500); tone(6, 330, 1000); delay(1000); } void loop() {} plays each tone with correct duration and delays matching durations, so notes play sequentially without overlap. void setup() { tone(6, 262); delay(500); tone(6, 294); delay(500); tone(6, 330); delay(1000); } void loop() {} omits duration in tone(), causing continuous tones. void setup() { tone(6, 262, 500); tone(6, 294, 500); tone(6, 330, 1000); } void loop() {} calls tone() three times without delay, overlapping sounds. void setup() { tone(6, 262, 500); delay(1000); tone(6, 294, 500); delay(1000); tone(6, 330, 1000); delay(1000); } void loop() {} uses delays longer than tone durations, causing unwanted silence.
  3. Final Answer:

    tone(6, 262, 500); delay(500); tone(6, 294, 500); delay(500); tone(6, 330, 1000); delay(1000); -> Option D
  4. Quick Check:

    Match delay to tone duration for clean melody [OK]
Hint: Use delay equal to tone duration to separate notes [OK]
Common Mistakes:
  • Omitting delay after tone() with duration
  • Calling multiple tone() without delay causing overlap
  • Using longer delays causing silence gaps
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard