When I first started working on MIDI devices, I did what most people do: I searched Google for schematic examples. I found plenty, but after a closer look, I realized I needed to dig deeper to build a truly reliable schematic for the 8X7 and 4X4 amp switchers. In this post, I want to share the practical solutions I’ve found and tested along the way.
Using the 6N138 Optocoupler for MIDI In Schematics
Galvanic isolation is crucial for all MIDI inputs to prevent ground loops. This is achieved with an optocoupler, which isolates the input signal from the digital circuit. It is important to choose a high-speed device to ensure reliable data transfer without skipping bits. For this design, I use the 6N138; it is available in both DIP and SMD packages and, though slightly bulky, it works well.

To protect the LED inside the optocoupler, R1 limits its current, while D1 protects it from excessive forward voltage. MIDI voltage is typically 5 V, though some modern devices operate at 3.3 V. The 220 Ω value for R1 is standard in MIDI designs and corresponds to the resistor values used in typical MIDI Out circuits.
The optocoupler output contains two transistors and one or two resistors. Using 1 kΩ for both R2 and R3 works the best. Actually making the circuit roughly four times faster, and using identical resistor values, reduces the bill of materials. C1 is optional. I use a 100 nF capacitor placed close to the optocoupler, providing local filtering. Finally, the MIDI IN signal is routed to the processor as shown in the schematic above.

The yellow trace shows the input MIDI signal before the optocoupler. The green trace shows the output signal after the optocoupler.
Using the 6N137 Optocoupler for MIDI In Schematics
The 6N138 is a high-speed optocoupler with a logic-level output providing the fastest rising and falling edges compared to the others. Both 6N137 and 6N138 optocouplers are pin-compatible, allowing for easy interchange with only a small modification when using a universal PCB layout.
The 6N137 features a digital output stage that sets it apart from the 6N138. Interestingly, its prices today are relatively similar to the price of the 6N138. The only schematic difference is the absence of one resistor compared to the 6N138 design.
Below is a fully working schematic using the 6N137 optocoupler:

Using the PC817 Optocoupler for MIDI In Schematics
The PC817 optocoupler is definitely too slow for direct MIDI signal transfer. However, by adding a single transistor after it, the switching speed increases dramatically. In fact, the same concept is used in the 6N138 optocoupler, which already includes an internal transistor.
So what makes this design better than the others? The price. It’s always the price. Making something cheaper while keeping it fully functional is the real art of electronics.
Price comparison (for 1000-piece quantities):
PC817S – $0.019
EL3H7 – $0.034
6N138S – $0.24
6N137S – $0.14
A single BC847C transistor costs only $0.004, which is still an order of magnitude cheaper!
The component area on the PCB is smaller. You can even replace the PC817 with an EL3H7 in the small SSOP package if you need to save even more board space. Here you can see the full schematics:

Designing The MIDI Out Schematics
The MIDI Out schematic uses a single transistor buffer, which is both fast and inexpensive. It protects the microprocessor from high static voltages coming through the MIDI cable. I chose the 2N5551 (or MMBT5551 SMD) for its high collector-emitter voltage (Vce) of 160 V.
For EMI filtering, I added two 100 pF capacitors. The 220 Ω resistors limit the current through the optocoupler’s LED from the MIDI In circuit to about 5 mA, while R3 limits the transistor’s base current. Separately, connecting the ground to the middle pin of the DIN5 provides additional shielding for the MIDI cable. Finally, note that this circuit requires the microprocessor signal to be inverted to operate correctly.

It is important to establish a proper ground reference at the node shared by C1, C2, Q1, and the MIDI OUT! You should also place all MIDI Out components next to the DIN connector. If the device uses an earth-connected chassis and the circuit ground is bonded to mains earth, a low-impedance return path must be provided.
In practice, this means using a proper wide PCB trace for that ground part connection or connecting the output ground directly to the solid ground plane. The return currents from all components in this section of the circuit must flow through a low-impedance path to the main ground reference to minimize noise coupling. Do not route this ground through thin PCB traces originating from the microcontroller.
Power over MIDI
One clever design feature of the N-audio amp switchers is the ability to power FX-Loop extensions directly through the MIDI Out connector. While this isn’t part of the official MIDI standard, some designs use pin 3 for +5 V and pin 2 as ground. This allows you to power other MIDI devices without a separate power supply. Even better, once the amp switcher is powered on, the connected FX-Loop turns on automatically.
Summary
I hope my experience with MIDI implementation helps you in your own projects. The schematics shown here are based on a solution I’ve tested in real-world designs, so they can save you quite a bit of trial and error when building your own MIDI interface. If you’d like to learn more, feel free to check out this blog post about MIDI for musicians, where I cover the essentials clearly and practically.
Niki Hristov