format of midi messages


i am trying to build a midi controller with my arduino to control software. i use to convert the serial messages to midi.
The problem is i don’t know what the format is of the midi messages so that the converter can read it.

This is my code. when i press button 51 it should light up the led and send a midi message.
// set pin numbers:
int buttonPin = 51; // the number of the pushbutton pin
int ledPin = 53; // the number of the LED pin

// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
Serial.print("???"); <----------------------------- what do i need to insert here?

// prints hello with ending line break

else {
// turn LED off:
digitalWrite(ledPin, LOW);


sorry if it is a stupid question. i’m just totally unfamilliar with midi and i just want my arduino to send a single message to the converter so i can let my software react to the push of a button.


Firstly, you need Serial.write(), not Serial.print().


thanks for the quick reply

do i need to send the messages in binary or in decimal?

As you should using Serial.write(), they should be sent as binary.

i still can't manage to send a message

I tried Serial.write(00000100); Serial.write(00000100); Serial.write(00000100);

I tried Serial.write("000001000000010000000100");

how do i need to seperate the midi bytes? i want to send this message 10010010(Chan 3 Note on) 00000101(Note Number 5) 01111111(Note Velocity 127)


sends the decimal number 100. You need the 0b prefix to tell the compiler that you are using binary numbers.


thanks again for all your help says the midi message contains of 3 bytes and the first byte is seperated in an action part and a command part. so i first tried sending 3 bytes Serial.write(B00000100); Serial.write(B00000100); Serial.write(B00000100); (the prefix B should also work right? and i tried splitting the action part and command part Serial.write(B0010); Serial.write(B0010); Serial.write(B00000100); Serial.write(B00000100); but in the conversion software the light still turns red (which means it is reading serial data but it's not midi format.

The 'B' prefix is Arduino specific. If you want to use it, it must be followed by eight binary digits.

Did you read the link I posted. It explains the way the command and channel are merged to a single byte.

Thanks got it working now!!