3
\$\begingroup\$

I want to control a 5 V input on another device with a ESP8266 by using a PC817 opto-isolator. I am using the following wiring:

Wiring Diagram

The output pin is connected to an Arduino-like microcontroller. I need the signal to update at a 0.5 ms rate (2 kHz).

Do the wiring and the values for the resistors seem correct? Should I go higher with the resistor values to be safe?

I am new to electronics, and I want to make sure everything is alright.

\$\endgroup\$
8
  • \$\begingroup\$ The value of R2 looks fairly low for when the output will just be used as a digital input to another device. You could probably change it to a higher value (like 4.7 k) for lower power consumption. It depends on the load and the switching speed needed at the output. Also consider that you're building an inverter. A high at the input will produce a low at the output and vice versa. Do you really need the two parts of the circuit to be galvanically isolated? \$\endgroup\$
    – StarCat
    Jan 30, 2023 at 7:39
  • \$\begingroup\$ Assuming a 1.9 V voltage drop across the LED, the LED current would be about 4 mA. The optocoupler's datasheet can tell you if this is OK. As for the pull-up resistor: its value looks low if you are driving a digital input. What is connected to the Output Pin? \$\endgroup\$
    – ocrdu
    Jan 30, 2023 at 7:39
  • \$\begingroup\$ The output pin is connected to an Arduino like Microcontroller \$\endgroup\$
    – Yuukino
    Jan 30, 2023 at 7:53
  • \$\begingroup\$ @Yuukino What speed (rate, frequency, whatever) do you need? The PC817 isn't exactly a speed-demon (and also depending on what you can accept at the output.) So how fast, exactly? \$\endgroup\$ Jan 30, 2023 at 7:58
  • \$\begingroup\$ I need the signal to update with a 0.5ms rate (it's emulating an NEC InfraRed signal) \$\endgroup\$
    – Yuukino
    Jan 30, 2023 at 8:10

2 Answers 2

3
\$\begingroup\$

Assuming a 1.2 V forward voltage drop across the optocoupler's LED, the LED current would be \$\frac{3.3~\mathrm{V}-1.2~\mathrm{V}}{330~\Omega}\small\approx 6~\mathrm{mA}\$. The optocoupler's datasheet can tell you if this is enough, and what the LED's exact voltage drop is to do your own calculation.

As for the pull-up resistor: its value is quite low if you are driving a microcontroller's digital input. I would go for a 10 kΩ resistor and adjust if necessary. A microcontroller's inputs are high-impedance and you don't need much current to drive them at the speed you need.

You do need to ask yourself if you need an optocoupler at all, or maybe just a level-shifter, or even a direct connection. Also, if you want to make things safer, you will also have to separate the grounds.

\$\endgroup\$
1
  • \$\begingroup\$ Assuming the 4mA is enough for the optocoupler, then it should be fine, right? 4mA wouldn't be too much draw for an ESP8266 output pin, even if it's constant? And regarding Optocoupler vs Levelshifter vs Direct - while I could probably safely go with a direct route, I just want to be uber safe here and figured nothing is safer than separating both circuits completely as long as it works :) \$\endgroup\$
    – Yuukino
    Jan 30, 2023 at 9:27
1
\$\begingroup\$

330 on the 3V side one side 470 on the 5V side:

You're asking for a current transfer ratio of about 100% very few opto-isolators perform that well. The data sheet for this one says 50% which Is higher than I am used to.

The data sheet suggests 5mA as the LED current. The 330 ohm resistor will get you close to that, it's one of the sizes keep plenty of in stock so I would probably forego increasing it slightly to get closer to 5mA.

Overdriving the LED reduces its life, so unless you need blinding speed, underclocking your parts can pay off.

On the output 10K is my favourite size, I look for a reason not to use 10K, and finding none use it.

In this case the saturation performance specified at 20mA for 1mA out is more like the 5% current transfer ratios I'm used to. That suggests 22K or even 33K might be a better pull-up. if you want to output to go really low and not just kind of low.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.