Summary of MIDI Note Player using Arduino
This tutorial explains how to send MIDI notes from an Arduino using the serial TX pin at the MIDI standard baud rate (31,250 bps). It covers MIDI byte types (command vs data), wiring a MIDI DIN jack to the Arduino (pin 1 to MIDI pin 5, ground to pin 2, +5V through 220 Ω to pin 4), and provides example code to sequence notes. It lists required hardware and points to further MIDI resources.
Parts used in the MIDI Note Player:
- Arduino Board
- MIDI jack (female)
- 220 ohm resistor
- Hook-up wire
- MIDI enabled device (optional, for testing)
This tutorial shows how to play MIDI notes from an Arduino.
MIDI, the Musical Instrument Digital Interface, is a useful protocol for controlling synthesizers, sequencers, and other musical devices. MIDI devices are generally grouped in to two broad classes: controllers (i.e. devices that generate MIDI signals based on human actions) and synthesizers (including samplers, sequencers, and so forth). The latter take MIDI data in and make sound, light, or some other effect.
MIDI is a serial protocol that operates at 31,250 bits per second. The Arduino’s built-in serial port (all of them on the Mega as well) can send data at that rate.
MIDI bytes are divided into two types: command bytes and data bytes. Command bytes are always 128 or greater, or 0x80 to 0xFF in hexadecimal. Data bytes are always less than 127, or 0x00 to 0x7F in hex. Commands include things such as note on, note off, pitch bend, and so forth. Data bytes include things like the pitch of the note to play, the velocity, or loudness of the note, and amount of pitch bend, and so forth. For more details, see the MIDI specification, or one of the many MIDI Protocol Guides on the Web.
MIDI data is usually notated in hexadecimal because MIDI banks and instruments are grouped in groups of 16.
For more see this introduction to MIDI or this example.
Circuit
All MIDI connectors are female, by definition of the MIDI spec. Here’s how to wire the connector to the Arduino:
- Arduino digital pin 1 connected to MIDI jack pin 5
- MIDI jack pin 2 connected to ground
- MIDI jack pin 4 connected to +5V through 220-ohm resistor
image developed using Fritzing. For more circuit examples, see the Fritzing project page
Schematic
Code
MIDI note player
This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data.
If this circuit is connected to a MIDI synth, it will play
the notes F#-0 (0x1E) to F#-5 (0x5A) in sequence.
Hardware Required
- Arduino Board
- (1) MIDI jack
- (1) 220 ohm resistor
- hook-up wire
- MIDI enabled device (optional, for testing)
- What baud rate does MIDI use?
MIDI operates at 31,250 bits per second. - Which Arduino pin sends MIDI data?
The Arduino serial transmit pin (digital pin 1) is used to send MIDI data. - How are MIDI command and data bytes differentiated?
Command bytes are 128 or greater (0x80–0xFF); data bytes are less than 128 (0x00–0x7F). - How do you wire the MIDI jack to the Arduino?
Connect Arduino digital pin 1 to MIDI jack pin 5, MIDI jack pin 2 to ground, and MIDI jack pin 4 to +5V through a 220 ohm resistor. - Why are MIDI values often shown in hexadecimal?
MIDI banks and instruments are grouped in groups of 16, so hexadecimal notation is common. - What notes does the example sketch play?
The sketch plays notes F#-0 (0x1E) to F#-5 (0x5A) in sequence. - Is a MIDI device required to test the circuit?
A MIDI enabled device is optional but used for testing the output.


