Hello, I need to connect a limit switch to an esp32. I'm building a robotic arm and the drivers of the stepper motors are supplied with 48V. Online, I have read that operating my limit switches with 3.3V for example count create problems with noise and my esp32 noticing an input even though there is none. I plan to use a PC817C optocoupler to isolate both circuits. I just wanted to check if my calculations for the resistors are correct.
R1 = (3.3V - 1.2V) / 0.02A = 105 Ohm
R2 = (48V - 2V) / 0.02A = 2300 Ohm (this is the right calculated value, ignore the one in the image)
Basing a design on something you think you read is not a good start. If using 3.3 volts with your Arduino and limit switch show problems, then address it at that time.
Why do you think 48 volts will not also have problems? Noise is noise at any voltage. And yes, noise may also turn the LED on in an opto-isolator.
By the way, a limit switch should OPEN when pressed, so if the switch and wiring fail and open up you will know it.By only checking for a closed switch and something fails you will never detect it.
R2 = (48-1.2)/10mA = 4680, use 4.7K
With a CTR of 200 the output current should be made less than 2 x 10mA
Five times less would be good so R1 = 5V/4mA = 1250, use 1.5K