Arduino MIDI device issue

I made a simple MIDI controller. I used 5 push buttons. I code it to play a note when pushing the button and stop the note when releasing the button. I selected 5 notes for 5 push button. But when it testing when I m pressing the button 3 notes are playing in the Ableton live. From that 3 notes one of them is the note i added in the code and others are unknown. For all the buttons unknown notes are same

this is my code

int noteON = 144;//144 = 10010000 in binary, note on command
int noteOFF = 128;//128 = 10000000 in binary, note off command

int but1=2;
int but2=3;
int but3=4;
int but4=5;
int but5=6;
int s1;
int s2;
int s3;
int s4;
int s5;
void setup() {
// put your setup code here, to run once:
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(5,INPUT);
pinMode(6,INPUT);
Serial.begin(115200);
s1=0;
s2=0;
s3=0;
s4=0;
s5=0;
}

void loop() {
// put your main code here, to run repeatedly:
int b1=digitalRead(but1);
int b2=digitalRead(but2);
int b3=digitalRead(but3);
int b4=digitalRead(but4);
int b5=digitalRead(but5);
//Serial.println(b1);
if(b1!=s1){
if(b1==1){
MIDImessage(noteON,36,127);
Serial.println("ON");
}
else{
MIDImessage(noteOFF,36,127);
Serial.println("Off");
}

s1=b1;
}

if(b2!=s2){
if(b2==1){
MIDImessage(noteON,37,127);
Serial.println("ON");
}
else{
MIDImessage(noteOFF,37,127);
Serial.println("Off");
}

s2=b2;
}
if(b3!=s3){
if(b3==1){
MIDImessage(noteON,38,127);
Serial.println("ON");
}
else{
MIDImessage(noteOFF,38,127);
Serial.println("Off");
}

s3=b3;
}

if(b4!=s4){
if(b4==1){
MIDImessage(noteON,39,127);
Serial.println("ON");
}
else{
MIDImessage(noteOFF,39,127);
Serial.println("Off");
}

s4=b4;
}
if(b5!=s5){
if(b5==1){
MIDImessage(noteON,40,127);
Serial.println("ON");
}
else{
MIDImessage(noteOFF,40,127);
Serial.println("Off");
}

s5=b5;
}
//delay(100);
}

void MIDImessage(int command, int MIDInote, int MIDIvelocity) {
Serial.write(command);//send note on or note off command
Serial.write(MIDInote);//send pitch data
Serial.write(MIDIvelocity);//send velocity data
//delay(1000);
}

Your post was MOVED to its current location as it is more suitable.

Please post you sketch and a schematic following the advice in given in the link below. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

You are using 'Serial' to send Midi Messages, that means you can not use it for anything else

Serial.println("Off");

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.