Now we are starting to do something useful with the MIDI receiving code from our Simple MIDI Monitor – this project gets it to play a note. It combines the MIDI monitor with the Simple Arduino Music Keyboard but instead of having keys to trigger notes, we are listening for MIDI messages.
- In Arduino Multi MIDI Tone Module I connect a few of these together for some simple polyphony.
- In Arduino Tone Polyphony I start to experiment with true Arduino tone polyphony in a single module.
Warning! I strongly recommend using an old or second hand keyboard for your MIDI experiments. I am not responsible for any damage to expensive instruments!
These are the key Arduino tutorials for the main concepts used in this project:
If you are new to Arduino, see the Getting Started pages.
Parts list
- Arduino Uno
- 8 ohm speaker or old headphone speaker
- 1x 220 resistor
- MIDI Shield or other MIDI input stage (see Arduino MIDI Interfaces)
- Breadboard and jumper wires
The Circuit

If you are using a MIDI shield there isn’t really a circuit as such. The speaker requires a 220Ω resistor between it and the signal line and then a link back to ground. In this demo I used put the resistor in-line between two jumper cables connected to the MIDI shield. Note that my version of the shield has all the I/O pins routed to the back of the board, so I just had to find the hole that linked to pin 12. There is a whole row of GND holes and a separate shorted row of 5V holes. At some point I might solder some headers onto the shield but for now, just poking a jumper wire with a male header pin in the right hole does the job.
Here is a picture of me using the MIDI shield with a speaker, using my Arduino MIDI Touch Piano as the MIDI controller.

The Code
If you’ve been following along from previous projects, you’ll spot that this code is essentially combining several features we’ve already encountered. They key things to note are that I’ve stopped specifying a list of MIDI note codes to recognise. Instead, I list the lowest note to use and then assume that the next few consecutive notes are the ones that we will map to our tone frequency values. It is much quicker to calculate which tone to use based on the numerical MIDI note value this way.
The other bit of programming “magic” used in this code is the use of callbacks from the Arduino MIDI Library. There are two ways to handle MIDI messages coming in – by checking yourself, or by telling the library what to do when it gets a certain type of message. This code is now using the latter method.
In the setup() function there are calls to functions in the library that basically say “when you get a noteOn message, do this, and when you get a noteOff messsage, do that”. It saves having to write code to work it our for yourself.
It is possible to expand this code to cover a much fuller set of notes now. To do that I once again turn to the “pitches.h” file from the toneMelody example.
If you don’t want the full set of notes, then just create your own notes[] list instead, but the provided list should give you almost seven octaves of tones().
Closing Thoughts
It would be nice to build up a set of these modules to give some basic polyphony.
Kevin