# Relays vs Optocouplers

For watching for on/off stuff on different circuits, which is better and why for the arduino? Like detecting if a light is on or not but making sure to protect the arduino from the voltages

Optocouplers are cheaper than a relay, longer lasting than a relay, use a lot less power than a relay, and handle less power than a relay. So for input it makes no sense to use a relay because the inputs don't use significant power. For output it might, since the relay can switch high power devices.

I want to detect a turnsignal being turned on in a 12v system and pass that information to the arduino. A relay can be used technically from my understanding by allowing a 5v signal to pass through when turn signal is "on" and visaversa thus creating an on off signal. How ever an optocoupler I think can do this too? Its a bit confusing for me since I see they can handle huge amounts of voltage? And but when I google it, its said the input voltage should be reduced to 1.5v?

Thus, Pros and cons, Should I reduce voltage for the optocoupler? (If I indeed need to) or just use a relay?

If the turnstile produces a 12v pulse, feed this to the LED in an opto isolator (lots of circuit examples on the web). The opto transistor output would go to the Arduino.

example:

3.3v would be 5v on an UNO.

From the "kettle" side, Is there a limit to how high that voltage can be? Or can it just accept a 12v signal with no issues? (No resistors or special care needed).

Arduino side I understood fairly well. Diagram helped a lot too. I figured it would need a resistor there other wise it would have issues with grounding out a 5v directly to an input pin

You know the construction of an opto coupler ? The circuit you are monitoring is simply driving its internal led. If you can imagine your 12volt circuit driving a led (which will need a current limiting resistor) then that is it.

Something like this is what Im thinking? In this case, It would go from HI to LO when signal detected on 12v dc correct? If I just want to see on/off at all I can just go from 5v to Optocoupler, and replace GND with I/o?

Yes, that looks good. You're better off leaving that circuit alone. It's not worth giving up the internal pullup resistor just to have a 1 for an on state and a 0 for an off state. That stuff is so easy to hide (abstract) in the code. For example, you can define:

const uint8_t ON = LOW;
const uint8_t OFF = HIGH;

then when you sample the input...

if (digitalInput(pin) == OFF) { ... // turn signal is off

Awesome! Thank you! As well, Was I correct in my assumption that -SOME- sort of resistor is needed between 5v source and I/o pin? or can the board handle it internally?

The two GNDs can be separated to achieve galvanic isolation.

INPUT_PULLUP will connect an internal 20-50k Resistor to a digital input.

INPUT_PULLUP

Oooh! Got it! 10k OHM resistor there. Pretty fantastic! Thank you very much for all of your guys' help!

It is actually a nominal 46 kΩ pull-up. You should locate the optocoupler reasonably near to the ATmega to minimise the possibility of leakage between connections, but it means you do not need much current into the opto-coupler even if it is a low performance one such as the obsolete 4N35 series.

46k would pass 100 µA at 5 V, so if the optocoupler is fed with just 1 mA this will switch even if you only had 10% CTR. For 12 V you could use a 10k resistor to the optocoupler LED.