Arduino Tone Library - Arduino

What is Arduino Tone Library?

In this chapter, we can use the Arduino Tone Library. it is nothing but an Arduino Library, which produces square-wave of a specified frequency (and 50% duty cycle) on any Arduino pin. A duration can optionally be specified, otherwise the wave continues until the stop() function is called. The pin can be connected to a piezo buzzer or a speaker to play the tones.

Warning − Do not connect the pin directly to any audio input. The voltage is considerably higher than the standard line level voltages, and can damage sound card inputs, etc. you can use a voltage divider to bring the voltage down

Components Required

You will need the following components −

  • 1 × 8-ohm speaker
  • 1 × 1k resistor
  • 1 × Arduino UNO board


Follow the circuit diagram and make the connections as shown in the image given below.

Arduino - Tone Library


Open the Arduino IDE software on your computer. Coding in the Arduino language will control your circuit. Open a new sketch File by clicking New.

Arduino - Tone Library

To make the pitches.h file, either click the button just below the serial monitor icon and choose "New Tab", or use Ctrl+Shift+N.

Arduino - Tone Library

Then paste the following code –

Save the above given code as pitches.h

Arduino Code

Code to Note

The code uses an extra file, pitches.h. This file contains all the pitch values for typical notes. For example, NOTE_C4 is middle C. NOTE_FS4 is F sharp, and so forth. This note table was originally written by Brett Hagman, on whose work the tone() command was based. You may find it useful whenever you want to make musical notes.


You will hear musical notes saved in the pitches.h. file.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

Arduino Topics