Bird
Raised Fist0
Arduinoprogramming~10 mins

noTone() to stop sound in Arduino - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - noTone() to stop sound
Start
↓
Call tone(pin, freq)
↓
Sound plays on pin
↓
Call noTone(pin)
↓
Sound stops on pin
↓
End
The program starts, plays a tone on a pin, then stops the sound by calling noTone on the same pin.
Execution Sample
Arduino
tone(8, 1000);  // Play 1000Hz tone on pin 8
delay(1000);      // Wait 1 second
noTone(8);        // Stop sound on pin 8
This code plays a 1000Hz sound on pin 8 for 1 second, then stops the sound.
Execution Table
StepActionPinFrequencySound StateOutput
1Call tone()81000PlayingTone starts on pin 8 at 1000Hz
2delay(1000)--PlayingSound continues for 1 second
3Call noTone()8-StoppedSound stops on pin 8
4End--StoppedNo sound playing
💡 Sound stops after noTone() is called on pin 8
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3Final
pin 8 sound stateStoppedPlayingPlayingStoppedStopped
Key Moments - 2 Insights
Why does the sound stop after calling noTone(8)?
Because noTone(8) tells the Arduino to stop generating the sound on pin 8, as shown in step 3 of the execution_table.
What happens if noTone() is not called after tone()?
The sound will keep playing indefinitely on the pin, as seen between steps 1 and 2 where the sound state remains 'Playing'.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the sound state on pin 8 after step 2?
APlaying
BStopped
CPaused
DUndefined
💡 Hint
Check the 'Sound State' column for step 2 in the execution_table.
At which step does the sound stop playing on pin 8?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look for when 'Sound State' changes to 'Stopped' in the execution_table.
If we remove noTone(8), what would happen to the sound state after step 3?
AIt would become Stopped
BIt would remain Playing
CIt would pause
DIt would cause an error
💡 Hint
Refer to key_moments about what happens if noTone() is not called.
Concept Snapshot
tone(pin, frequency) starts sound on a pin
noTone(pin) stops sound on that pin
Use noTone() to end a tone early
Without noTone(), sound plays indefinitely
Works on Arduino digital pins
Full Transcript
This example shows how to use noTone() to stop a sound started by tone() on an Arduino pin. First, tone(8, 1000) starts a 1000Hz sound on pin 8. The program waits 1 second with delay(1000), during which the sound plays. Then noTone(8) is called to stop the sound on pin 8. The execution table tracks each step: starting the tone, waiting, stopping the tone, and ending. The variable tracker shows the sound state on pin 8 changing from stopped to playing, then back to stopped. Key moments clarify that noTone() is necessary to stop the sound, otherwise it plays forever. The quiz tests understanding of when the sound stops and what happens if noTone() is omitted. The snapshot summarizes the key points: tone() starts sound, noTone() stops it, and noTone() is needed to end the sound early.

Practice

(1/5)
1. What does the Arduino function noTone(pin) do?
easy
A. Changes the volume of the sound on the specified pin
B. Starts playing a tone on the specified pin
C. Stops any sound currently playing on the specified pin
D. Sets the pin as an output pin

Solution

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

    The function noTone(pin) is designed to stop any sound that is currently playing on the given pin.
  2. Step 2: Differentiate from tone()

    Unlike tone(pin, frequency) which starts a sound, noTone(pin) stops it.
  3. Final Answer:

    Stops any sound currently playing on the specified pin -> Option C
  4. Quick Check:

    noTone() stops sound = A [OK]
Hint: Remember: noTone() always stops sound on the pin [OK]
Common Mistakes:
  • Confusing noTone() with tone()
  • Thinking noTone() changes volume
  • Assuming noTone() starts sound
2. Which of the following is the correct syntax to stop a tone on pin 8?
easy
A. noTone8();
B. noTone();
C. noTone(pin=8);
D. noTone(8);

Solution

  1. Step 1: Recall the function syntax

    The correct syntax for stopping a tone on a specific pin is noTone(pin); where pin is the pin number.
  2. Step 2: Check each option

    noTone8(); uses invalid function name. noTone(pin=8); uses invalid named parameter syntax. noTone(); omits the pin number. noTone(8); is correct.
  3. Final Answer:

    noTone(8); -> Option D
  4. Quick Check:

    Correct syntax = B [OK]
Hint: Use noTone(pin) with pin number inside parentheses [OK]
Common Mistakes:
  • Omitting the pin number
  • Using incorrect function names
  • Passing pin as named argument
3. What will be the output behavior of this Arduino code snippet?
tone(9, 1000);
delay(500);
noTone(9);
delay(500);
medium
A. A 1000 Hz tone plays continuously without stopping
B. A 1000 Hz tone plays for 500 ms, then stops
C. No sound plays at all
D. The tone plays for 1000 ms then stops automatically

Solution

  1. Step 1: Analyze tone() and delay()

    The tone(9, 1000); starts a 1000 Hz sound on pin 9. The delay(500); pauses the program for 500 milliseconds while the tone plays.
  2. Step 2: Analyze noTone() and second delay()

    The noTone(9); stops the sound on pin 9. The following delay(500); pauses for another 500 ms with no sound.
  3. Final Answer:

    A 1000 Hz tone plays for 500 ms, then stops -> Option B
  4. Quick Check:

    tone + delay + noTone = sound stops after 500 ms [OK]
Hint: noTone(pin) stops sound immediately after delay [OK]
Common Mistakes:
  • Assuming tone stops automatically after delay
  • Thinking noTone restarts sound
  • Ignoring delay effects
4. Identify the error in this Arduino code snippet:
tone(7, 500);
noTone();
delay(1000);
medium
A. noTone() is missing the pin number argument
B. tone() frequency 500 is invalid
C. delay() cannot be used after noTone()
D. tone() must be called after noTone()

Solution

  1. Step 1: Check noTone() usage

    The function noTone() requires the pin number to specify which pin to stop sound on. Here, it is called without any argument, which is incorrect.
  2. Step 2: Verify other function calls

    The tone(7, 500); is valid, and delay(1000); is allowed after noTone(). The error is only the missing pin argument in noTone().
  3. Final Answer:

    noTone() is missing the pin number argument -> Option A
  4. Quick Check:

    noTone() needs pin argument = C [OK]
Hint: Always pass pin number to noTone() [OK]
Common Mistakes:
  • Calling noTone() without pin
  • Thinking delay() is disallowed after noTone()
  • Misunderstanding tone() frequency limits
5. You want to play a 440 Hz tone on pin 6 for 2 seconds, then stop the sound immediately. Which code snippet correctly achieves this?
hard
A. tone(6, 440); delay(2000); noTone(6);
B. noTone(6); tone(6, 440); delay(2000);
C. tone(6, 440); noTone(6); delay(2000);
D. tone(6, 440, 2000); noTone(6);

Solution

  1. Step 1: Understand tone() with duration

    tone(6, 440, 2000); plays tone for 2 seconds automatically, so calling noTone(6); immediately after stops it early, which is unnecessary.
  2. Step 2: Analyze each option's order

    tone(6, 440); delay(2000); noTone(6); plays tone on pin 6 at 440 Hz, waits 2 seconds, then stops the tone with noTone(6);. This correctly plays sound for 2 seconds then stops.
  3. Step 3: Check incorrect options

    noTone(6); tone(6, 440); delay(2000); stops tone before playing it. tone(6, 440); noTone(6); delay(2000); stops tone immediately after starting, so no sound lasts. tone(6, 440, 2000); noTone(6); stops tone immediately after starting with duration, which is redundant.
  4. Final Answer:

    tone(6, 440); delay(2000); noTone(6); -> Option A
  5. Quick Check:

    Play tone, delay, then noTone = D [OK]
Hint: Play tone, delay for duration, then call noTone(pin) [OK]
Common Mistakes:
  • Calling noTone() before delay
  • Stopping tone immediately after starting
  • Using tone() duration with noTone() redundantly
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