# Substituting Arduino for ESP8266 in a (Yet Another!) Garage Door Controller

I have a garage door opener with two leads that will activate the motor if the leads are shorted. I hooked my multimeter into the leads and measured ~24VDC and triggered the motor ~50mA.

Using an Arduino Nano v3 as a power supply, I wired a simple push button to short the 3v3 output through a 100 Ohm resistor (R1) to the emitter side of the an H11AA1M optoisolator. The Arduino's ground goes to the other input of the emitter side of the optoisolator.

On the detector side of the optoisolator, I hooked the leads from the garage door opener through another 100 Ohm resistor (R2), and when I press the button, I can successfully control the garage door opener. I could be remembering things incorrectly, but I'm fairly certain I measured between 20-30mA across R2 when the door activates.

When I swap the Arduino for an implementation of the ESP8266 and swap the button for one of the ESP8266's GPIO, I cannot activate the garage door opener when I push gpio.HIGH across the connect GPIO. I also measured 20-30mA across R2.

If I toggle R1 or R2, I see different current values across R2, but if I'm fairly confident that I'm within tolerance for the necessary current to trigger the garage door opener. I ultimately want to drive my custom controller using the GPIO, and as far as I'm aware, I just need to activate the optoisolator's emitter to drive the transistor on the optoisolator's detector side into saturation.

What's going wrong? I'd love to know how to best diagnose my problem. I have a feeling that I'm not calculating something correctly based on the optoisolator's specs, but Googling hasn't led me to tutorial that hasn't made my head swim. I'm love some more insight into how to best read the optoisolator's specs and how they apply to my current and future projects.

(Please don't suggest I swap out the optoisolator for a relay. I realize that relays will probably be less finicky, but at this point, I'm more interested in the why than how.)

EDIT: I removed R2 and confirmed with the multimeter that >30mA run across garage door opener's leads, and now, the garage door opener is properly triggered!

• A schematic might help, you can add one using the editor, by pressing Ctrl-M. – Tyler Mar 28 '16 at 15:01
• Please provide a schematic, you probably don't have your grounds connected correctly and you actually have an open circuit now that you've gone wireless – Voltage Spike Mar 28 '16 at 19:53
• Your mention of measuring currents "across" components is a bit unsettling. Voltage is measured across components, while current is measured through them - so hopefully you broke the circuit and inserted the ammeter inline to reconnect it, rather than shorting the circuit with the meter. – Chris Stratton Apr 2 '16 at 17:11
• @ChrisStratton, I'm sorry for the poor choice of my words. I inserted the ammeter inline. – sl33nyc Apr 3 '16 at 17:22

The H11AA1M has a minimum CTR (Current Transfer Ratio) of 20%. That means if you have 20mA going through the emitter (LED) then the detector (transistor) may only be able to switch 20mA * 20% = 4mA.

You measured 50mA 'trigger' current when the garage door opener input was shorted, so you should be using an optocoupler that will switch that much current. ESP8266 GPIOs are only guaranteed to supply 12mA maximum, so your optocoupler should have a CTR of at least 50mA/12mA = 4.2.

So why does it work after removing R2? Your particular ESP8266 might manage to drive 20mA into a 100Ω resistor and infrared LED, and your individual optocoupler unit might achieve a CTR of >1.5 at 20mA. However the fact that it can't handle an extra 100Ω on the output suggests that it is barely working. It may fail in colder or hotter weather, or when the optocoupler transistor overheats because it is out of saturation.

For reliability you should increase the value of R1 to draw no more than 12mA from the ESP8266's GPIO, and change the optocoupler to one with higher CTR, eg. 4N33 or H11B3.

• Yes. One could presumably also use an at-hand NPN transistor and base resistor to achieve some current gain for driving the existing optocoupler. With the NPN as a low side switch the high-to-activate sense of the current setup would be preserved. – Chris Stratton Apr 2 '16 at 17:10