Songs for Arduino

I have recently become very interested in music. Consequently, I started to learn how to read scores. So, I thought that adapting some songs for Arduino would be a good exercise. I wrote a few Arduino sketches, with some details on mind:

  • Sketches should be compatible with all or almost all Arduino boards;
  • No need for installing libraries;
  • Sketches should be easy to understand and modify.

That said, I have only used the tone() function, which is part of the Arduino “language”. The tone() function is capable of generating a single tone, in only one pin at a time. Libraries such as the Tone library allow you to generate more tones, but use specific timers of some microcontrollers, which causes incompatibility with many boards. This means that the sketches here are monophonic, that is, only one note can be played at a time.

Songs

At the moment, the following songs are currently available. Just click the name of the song to view the code.

Movies

Games

Classic

Others

Example

As an example, we will use the theme of the game Tetris (type A).  Simply copy the code into the Arduino IDE and connect a buzzer to pin 11 of your Arduino board, or connect it to any pin and edit the value of the buzzer variable accordingly.

With the piezo connected to the board, simply add the code with the desired song in the IDE and upload it to the Arduino. The tempo variable can be changed to make the music play faster or slower, while the buzzer variable contains the number of the pin to which the piezo is connected. The melody vector contains each note of the song followed by their duration.

 

After uploading the sketch, the Arduino will play the song. The setup() code can be moved to the loop() if the music is to be repeated.

 

That’s it for now.  Thanks for reading, see you next post o/

Robson Couto

Recetnly graduated electrical engineer. I enjoy devoting my time to learning about computers, electronics, programming and reverse engineering. My projects are documented in this blog when possible. I am currently looking for a job

One thought to “Songs for Arduino”

Leave a Reply

Your email address will not be published. Required fields are marked *