arduinospeaker

Arduino Mario Theme Song

Playing sounds on Arduino

The Tone Library allows the user to play different tunes through the Arduino. This library provides functions which specify the pin, tone and duration for the output. This makes it extremely easy to play any audio output on a single or multiple pins through the use of a speaker or a simple buzzer.

Required Hardware

Playing a tune is quite simple. Hooking up a buzzer through a current limiting resistor will allow you to get started right away. That being said, if you plan on using a speaker, you want to make sure that the current drawn is within your boards specifications. The solution is driving this speaker with a transistor. See an example below for how you can wire the speaker to an Arduino board:
arduino audio

Playing the Mario Theme Song

Once you have the Tone Library working and an output device connected to one of your pins, you have the capability of playing multiple different tunes. One of the most iconic tunes of the 8-bit world, is the Mario theme Song which can be very easily played with this setup. At this point, simply copy and paste the code below in order to play your favourite childhood theme song.

Mario Theme Song Code


#include
Tone tone1;

void setup()
{
tone1.begin(11);//Playback on Pin 11, change to whatever you may need
}

void loop()
{
tone1.play(660,100);
delay(75);tone1.play(660,100);
delay(150);tone1.play(660,100);
delay(150);tone1.play(510,100);
delay(50);tone1.play(660,100);
delay(150);tone1.play(770,100);
delay(275);tone1.play(380,100);
delay(287);tone1.play(510,100);
delay(225);tone1.play(380,100);
delay(200);tone1.play(320,100);
delay(250);tone1.play(440,100);
delay(150);tone1.play(480,80);
delay(165);tone1.play(450,100);
delay(75);tone1.play(430,100);
delay(150);tone1.play(380,100);
delay(100);tone1.play(660,80);
delay(100);tone1.play(760,50);
delay(75);tone1.play(860,100);
delay(150);tone1.play(700,80);
delay(75);tone1.play(760,50);
delay(175);tone1.play(660,80);
delay(150);tone1.play(520,80);
delay(75);tone1.play(580,80);
delay(75);tone1.play(480,80);
delay(175);tone1.play(510,100);
delay(275);tone1.play(380,100);
delay(200);tone1.play(320,100);
delay(250);tone1.play(440,100);
delay(150);tone1.play(480,80);
delay(165);tone1.play(450,100);
delay(75);tone1.play(430,100);
delay(150);tone1.play(380,100);
delay(100);tone1.play(660,80);
delay(100);tone1.play(760,50);
delay(75);tone1.play(860,100);
delay(150);tone1.play(700,80);
delay(75);tone1.play(760,50);
delay(175);tone1.play(660,80);
delay(150);tone1.play(520,80);
delay(75);tone1.play(580,80);
delay(75);tone1.play(480,80);
delay(250);tone1.play(500,100);
delay(150);tone1.play(760,100);
delay(50);tone1.play(720,100);
delay(75);tone1.play(680,100);
delay(75);tone1.play(620,150);
delay(150);tone1.play(650,150);
delay(150);tone1.play(380,100);
delay(75);tone1.play(430,100);
delay(75);tone1.play(500,100);
delay(150);tone1.play(430,100);
delay(75);tone1.play(500,100);
delay(50);tone1.play(570,100);
delay(110);tone1.play(500,100);
delay(150);tone1.play(760,100);
delay(50);tone1.play(720,100);
delay(75);tone1.play(680,100);
delay(75);tone1.play(620,150);
delay(150);tone1.play(650,200);
delay(150);tone1.play(1020,80);
delay(150);tone1.play(1020,80);
delay(75);tone1.play(1020,80);
delay(150);tone1.play(380,100);
delay(150);tone1.play(500,100);
delay(150);tone1.play(760,100);
delay(50);tone1.play(720,100);
delay(75);tone1.play(680,100);
delay(75);tone1.play(620,150);
delay(150);tone1.play(650,150);
delay(150);tone1.play(380,100);
delay(75);tone1.play(430,100);
delay(75);tone1.play(500,100);
delay(150);tone1.play(430,100);
delay(75);tone1.play(500,100);
delay(50);tone1.play(570,100);
delay(110);tone1.play(500,100);
delay(150);tone1.play(760,100);
delay(50);tone1.play(720,100);
delay(75);tone1.play(680,100);
delay(75);tone1.play(620,150);
delay(150);tone1.play(650,200);
delay(150);tone1.play(1020,80);
delay(150);tone1.play(1020,80);
delay(75);tone1.play(1020,80);
delay(150);tone1.play(380,100);
delay(150);tone1.play(500,100);
delay(150);tone1.play(760,100);
delay(50);tone1.play(720,100);
delay(75);tone1.play(680,100);
delay(75);tone1.play(620,150);
delay(150);tone1.play(650,150);
delay(150);tone1.play(380,100);
delay(75);tone1.play(430,100);
delay(75);tone1.play(500,100);
delay(150);tone1.play(430,100);
delay(75);tone1.play(500,100);
delay(50);tone1.play(570,100);
delay(210);tone1.play(585,100);
delay(275);tone1.play(550,100);
delay(210);tone1.play(500,100);
delay(180);tone1.play(380,100);
delay(150);tone1.play(500,100);
delay(150);tone1.play(500,100);
delay(75);tone1.play(500,100);
delay(150);tone1.play(500,60);
delay(75);tone1.play(500,80);
delay(150);tone1.play(500,60);
delay(175);tone1.play(500,80);
delay(75);tone1.play(580,80);
delay(175);tone1.play(660,80);
delay(75);tone1.play(500,80);
delay(150);tone1.play(430,80);
delay(75);tone1.play(380,80);
delay(300);tone1.play(500,60);
delay(75);tone1.play(500,80);
delay(150);tone1.play(500,60);
delay(175);tone1.play(500,80);
delay(75);tone1.play(580,80);
delay(75);tone1.play(660,80);
delay(225);tone1.play(870,80);
delay(162);tone1.play(760,80);
delay(300);tone1.play(500,60);
delay(75);tone1.play(500,80);
delay(150);tone1.play(500,60);
delay(175);tone1.play(500,80);
delay(75);tone1.play(580,80);
delay(175);tone1.play(660,80);
delay(75);tone1.play(500,80);
delay(150);tone1.play(430,80);
delay(75);tone1.play(380,80);
delay(300);tone1.play(660,100);
delay(75);tone1.play(660,100);
delay(150);tone1.play(660,100);
delay(150);tone1.play(510,100);
delay(50);tone1.play(660,100);
delay(150);tone1.play(770,100);
delay(225);tone1.play(380,100);
//tells the user it is over and delays it a little before going to the top again
delay(1000);
tone1.play(440,200);
delay(200);
delay(200);
tone1.play(440,400);
delay(200);
delay(200);
delay(5000);
}

Movind Forward with the Tone

Feel free to experiment with different tones and create your own compositions. Share them through the comments below or by a YouTube video!

Thank you for reading,
– EEEnthusiast