How do I properly receive MIDI with Arduino, with 6n138? UPDATE : I still can't receive MIDI as of 2019/07/01. 

Here goes so far : I'm trying to follow this schematics from instructables, using 6N138. To make it easier, I'm going to copy his schematics. 


===================================

I'm using Arduino Mega. I tried to find specific topic about this and can't find any. 

The target is actually send and receive MIDI, then replace the whole Arduino Mega to ESP8266 (probably the ESP-01, or Wemos D1), but I'm afraid it is too specific. 

Here's the code so far on PasteBin

Here's my work so far. 



The diodes were replaced with LED, because I don't have one Original guide here.
But that schematics on that thread also didn't work for some reason.
Most start at the midi site at playground.arduino.cc.  But there are numerous web sites across the Internet.  It is important to understand that the MIDI interface uses a current loop to send and receive data.  While the Arduino normally uses voltage levels to communicate.  As such, an electronic interface needs to be built or bought to convert between these two types of signals.  Some interface designs are simple and limited.  Others are complex and robust.