At this point we are ready to implement MIDI thus making our Motorized Fader a complete Surface Controller.
We will be able to control volume of any channel of the virtual Mixer of a DAW.
Thanks to Cody Hazelwood for implementing the code of the first Bank of Mackie HUI Protocol for a motorized fader and two buttons.
To accomplish this we will need:
-Two Female 5-pin DIN standard MIDI connectors.
-An Optocoupler.
-One Diode.
-Two 220 Ohm Resistors.
-One 270 Ohm Resistor.
-Two 47 Ohm Resistors.
-Two Push-buttons.
So let’s see the Original MIDI Specifications: 
We have there three MIDI circuits we can implement: MIDI IN, MIDI OUT, and MIDI THRU. This last is optional and we will not implement it because it has no sense in our project.
Let’s begin with the MIDI output circuit: this is the circuit featured in https://www.arduino.cc/en/Tutorial/Midi.
You may find this image useful:

Once done this we can connect a MIDI cable from the MIDI Output of our circuit to the MIDI Input of our Audio/MIDI interface.
Now it is useful to install a tool which allows us monitoring incoming MIDI messages such as MIDI-OX (http://www.midiox.com).
Next thing to do in MIDI-OX is enable MIDI Input and Output ports in Options->MIDI Devices.
Some interfaces have an internal loop between MIDI Input and Output ports by default, we can disconnect this loop in MIDI-OX -> View -> Port Routings.
Now we are ready to test our MIDI Output circuit: open the Arduino IDE and load this program extracted form the Arduino MIDI tutorial posted above:
You should be able to see the MIDI messages corresponding to the notes being played in the Input Monitor of MIDI-OX.
If it is all good now let’s implement the MIDI Input circuit:
The reference design above specifies the long obsolete Sharp PC-900; modern designs frequently use the 6N138.

A common 1N4148 diode can also replace the 1N914.
Now we are ready to test the MIDI In part of our circuit:
Copy this program into the Arduino IDE (from http://www.hispasonic.com/tutoriales/bricolaje-midi-arduino/38463):
This program reads incoming MIDI messages and if the message is a NoteOn corresponding to a C3 note in channel 1, the led integrated in pin 13 of Arduino lights for one second.
It is very important to disconnect pins 0 (RX) and 1 (TX) of Arduino while loading the program to the board because the programming is going through the serial port itself connected to the USB, otherwise we will get errors and the program will not load.
Finally we can send MIDI messages from MIDI-OX itself: Actions->Keyboard and our computer keyboard will work as a MIDI Keyboard.
Let’s press letter Q, which corresponds to C3, and see if the Arduino led lights.
Now we only have to add the two push buttons like this:

We use here the two 47 Ohm resistors (one for each button) as Pull Down Resistors.
We have to connect the push buttons to Digital pins 2 and 3, because the code uses interrupt function triggered by the push buttons to change channels, which is only available in those pins.
Finally we can load the code to make our circuit a full Surface Controller!
As explained above we used Cody Hazelwood code, but we had to adapt it because the library dependencies had updated their API since 2012, and the original code was broken.
One more thing, once in the DAW selecting Mackie HUI in Surface Controller section was not working but selecting Mackie Control did the trick, try between these two!
Download the code and final schematic here:



