The tone() function generates a square wave of a specified frequency on a pin, which can be used to play sounds like beeps or tones.
Click to reveal answer
beginner
What are the basic parameters of the tone() function?
The basic parameters are: pin (the output pin), frequency (in Hertz), and optionally duration (how long to play the tone in milliseconds).
Click to reveal answer
beginner
How do you stop a tone generated by tone()?
Use the noTone(pin) function to stop the tone on the specified pin.
Click to reveal answer
intermediate
Can tone() play multiple tones on different pins at the same time?
No, Arduino can only generate one tone at a time. Calling tone() on a new pin stops the previous tone.
Click to reveal answer
beginner
Write a simple Arduino code snippet to play a 440 Hz tone for 1 second on pin 8.
void setup() {
tone(8, 440, 1000); // Play 440 Hz tone on pin 8 for 1000 ms
}
void loop() {
// Nothing here
}
Click to reveal answer
What does the tone() function generate on an Arduino pin?
AA PWM signal with variable duty cycle
BA square wave of a specific frequency
CA constant voltage
DAn analog voltage
✗ Incorrect
The tone() function generates a square wave at the frequency you specify.
Which parameter is NOT part of the tone() function?
AVolume level
BFrequency in Hertz
CDuration in milliseconds
DPin number
✗ Incorrect
The tone() function does not control volume; it only controls frequency and duration.
How do you stop a tone playing on a pin?
ACall <code>noTone(pin)</code>
BCall <code>stopTone(pin)</code>
CCall <code>tone(pin, 0)</code>
DDisconnect the pin
✗ Incorrect
The noTone(pin) function stops the tone on the specified pin.
What happens if you call tone() on a new pin while a tone is already playing?
ABoth tones play simultaneously
BArduino crashes
CThe new tone is ignored
DThe new tone replaces the old one
✗ Incorrect
Arduino can only play one tone at a time; the new call stops the previous tone.
Which frequency corresponds to the musical note A4, often used in tone examples?
A220 Hz
B330 Hz
C440 Hz
D880 Hz
✗ Incorrect
440 Hz is the standard frequency for the musical note A4.
Explain how to use the tone() function to generate a sound on an Arduino pin.
Think about what parameters you need and how to stop the sound.
You got /4 concepts.
Describe the limitations of the tone() function when playing multiple sounds.
Consider what happens if you try to play two tones at once.
You got /3 concepts.
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
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.
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.
Final Answer:
Generates a sound of a specific frequency on a pin -> Option A
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
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);.
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.
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
Step 1: Analyze tone() with duration
The tone(9, 440, 1000); plays a 440 Hz tone on pin 9 for 1000 milliseconds (1 second).
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).
Final Answer:
Pin 9 outputs a 440 Hz tone for 1 second, then stops -> Option C
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:
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
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.
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.
Final Answer:
Calling tone() inside loop() with duration causes overlapping tones -> Option B
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?