মূল বিষয়বস্তুতে যান
Learn/Sound & motion/Playing tones
Sound & motion · Lesson
8 min read

Playing tones

tone() and noTone(), notes and rhythms with arrays.

What You Will Learn

  • Play a frequency with tone()
  • Store a melody in arrays

A passive piezo buzzer clicks each time the voltage changes. tone(pin, frequency) toggles the pin at that frequency, producing a note. Middle C is 262 Hz; A4 is 440 Hz.

Buzzer melodyarduino-uno
Open in Lab
UNOATmega328P: The 8-bit AVR microcontroller that runs your sketch (16 MHz, 32 KB flash, 2 KB RAM).ATmega328PUSB-B: USB connection for uploading sketches and for the Serial Monitor. Also powers the board (5 V).DC jack: Barrel jack for 7–12 V from a battery pack or adapter (centre positive).ATmega16U2: Converts USB to serial for uploads and Serial.print().RESET: Restarts your sketch from the beginning (setup() runs again).L (D13): Built-in LED connected to pin 13 (LED_BUILTIN).ON: Power indicator.5 V regulator: Turns 7–12 V from VIN/jack into a steady 5 V.16 MHz: Clock source: the microcontroller runs 16 million cycles per second.ICSP: In-circuit programming header (SPI). Used to burn a bootloader; not needed for normal uploads.
Note: Turn on sound in the Lab toolbar to hear it. Edit the notes array to write your own tune.
The Uno can play only one tone() at a time, and tone() interferes with PWM on pins 3 and 11.

Check Your Understanding

Test what you learned in this lesson

1What does tone(8, 440, 200) do?

Finished this lesson?

Keep track of your progress as you learn