Sunday, 28 June 2020

More Power! HY-M154 4-Channel Optocoupler PCB as Digital Output

Tim Allen's Home Improvement TV Series

More power always seem like a good idea at first. Well at least you fail in style: if you were to crash and burn, you might as well burn the candle at both ends.

PC817-based 4-channel optocoupler PCB
The HY-M154 is a cheap and cheerful optocoupler board, and is very useful converting digital input voltages to the 3.3V required by the ESP8266 or Raspberry Pi GPIO pins.

Note the 3K series resistors at the input as well as output

You could for instance feed 12V at the input IN1 and this will pass about 4mA into the optocoupler diode. The PC817 has a current transfer ration (CTR) of 50% so the output will put out at least 2mA. A typical V1 is 3.3V so this is more than enough to pull the ESP8266 or Raspberry Pi GPIO pin low.

But what if I wanted to use it as an optoisolated digital output board? If I connected an ESP8266 3.3V GPIO configured as output, it will light up the input LED and feed approximately 1mA into the optocoupler diode. With a CTR of 50% I would expect a maximum of 0.5mA at the output. With 5V at V1, I measured 0.09mA at the output. That will light up an LED dimly, but will not do much else.

One way to improve the output drive is to convert the output to a darlington stage. Indeed, with typically low CTRs, optocouplers with darlington outputs are quite common, like the 6N138.

Optoisolator with darlington output

I have plenty of the venerable 2N2222 in TO-92 package which will attach nicely to the HY-M154:

Darlington output stage using 2N2222 transistor
But this only got me 0.25mA, a gain of just 2.5, which was disappointing because darlingtons can often achieve gains of 100 or more. Now this might be because of the 3K series output resistor. I shorted it with a pair of tweezers and I now get 5.6mA. Much much better: I get a decent brightness at the output LED now, but more power! would be nice. Maybe 100mA, enough to drive a small relay or an ultrabright LED, or a buzzer.

To increase power I would need to drive the optocoupler input diode harder, and the input 3K resistor needs to be changed. I started with a 30R resistor.

HY-M154 with 30R input and 0R output resistors

  I get 39mA at the darlington output at 5V. Now we're talking. Lowering  it further to 10R should be good enough to drive a small relay.

I used this program to blink the ouputs.

Lolin NodeMCU ESP-12E driving HY-M154. Note easyhook supplying 5V to HY-M154 output darlington 

Happy Trails.