This article explains how to play music using the Arduino microcontroller. Do you remember those musical ringtones from old cell phones, like the Nokia 3310? Well, here you can play the same musical tones using Arduino!

Necessary materials

  1. Arduino UNO
  2. Passive buzzer for Arduino (5V)
  3. Jumpers
  4. breadboard

Circuit

Figure 1 illustrates the circuit assembly diagram for the music project with Arduino. As shown, assembly is relatively simple, requiring only a few basic components. The Arduino board is the brain of the system, responsible for controlling audio generation and reproduction. Connected to the board, a loudspeaker speaker is used to produce the sounds generated by the program. This diagram serves as a useful visual guide to assist in the physical assembly of the circuit, facilitating the process of implementing the music project with Arduino:

Code

You can download the TONE code and library by clicking the link below:

Download: http://bit.ly/2VSIpA3

Details:

The RTTL_sequencia_de_musicas.ino file is the song code, it is necessary to remove the slashes // from the song to be able to compile and play it.

The TONE folder is the library that you need to add to the libraries folder of the Arduino IDE.

The download file is now ready to play the songs in sequence. If you want to change the songs,
do the following:

– Firstly you will need to go to the song code and list the songs you want to play in sequence, for example: song1, song2, song3 and etc…

– Then in void loop(void), at the end of the code, you can increase the sequence of songs by copying and pasting the code as many times as you want,
just changing the number of the “song” constant:

– Code example:

void loop(void)
 
{
 
  play_rtttl(song1);
 
  Serial.println("Done.");
 
  while(0);
 
  delay(1000);
 
 
 
  play_rtttl(song2);
 
  Serial.println("Done.");
 
  while(0);
 
  delay(1000);
 
 
 
  play_rtttl(song3);
 
  Serial.println("Done.");
 
  while(0);
 
  delay(1000);
 
}

Important:

In the project of this article, the Arduino IDE version 1.0.5 was used.

Adding new songs:

You can search for new RTTTL songs on the website indicated below. Just add the Ring Tone RTTTL code within the code provided in this article, just paste the new music line into the list of variables declared “char”, as shown in Figure 2. After that,
add the song inside the void loop exemplified in the previous topic.

Remember to remove the slashes “\” to enable song codes.

Arduino makes it possible to carry out different projects with arduino (projetos com arduino), you can create music and add the code music list to hear them on your buzzer. Another idea you can create is to make a home alarm where upon detecting presence, the Arduino activates the buzzer emitting music to ward off the intruder. Anyway,
There are many ideas for us to do with Arduino!

Watch the example of music playing with Arduino: