0
\$\begingroup\$

I want to detect a binary switch state - better said a logic 1 or 0 via a PC817 optocoupler - and my question is, if both of these ways are correct:

A) Connecting the GPIO input pin via the optocoupler directly to 3.3V of the ESP32 without resistor with 4.7K and then using a pull-down resistor to GND of the ESP32. Is the pull-down resistor here even required?

B) Connecting the GPIO input pin via the optocoupler directly to GND of the ESP32 without resistor and then using a pull-up resistor with 4.7K to 3.3V of the ESP32.

Here is a schematic, I am using variant A. Does that make sense or is that dangerous to the GPIO?

I am aware that the ESP32 also has internal resistors, but I prefer an external one.

enter image description here

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Both are equally correct. It is really not much different than connecting a push button, one pin to GPIO pin and the other pin to 3.3V or GND, depending on if you want active high or low button.

A) It is correct. The pull-down resitor might not be needed but best to have it there anyway. The ESP32 has internal pull-down resistors, but they may be too high value and it will not be enough to counter the leakage current through optocoupler. It requires pull-down, either internal or external.

B) It is correct. The up-down resitor might not be needed but best to have it there anyway. The ESP32 has internal pull-up resistors, but they may be too high value and it will not be enough to counter the leakage current through optocoupler. It requires pull-up, either internal or external.

\$\endgroup\$

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.