tone() function generates a square wave of the specified frequency on a pin, which can be used to emit a tone.
tone() to Play a Melody
The following code was adapted from the Play a Melody using the tone() function Built-In Example tutorial.
Broader Topics Related to Arduino tone() Function
Knowledge about programming Arduino boards