My friend was asking me why I was not using optocouplers to drive the relays on my project im prototyping.
Ive never even given it much thought to as why, as I have never ever used them before, but he said its needed to protect the microcontroller.
If proper spike protection is used, is it a worry?
Im wanting to control two 12v relays by means of an NPN transistor, and will implement spike protection by means of a zener from collector to ground.
Question is this overboard to use an optocoupler?
There seems plenty of discussion on this, but it seems that its more of a safety issue to isolate any potentially dangerous load on the relay from the rest of the circuit, from what im reading, its basically because alot of people are copying industrial schematics that warrant their use.
If i have good spike protection in place, is there any risk to the microcontroller?
Just seems like a whole lot of unnecessary expense and extra components.
Isolate the power rails from noise and spikes caused by EMI/RFI during contact arc and from driving the relay coil. This interference becomes worse when switching high energy inductive loads (high current and/or high voltage AC or DC).
Help prevent latch-up or reset of the MCU as the relay contacts break the load
Provide higher reliability and full isolation
Allow longer cable run from relay module to MCU circuitry
Provide a simple interface ... only require one 4-pin optocoupler and 1 resistor, verses one 3-pin transistor and 1 resistor
If you can get the FOD852 photodarlington optocoupler (datasheet), it can switch up to 300V and 150mA which could directly drive most any relay coil. What's the part# or link to your relay?
You may try it and you will see. I doubt optocoupler is needed for small relays. Its advantage is completly isolated power - you don't have to connect grounds and so less noise will reach rest of your circuit. Otherwise I don't think much harm can cross the 10k resistor and transistor. Even without the transistor it would be nearly safe connect Arduino pin to 12V via 10k resistor (but not driving the relay ofc).
Im only using a couple of small sugarcube relays, I was thinking at first that I would just go with 5V ones, but if that risks spikes on the 5V supply to the logic board, I will simply use the 12V supply feed in to power the relay coils instead.
This would also mean less current demand on the 5V rail and I could probably ditch the 7805 which would have the potential to dissipate lots of heat, and instead go with something like an AMS1117 perhaps?
nzoomed: Skip 5V regulator. Just use 12V DC source to power the relay ... and (5V) arduino via raw power pin.
There is 5V regualtor (usually AMS1117) on arduino itself to regualte power. No need to duplicate the same function.
I use such setup: 12V DC 2A rectifier drives:
2 serially conected low power lasers (14mA)
a 12V LED light strip with about 1A consumption (which is swiched on and off by arduino using FET transistor (SMD type capabel of 4A)
and arduino nano 5V 16Mhz (via raw power pin)
5V Arduino controls: - abovementioned 12V LED strip
and 240V mains fan (via optocoupler and triac).
Very few commercial designs using a relay to switch a significant load would use an optocoupler. Example: a PIR switch:
It's all a matter of proper design including PCB layout, routing and placement of (electrolytic) bypass capacitors.
You need to ensure that the current path driving the relay connects separately to the main reservoir capacitor from the supply to the logic circuits - "star grounding" and "star sourcing" because it is not only the ground.
Similarly you need to ensure that the switched mains wires are kept together all the way and kept completely apart from all the logic wiring,