When talking MIDI and Arduino, everybody uses the 6N138 opto-isolator, and for good reason. It has a fairly high gain!
Imagine you’re struck by inspiration and you can’t find a 6N138 in your toolbox. Oh no! but you find another opto-isolator and a NPN transistor. You could still make it work!
That high gain is needed because:
- Usually a 470Ω resistor connected to +5V is used to overcome Arduino’s 1kΩ resistors to the USB-to-Serial chip (held at 5V or 0V), so that pin 0 (RX) reads a digital HIGH.
- The MIDI interface needs to sink around 20mA of that resistance to achieve a voltage low enough that Arduino takes as a digital LOW
The problem with “normal” opto-isolators is that their gain, or more datasheet-technical, “Current Transfer Ratio (CTR)” which is usually below 100%. E.g. if an opto has a CTR of 20% it means if you input 15mA you’ll allow around 3mA to pass on the ouput (the case of 6N136 and 4N25). The 6N138, on the other hand, has a CTR of ~2000%, and 15mA would let up to 300mA through! see the difference?