Problem Controlling Individual Outputs When Receiving Messages

Hello! I am making a circuit of LEDs that respond to MIDI messages using an Arduino Uno. I wish to have each LED correspond to a musical note contained in the MIDI file. Here is the code I am using:

<pre>/*Receive MIDI and check if note = 60
By Amanda Ghassaei
July 2012
<a href="">>

 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.


byte commandByte;
byte noteByte;
byte velocityByte;

byte noteOn = 144;

//light up led at pin 13 when receiving noteON message with note = 60

void setup(){

void checkMIDI(){
    if (Serial.available()){
      commandByte =;//read first byte
      noteByte =;//read next byte
      velocityByte =;//read final byte
      if (commandByte == noteOn){//if note on message
        //check if note == 60 and velocity > 0
        if (noteByte == 60 && velocityByte > 0){
          digitalWrite(13,HIGH);//turn on led
  while (Serial.available() > 2);//when at least three bytes available

void loop(){
  digitalWrite(13,LOW);//turn led off

As you can see, this code is not my own; it was made by Amanda Ghassaei. I am following her instructable starting at this step. In the test code from the instructable (the code above), an LED at pin 13 flashes on and off when the Arduino Uno receives note “60”.

What I want to happen: I want to duplicate this process, so an LED at pin 12 flashes on and off when receiving MIDI note “59”, and an LED at pin 11 flashes on an off when receiving MIDI note “58”, and so on with pins 2-10 and MIDI notes “57-49” in addition to the LED at 13.

What I tried to do: I tried to copy and paste the code below the original code as a test to see if I could get the program to work with one additional LED. In the copied and pasted portion, I changed “if (noteByte == 60 && velocityByte > 0)” (which checks to see if the MIDI note is 60) to “if (noteByte == 59 && velocityByte > 0)” so it would instead check to see if the MIDI note was 60 or 59. I also changed “pinMode(13,OUTPUT); digitalWrite(13,LOW);” and “digitalWrite(13,HIGH);//turn on led” and “digitalWrite(13,LOW);//turn led off” to “pinMode(12 OUTPUT); digitalWrite(12,LOW);” and “digitalWrite(12,HIGH);//turn on led” and “digitalWrite(12,LOW);//turn led off”, which would turn on an LED at pin 12 (if the MIDI note was 59).

What I thought would happen: The Arduino would turn on and off an LED at pin 13 if the MIDI note was “60”, and an LED at pin 12 if the MIDI note was “59”, each LED acting individually from each other.

What actually happened: Only the LED at pin 13 would turn on, and that would only happen if both notes 60 and 59 were sent to the Arduino at the same time. Nothing would happen if I sent only note 59 or 60, meaning neither LED would turn on if I I sent the notes individually.

Essentially, my problem is I can not individually control outputs when MIDI notes are received by the Arduino Uno.

You should post the code that does not work. It is quite poor code to begin with. Look at