The Forrest Mims Sunday Night Special

Sunday night. The kids and the wife went to bed early, and I decided to bust out some parts for that MIDI to Arduino interface I'd been planning on making for the past few months. While performing some tests, in a sudden fit of stupidity I fried my optocoupler.

Now what?

The Radio Shack by my house *probably* has one in stock, but they're closed. Digikey is in my state but even so they're 5 hours away, and I'm pretty sure banging on their doors at 1:00 A.M. is not going to get me what I want. I don't have to check my parts bin to know I don't have a phototransistor on hand, so I can't make my own.

But wait, didn't I just read about how to use an LED as a light *detector*? Wait, what? An LED will start reverse conducting when hit with light?

A drawing of two LEDs facing each other inside a tube of electrical tape.

YES. Ha ha. Ha ha ha ha ha ha ha! It's the MacGyver of optocouplers. Forrest Mims is a bad-ass. Check out his example schematic:

Forrest Mims example schematic for the LED optoisolator.

When LED1 flashes, it causes LED2 to reverse conduct, which brings the inputs of the nand gate high, swinging the output low, which turns on LED3. When LED1 is off, R2 pulls the inputs low, causing the output to go high, and the LED turns off.

Alright, that's fine and good but it's still Sunday night and I don't have any nand gates. Notice the signal is going to get inverted with that nand gate. I don't want it inverted so I'll try using an opamp as a buffer. This is the circuit I tried first:

Schematic for my first attempt

I grabbed a couple of LEDs. Note from the article that LEDs only detect light in a narrow band which is dependent on their output frequency. So I used two of the exact same LED.

Next, I wrapped those LEDs up in electrical tape:

Two LEDs facing each other on a strip of electrical tape.

If you do this, before you finish, make sure you put some kinks in one of the leads to the LED. Otherwise, after you spread the leads apart and wrap the whole thing up in e-tape you won't have any idea which lead is which, or even which end is which and it all gets very confusing. I think I wrapped and unwrapped it a half a dozen times.

An LED with a kinked lead.

I wired up the circuit on the breadboard, and..... nothin. That light steadfastly refused to light up no matter what I did. After 2-4 hours of thinking about it (read: supervising the kids on the playground) it was time to fiddle with the schematic. After some fiddling I came up with this circuit:

Schematic for my second attempt

I decided to invert the signal twice, and it worked perfectly! Well, not exactly perfectly. It spuriously turns on from time to time, but I'm pretty sure this is due to light leaks in my electrical tape housing. (I left the light leaks in on purpose so I could visually see if I had the first LED miswired or not.) Notice in the second schematic I'm running the opamps open loop. Also note the op amps are of the low voltage, rail to rail variety, so they'll actually output up to 5v.

Now, I don't know about response times. I spent so much time getting the circuit to work I didn't have any time to actually test it with some midi data. I'm in the middle of building out the rest of the midi input circuit, and I realized I lent my midi cable to a friend so I have to go get a new cable. But I'll update this page when I get everything working!

UPDATE: That circuit that I have that "works"... doesn't. I must admit I've been wracking my brains for days trying to figure out why it works because it should not work. From day one as soon as I wrote that circuit down I thought to myself, "wait, this is impossible, this shouldn't work!" Yet it does. Or, I should say, did. Turns out that it entirely depends on the circuit board layout whether or not it will work. A very slight change causes it to behave as I think it ought to theoretically. I, uh, will be happy to fix this when I figure out an appropriate fix.