To convert MIDI files into Arduino sketches

The intention of this experiment to play MIDI tones by using Arduino. This is very easy with some resistors and one speaker.

The components which used are:

1. Arduino UNO

2. Three 470 Ohm Resistors

3. one speaker/buzzer


First thing we need to take some midi sound files .eg:  This is James Bond movie tone.Next thing we need to convert it into Arduino Sketch. For that we need one special software called Miditones. Download latest MidiTones .exe file. This is a command line utility. create one folder and copy-paste Miditones.exe and .midi file which we downloaded earlier .

Nextstep is to convert MIDI file to Sketch.Run the below command from DOS prompt. CD to the new directory.


lmiditonesV1.6.exe -t3 Movie_Themes_-_James_Bond


Note that we need to give MIDI file name without .midi extension. the above command will generate Movie_Themes_-_James_Bond.c file on the same directory. Open this file on any texteditor, that will be our Arduino Sketch.


Next part is to install Playtune library to Arduino IDE. For that create a directory “Playtunes” under “C:\Program Files (x86)\Arduino\libraries“. Then download “Playtune.cpp & Playtune.h” and paste it into Playtunes directory.Now your IDE is able to process playtune library.


Next step is to wire the circuit. connect 470 Ohm resistors to 10,11 & 12 pins of Arduino and the other end of resistor connect together . Take one wire from GND , connect to one speaker lead and the other lead connect to resistor .I am not going to show the circuit as this is very simple to wire.


Next part is coding. Open Arduino IDE and paste below code.



#include <Playtune.h>


//copy paste content of converted midi file Movie_Themes_-_James_Bond.c


Playtune pt;

void setup() {
pt.tune_initchan (10);
pt.tune_initchan (11);
pt.tune_initchan (12);

void loop () {
pt.tune_playscore (score); /* start playing */
while (pt.tune_playing) ; /* wait here until playing stops */


replace the second line with output of .c file from miditones and upload to Arduino. That’s it.


Share this Story:
  • facebook
  • twitter
  • gplus

About bentech4u


  1. xargs
    3470 days ago

    Nice to see this. Very useful. All the info in one place

  2. Dedicated server
    2979 days ago

    Is it possible to play midi files with the arduino and a speaker? If so, how would I go about doing it?

  3. bentech4u
    2979 days ago


    yes it’s possible and connection method also i mentioned above.

    connect 470 Ohm resistors to 10,11 & 12 pins of Arduino….

  4. Luis
    2943 days ago

    i already cd to my folder and try to use the command but it says that “lmiditonesV1.6.exe”
    isn’t an internal or external command….what should i do?

  5. Jacob Jarick
    2838 days ago

    Hello, thanks for the guide.

    To ensure this works with Arduino 1.6.X edit playtune.cpp

    to :
    #include “arduino.h”

  6. bentech4u
    2832 days ago


    thanks for your update

  7. bentech4u
    2832 days ago


    please check the programe name you entered

  8. TheUltimateAbsol
    2822 days ago

    I got this error:
    MIDI:7: error: variable ‘score’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’

  9. kjoelby
    2822 days ago

    Sweet, nice simplified instructions, thanks for posting this!
    Author Len Shustek’s github page has compatible vs for Arduino IDE 1.6:

  10. bentech4u
    2821 days ago

    HI kjoelby

    Thanks for your update.


  11. Smithc775
    2583 days ago

    Totally pent subject matter, appreciate it for selective information. kddcbbbdgecaddbg

  12. Braiden
    2501 days ago

    I followed the link you gave @TheUltimateAbsol, and I still can’t figure out how to get it to compile. Please update your guide or leave a reply

  13. Teleputer
    2394 days ago

    Your Technically a System Engineer but your Systematically a technical Engineer =)

  14. praveen kumar r
    2341 days ago

    Can you please guide how to create midi file of my custom mp3 file.I have tried with lot of tools.Can you suggest me few more?

    • david
      1976 days ago

      hi, there is no actual way to do that since a midi file are just note and a mp3 file is audio, i would recommend you check out , there is a huge collection of midis

  15. luis
    1611 days ago

    it’s possible with arduino nano?

  16. Edwardo Annen
    1296 days ago

    I’m still learning from you, but I’m improving myself. I definitely enjoy reading everything that is posted on your site.Keep the stories coming. I enjoyed it!

Leave a comment