Main Content


Play tone on piezo speaker using digital pin



playTone(a,pin,frequency,duration) plays a tone on a piezo speaker attached to the digital pin on Arduino® hardware at the specified pin and frequency for the specified duration.


collapse all

Play a tone connected to digital pin 5 on the Arduino hardware for 10 seconds at 2400Hz.

a = arduino();

Input Arguments

collapse all

Arduino hardware connection created using arduino, specified as an object.

Digital pin number on the physical hardware, specified as a character vector.

Frequency of tone to be played, specified as a number between the frequency range 0 and 32767Hz.

Duration of tone to be played specified as a number, which represents the number of seconds. Valid values are between 0 and 60.


This function is not supported on the Arduino Due boards.

See Also

Introduced in R2014b