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.


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






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.

17 thoughts to “Songs for Arduino”

  1. Oi Robson,

    Fiz a montagem certinha, subi o sketch do mesmo jeito, mas o som não sai no meu buzzer (que é igual o da foto). Eu testei na aula em um buzzer com 3 saídas, onde 1 ia pro pino11, outra no 5v e outra no terra. Como funciona quando o buzzer só tem 2 pinos, que é o caso do meu?

  2. Hi, Thank you for posting. The code does not compile on the Arduino IDE 1.8.10. The variables lt and gt are not declared. I noticed there are also four ‘;’s in some of your for loops.


    1. Hi Robert, dozens of people use this code everyday without problems.
      There seems to a problem with your browser. Are you using a page translator or something similar?
      Have you tried downloading the repository from Github?

Leave a Reply

Your email address will not be published.