Sustain via midi

I've never done any MIDI serial style like Tom's sketch, I've always used the MIDI library. And I've always either used a MIDI shield or built my own MIDI I/O hardware.

Debugging could be difficult because MIDIOX might clean up some slop in the background that you're unaware of, and sends properly formatted MIDI to the Korg to make it work. Unless you wrote MidiOX, you have no idea what it's doing to help out.

Personally, I'd scrap whatever you're doing, build a proper balanced MIDI OUT port, connect that to the Korg with a MIDI cable, use the MIDI Library with the MIDI_BASIC_IO and get it working. That shouldn't take more than about 5 minutes of your time.

In regards to MIDI I/O, if you're building a one way controller you don't need a MIDI IN. I.e. a typical open loop system. In an open loop system you have no idea if the MIDI actually did anything or not because it's a dumb controller and receives no feedback from the host. An open loop system doesn't even know if it's connected to a host. Really.

I build closed loop MIDI controllers. When I make a change on the Arduino, the host it's connected to will reflect that change and I can act on it accordingly (change my display, light up an LED, send more commands, etc). That's why I build MIDI IN ports.

As for the Opto on the MIDI IN, well, 5 seconds in Google would get you to the MIDI ORG electrical specification page and all is made abundantly clear:

And yes, you'll see many "other" ways of doing it (I call it fudging) by guys who think they know better. But my gear is valuable to me so I avoid ground loops and protect it with a simple Opto.