Correct usage of optoisolator for noise immunity on unshielded connections

MrChips

Joined Oct 2, 2009
31,192
Ok. Pull-up resistors 20kΩ-50kΩ are there to just barely pull up the input when the limit switch is open.
I say you can go as low as 100Ω and this should absorb most EMI.

Edit:
Just to make it clear, put the 1μF from input to ground.
The 100-220Ω goes from input to the +ve supply line of your Arduino circuit.
(I don't see why you couldn't put both R and C in parallel from the input to the +ve supply line.)

Make sure that you are connecting to the right voltage. Put a voltmeter across the limit switch. Activate the switch and tell me the voltage reading.
I had asked for a reading of the switch voltage which we have yet to receive.
I needed to know if the voltage is 3V, 5V, 12V or something else.

Assuming the voltage is 5V, 100Ω would be drawing 50mA from one resistor. I would assume that the regulator could handle an additional 50mA. I did not expect that you would change all the inputs at once.

This was to see if the noise problem would be eliminated. Following that test we could have modified the current draw. We could have dropped this to 5mA.
 

Thread Starter

daxliniere

Joined Aug 7, 2021
52
I did not expect that you would change all the inputs at once.
Hey MrChips! Ahh, I see, I didn't realise that. :(

Switch voltage is 5.02v when open.

Yep, I can try with 1k, but I'll have to wait a few more days to order a new Nano.
Thanks again for your help. I'll let you know how I get on.
 

Thread Starter

daxliniere

Joined Aug 7, 2021
52
As for the regulator, yes, me too. Especially since it's a 7812. No heatsink, but it's only powering the Nano, which in-turn creates the 5v rail.
 

MrChips

Joined Oct 2, 2009
31,192
I looked at the Arduino Uno circuit diagram. There is no pull-up resistor present.
Hence they are using the internal GPIO pull-up which explains the 20k-50k values given.

Normally, GPIO pins are in the input state on power up.
If for some reason the code switches the GPIO pin to output then we're in trouble asking the pin to sink 50mA.

You can do this in stages. Try 10kΩ pull-up to 5V for starters followed by 1kΩ. Don't go below 1kΩ.

Sorry about the mishap.
 

BobTPH

Joined Jun 5, 2013
9,335
A 7812 is not 5V! If you connected the resistor to 12V, you probably destroyed at least the inputs on the Arduino.

Bob
 

MrChips

Joined Oct 2, 2009
31,192
That just crossed my mind.
Are you sure that there is a 7812 regulator on the board?
There should not be one on the board.

Where did you connect the pull-up resistors?
 

Thread Starter

daxliniere

Joined Aug 7, 2021
52
Don't worry, guys, the 7812 is powering the Arduino only, not used for any signals. The system PSU is 24v, but Arduino Nano can only handle 12v VCC, hence the 7812. Arduinos have 3.3V and 5V output pins for connecting to myriad devices.

The 100R pull ups were connected between the same 5v rail as is used to set the stepper drivers' modes.

Thank you for your concern!!

"Sorry about the mishap."
Don't mention it, I really appreciate all of your help. :)
 

drjohsmith

Joined Dec 13, 2021
852
Don't worry, guys, the 7812 is powering the Arduino only, not used for any signals. The system PSU is 24v, but Arduino Nano can only handle 12v VCC, hence the 7812. Arduinos have 3.3V and 5V output pins for connecting to myriad devices.

The 100R pull ups were connected between the same 5v rail as is used to set the stepper drivers' modes.

Thank you for your concern!!

"Sorry about the mishap."
Don't mention it, I really appreciate all of your help. :)
The 7812 is dropping 24 to 12 v
assuming 100 mA as a rough guess of the circuit
thats 1.2 watts dissipated , Ouch,

BTW:
have you seen these

https://www.rugged-circuits.com/

may be more in tune with the 1.5 Kw motors your using,
 

MrChips

Joined Oct 2, 2009
31,192
Something still does not add up.

The 7812 regulator is external to the Arduino Nano? It is not on the Nano pcb, correct?

Check your code. Does it at anytime enable the GPIO pins under question to outputs?
 

djsfantasi

Joined Apr 11, 2010
9,189
I would bet that just a pullup if 100R would do it.

Bob
NO!

That will destroy the Arduino GPIO pin and likely the Arduino.

A 100R resistor at 5V will draw 50ma. The MAXIMIM current per pin is 40ma and should be designed to be around 20ma. PLUS, the TOTAL current draw has a MAXIMUM of 200ma. With three limit switches with an external 100R pullup resistor draws 150ma and the Arduino can easily pull 50ma. Anything more, with any external devices, etc… and the Arduino will self-destruct.
 

MrChips

Joined Oct 2, 2009
31,192
NO!

That will destroy the Arduino GPIO pin and likely the Arduino.

A 100R resistor at 5V will draw 50ma. The MAXIMIM current per pin is 40ma and should be designed to be around 20ma. PLUS, the TOTAL current draw has a MAXIMUM of 200ma. With three limit switches with an external 100R pullup resistor draws 150ma and the Arduino can easily pull 50ma. Anything more, with any external devices, etc… and the Arduino will self-destruct.
If the pins are in input mode?
 

djsfantasi

Joined Apr 11, 2010
9,189
Can you explain how the chip would be damaged if the pin is set to input mode with 100Ω pull-up to +5V?
It’s good for me to be challenged; that’s how I learn.

I’ve always based my design decisions based on references like the one below.

8D2E9CA8-33C6-4A63-8BB2-BC1DE1DFA42F.jpegB67534E8-4128-499E-B3CB-CD73A4B0CBA5.jpeg

However, you also have to consider your instructions to the TS.

The 100-220Ω goes from input to the +ve supply line of your Arduino circuit.
(I don't see why you couldn't put both R and C in parallel from the input to the +ve supply line.)
What is the +ve supply line of this circuit? If it’s 12V, then the pin will be destroyed. If it’s the Vin pin, then the three pullup resistors will be sinking 150ma from the Arduino 5V regulator. Again, it likely with everything else to be drawing more than 200ma. And, the 200ma is a maximum. Often, design specifications specify 150ma. In either case we are in the danger zone if we use a 100R resistor.
 

Thread Starter

daxliniere

Joined Aug 7, 2021
52
It’s good for me to be challenged; that’s how I learn.
I couldn't agree more. :)
Can I just say how great this forum is? Well, more accurately, the members. :) Thanks everyone.

By the way, I think I might solve all this nonsense by adding another 12v PSU (buck converter) and using it to run the limit switches at a higher voltage, which can then feed into optoisolated relays. Surely that will solve everything, right?
 

MrChips

Joined Oct 2, 2009
31,192
I am thinking that adding a low resistance pull-up resistor will not eliminate the noise problem.

I have built my own CNC machine from scratch and made a point of using shielded cables on the limit switches.
Also, the controller input uses opto-couplers which sense current and not voltage.

In your case, the limit switches are normally closed to GND. The unshielded cables are picking up EMI which is seen as a voltage going above the logic threshold voltage at the input pin of the ATmega328. We can assume that the signal has to rise about Vcc/2, that is above 2.5V to register as a fault condition. Adding a pull-up resistor will only make this worse. What we need instead is low impedance termination to GND.

So, what can we do to remedy your situation? Perhaps a capacitor to ground might help but you will still need a pull-up resistor in order to present a low RC time-constant otherwise the fault condition will not be recognized in a timely fashion.

Would an extra board with opto-couplers on the inputs be an acceptable solution for you?
 

Thread Starter

daxliniere

Joined Aug 7, 2021
52
Yeah, I've got a 4-channel unit of these optoisolated relay boards. (Actually, one channel is dead, so this is a perfect use for it.)


Do you think I'll still need to go down the route of adding a separate 12v isolated supply for the limit switch side of the relay board? I guess I can just test it and see.

It was good to learn about the Arduino pin current limitations, hopefully I can avoid a mishap in future.
 
Top