Optoisolator to check that a vehicle switch is turned on

I have a small project I am working on where I originally had planned on using a 12vdc relay to control the 5vdc logic on my arduino input to tell me when a switch is turned on or off. When the switch is on in the vehicle there is obviously 12vdc present (11-15vdc range). I got to thinking about this in a packaging sense, since I am trying to keep cost down and size down.. Can I just use an opto-isolator to sense the 12vdc presense, and just run the arduino to the other side of the opto to complete my input logic?

More specifically, I just happen to have about 2 dozen ISOCOM MOC3041X opto-isolators laying around.. Is it as simple as putting a 330ohm resistor inline with my 12v input to drive the LED and hooking my arduino up to my input with a resistor also?

What am I missing?

1 Like

You want an opto that has a transistor type output , the type you mention has a triac output .

Otherwise yes !

hammy:
You want an opto that has a transistor type output , the type you mention has a triac output .

Otherwise yes !

Doh! My bad on the triac.. I should have known that, haha.. I have a bunch of these on my desk that our CNC machines use for AC controls.. That should have been my first indicator.. In any case, I just ordered some 4n25 optos that should work just fine and were cheap..

Thanks!

Just remember, logic will be reversed, when input goes HIGH, output transistor will pull to ground (LOW).

330R sounds a little low with a 12V signal. IR LEDs have a forward voltage around 1.5V. I don't know what current is required to produce enough IR light to saturate the transistor, but don't imagine it will be much. Even if it is as high as 10mA, you want a series resistor around 1K.

PaulRB:
330R sounds a little low with a 12V signal. IR LEDs have a forward voltage around 1.5V. I don't know what current is required to produce enough IR light to saturate the transistor, but don't imagine it will be much. Even if it is as high as 10mA, you want a series resistor around 1K.

That was based on the specs for the MOC3041X which has a max input current of 50mA and test condition 20mA.. 1.2-1.4v drop and assuming I would be anywhere between 11 and 15v with the vehicle engine running.

15v-1.4v = 13.6v
11v-1.4v = 9.6v

13.6v at 50mA = 272 ohm
9.6v at 50mA = 192 ohm
13.6 at 20mA = 680 ohm
9.6 at 20mA = 480 ohm

That said, the 330ohm was in between the max spec and the test number and a standard resistor that I have on hand..

In any case, now using the 4n25 I will recalculate those numbers..

Is it more common to just use the "test condition" numbers on the spec sheet for these components? I just dont want to lose signal if my voltage dips with the engine not running.. Then again, I guess if my battery falls to 11 volt or lower I have bigger issues on my hands.

No, the "test condition" specs are simply there for testing. :roll_eyes:

It's like people quoting the absolute maximum current rating for an Arduino (UNO etc.) as 40 mA as if this is some sort of appropriate figure to use in designs.

So, you connect the transistor output of the isolator between a pin and ground, using INPUT_PULLUP to enable the approximately 47k pull-up. The current required to pull that down is about 100 µA, so we will figure for at least twice that. At these low pull-up currents however, you should ensure the opto-coupler is mounted fairly close to the Arduino.

The CTR (Current Transfer Ratio) of the ancient 4N25 is specified at minimum 0.2 (20%) - it is the better of the series; the 4N27 is minimum 10%. :astonished: So to guarantee operation, you might want to drive the LED at 1 mA but figure 3 of the datasheet shows that the CTR drops off substantially at 1 mA, so you probably should supply about 5 mA to make absolutely sure (so basic optocouplers are completely unsuitable for passing analog signals as they would distort them severely).

So for 12 V (or 13.6 V in a car), the LED resistor should be about 2k7 (near enough to 2k4).

More modern opto-isolators such as the PC817 have a minimum CTR of at least 50% at lower LED currents.

You can go straight in to the Arduino with a divide by three resistor chain.