How to Make Midi Keyboard Using Arduino

Introduction: How to Make Midi Keyboard Using Arduino

This instruction video is made for those musician and music producer who have basic knowledge of electronics. But can't afford to purchase expensive one. We spend a huge time and energy for building this project. If this video helps those person then our Mission will be successful. From hardware to software. Installation and connection everything explained in detail.

Step 1: COMPONENTS REQUIRED

this is a complete tutorial to convert a piano to midi keyboard using arduino. you dont need to buy expensive one for your home studio setup. it is a complete guide of making midi keyboard and connecting it to your computer and DAW.

Components needed :

Arduino uno,

74hc595 shift register,

coloured cable,

2 breadboard,

breadboard jumper,

1 vero board,

male pin header

Arduino code link Arduino circuit link Key matrix link http://www.codetinkerhack.com/2012/11/how-to-turn...

Hairlessmidi link http://www.codetinkerhack.com/2012/11/how-to-turn...

Loopmidi link http://www.codetinkerhack.com/2012/11/how-to-turn...

Arduino ide - http://www.codetinkerhack.com/2012/11/how-to-turn...

Step 2: Unscrew the Back Cabinet

first unscrew the back cabinet. you will be able to find a speaker. remove it as it is of no use now. midi keyboard only send midi signals not hearable audio signals to produce sound using inbuilt speaker.

remove the main circuit board as we are going to build our very own circuit board using arduino.

WE ONLY REQUIRE THE KEY SWITCH CIRCUIT BOARD FOR OUR PROJECT.

Step 3: FIGURING OUT SCAN MATRIX

desolder 12 pin ribbon cable from main board. we have 12 pin ribbon cable and 32 key switch. here scan matrix is used to deliver 32 keys sound using only 12 pin cable.otherwise we require 32 cables for 32 note sound.

lets have a close look at the pcb key switch. we can see that combinations of 8 keys are connected serially and after that there is a split. we can assume that our key matrix to be 8*4.

Step 4:

select the multimeter to continuity range. connect black probe to pin 1 and red probe to pin 12 of the ribbon cable and hit all 32 buttons of piano switch. we have to find out continuity reading at any one of the key switch. after hitting all 32 buttons we didn't get any reading in multimeter. now i am shifting towards left one to pin 11. again hit all 32 keys. in this time we didn't get any reading. am\nd the process continues until we get any continuity reading. after connecting red probe to each of the pin of ribbon cable except pin 1( black probe is connected to pin 1) and hitting all the buttons we didn't get any desired outcome. this is beacause diodes are provided in the circuit which allows current to move only one direction.

now i am changing the position of probes. red to pin 1 and black to pin 12. and same process continues. when red probe is connected to pin 1 and black probe is connected to pin 9 we get continuity reading by hitting key 25 of the piano switch. which means when key 25 is pressed pin 1 and pin 9 are shorted. current flows from pin 1 to pin 9 via key switch 25. by following the same process we can figure out combinations of pins and key pressed accordingly. and figure out the scan matrix.

Step 5: Combinations of Pins and Key Pressed Accordingly

Step 6:

from the pcb we can see that pin 1 goes to a diode and then reached pin 6. when key switch 1 is pressed pin 1 and pin 6 shorted. signal from pin 1 reached to pin 6 via key switch 1. here diodes are provided to eliminate note ghosting.

Step 7:

so we can conclude that we have 8 output and 6 input.

Step 8: Customise Circuit Board in Breadboard

here i am using 74hc595 shift register. we dont have enough digital pin in arduino uno so we connect 8 output pin of ribbon cable to the shift register. here 8 output from ribbon cable minimise to 3 output via shift register named as clock, latch and data . only 3 digital pin of arduino is required inspite of 8. connect everything using this arduino diagram.

Step 9: Connection of Pins of 74hc595 Shift Register

74hc595

pin 16 to VCC ( 5 volt+)

15 to ribbon pin 12

14 to digital pin 11 of arduino

13 to ground

12 to digital pin 10 of arduino

11 to digital pin 9 of arduino

10 toVCC

8 to ground

7 to ribbon cable pin 11

6 to ribbon cable pin 10

5 to ribbon cable pin 5

4 to ribbon pin 4

3 to ribbon pin 3

2 to ribbon pin 2

1 to ribbon pin 1

Step 10:

in this project i am not gonna use 5 pin DIN socket or MIDI socket. hence connecting Tx pin from arduino is not required as per diagram.

Step 11:

now connect input pin 6,7,8,9 of the ribbon cable( green colour) to the arduino digital pin 8,7,6,5 and connect them to ground using 10 k resistor.

Step 12: Arduino Code

// Rows are connected to

const int row1 = 5;

const int row2 = 6;

const int row3 = 7;

const int row4 = 8;

// The 74HC595 uses a serial communication

// link which has three pins

const int clock = 9;

const int latch = 10;

const int data = 11;

uint8_t keyToMidiMap[32];

boolean keyPressed[32];

int noteVelocity = 127;

// use prepared bit vectors instead of shifting bit left everytime

int bits[] = { B00000001, B00000010, B00000100, B00001000, B00010000, B00100000, B01000000, B10000000 };

// 74HC595 shift to next column

void scanColumn(int value) {

digitalWrite(latch, LOW); //Pulls the chips latch low

shiftOut(data, clock, MSBFIRST, value); //Shifts out the 8 bits to the shift register

digitalWrite(latch, HIGH); //Pulls the latch high displaying the data }

void setup() {

// Map scan matrix buttons/keys to actual Midi note number. Lowest num 41 corresponds to F MIDI note. keyToMidiMap[0] = 48;

keyToMidiMap[1] = 41;

keyToMidiMap[2] = 42;

keyToMidiMap[3] = 43;

keyToMidiMap[4] = 44;

keyToMidiMap[5] = 45;

keyToMidiMap[6] = 46;

keyToMidiMap[7] = 47;

keyToMidiMap[8] = 56;

keyToMidiMap[1 + 8] = 49;

keyToMidiMap[2 + 8] = 50;

keyToMidiMap[3 + 8] = 51;

keyToMidiMap[4 + 8] = 52;

keyToMidiMap[5 + 8] = 53;

keyToMidiMap[6 + 8] = 54;

keyToMidiMap[7 + 8] = 55;

keyToMidiMap[16] = 64;

keyToMidiMap[1 + 16] = 57;

keyToMidiMap[2 + 16] = 58;

keyToMidiMap[3 + 16] = 59;

keyToMidiMap[4 + 16] = 60;

keyToMidiMap[5 + 16] = 61;

keyToMidiMap[6 + 16] = 62;

keyToMidiMap[7 + 16] = 63;

keyToMidiMap[24] = 72;

keyToMidiMap[1 + 24] = 65;

keyToMidiMap[2 + 24] = 66;

keyToMidiMap[3 + 24] = 67;

keyToMidiMap[4 + 24] = 68;

keyToMidiMap[5 + 24] = 69;

keyToMidiMap[6 + 24] = 70;

keyToMidiMap[7 + 24] = 71;

// setup pins output/input mode

pinMode(data, OUTPUT);

pinMode(clock, OUTPUT);

pinMode(latch, OUTPUT);

pinMode(row1, INPUT);

pinMode(row2, INPUT);

pinMode(row3, INPUT);

pinMode(row4, INPUT);

Serial.begin(38400);

delay(1000);

}

void loop() {

for (int col = 0; col < 8; col++) {

// shift scan matrix to following column

scanColumn(bits[col]);

// check if any keys were pressed - rows will have HIGH output in this case corresponding

int groupValue1 = digitalRead(row1);

int groupValue2 = digitalRead(row2);

int groupValue3 = digitalRead(row3);

int groupValue4 = digitalRead(row4);

// process if any combination of keys pressed if (groupValue1 != 0 || groupValue2 != 0 || groupValue3 != 0 || groupValue4 != 0) {

if (groupValue1 != 0 && !keyPressed[col]) { keyPressed[col] = true; noteOn(0x91, keyToMidiMap[col], noteVelocity); }

if (groupValue2 != 0 && !keyPressed[col + 8]) { keyPressed[col + 8] = true; noteOn(0x91, keyToMidiMap[col + 8], noteVelocity); }

if (groupValue3 != 0 && !keyPressed[col + 16]) { keyPressed[col + 16] = true; noteOn(0x91, keyToMidiMap[col + 16], noteVelocity); }

if (groupValue4 != 0 && !keyPressed[col + 24]) { keyPressed[col + 24] = true; noteOn(0x91, keyToMidiMap[col + 24], noteVelocity); }

}

// process if any combination of keys released if (groupValue1 == 0 && keyPressed[col]) { keyPressed[col] = false; noteOn(0x91, keyToMidiMap[col], 0); }

if (groupValue2 == 0 && keyPressed[col + 8]) { keyPressed[col + 8] = false; noteOn(0x91, keyToMidiMap[col + 8], 0); }

if (groupValue3 == 0 && keyPressed[col + 16]) { keyPressed[col + 16] = false; noteOn(0x91, keyToMidiMap[col + 16], 0); }

if (groupValue4 == 0 && keyPressed[col + 24]) { keyPressed[col + 24] = false; noteOn(0x91, keyToMidiMap[col + 24], 0); }

}

}

void noteOn(int cmd, int pitch, int velocity) { Serial.write(cmd); Serial.write(pitch); Serial.write(velocity); }

Step 13: Midi Note Table

Step 14:

serial.begin( 38400) is actually the baud rate of the software programme hairless midi. go to preference of hairless midi and note down the baud rate and put it on the bracket portion of arduino code. upload arduino code.

Step 15:

transfer everything from bread board to vero board. this is the final look after placing everything inside keyboad.

Step 16: Connecting Midi Keyboard to Pc

connect midi keyboard to pc using usb a to usb b cable. install and open loop midi port software which works as a virtual midi port. open hairless midi. now fire up your daw and enjoy playing different virtual instruments. if you find this video helpfull please feel free to post your thoughtfull comments.

(ONE IMPORTANT THING I FORGOT TO MENTION IN THE VIDEO THAT I HAVE CHANGED THE POLARITY OF EACH DIODE OF THE KEY SWITCH PCB BOARD. BECAUSE DIODES PREVENTING THE DIRECTION OF CURRENT TO FLOW FROM SHIFT REGISTER TO ARDUINO INPUT PIN VIA KEYBOARD SWITCH)

Be the First to Share

    Recommendations

    • Lamps Challenge

      Lamps Challenge
    • Puzzles Challenge

      Puzzles Challenge
    • CNC and 3D Printing Contest

      CNC and 3D Printing Contest

    Comments

    0
    unyimedavid
    unyimedavid

    Question 1 year ago on Step 2

    I want to convert yamaha psr-240 keyboard with 61 keys to midi keyboard. What changes can I make using your above keys... if pleased to reach me on whatsapp plus2348127932544 thanks