Multiple optocouplers

Hi folks,

I am creating an all digital dashboard for my van. I’ve already worked out the interface and a number of sensors, using Arduino and Raspberry Pi, but I’m going to have to connect the Arduino with a number of circuits (8-10) in order to see if they are powered (or grounded in some cases) and light up the proper icon on the dash. For example, low or high beams, turn signals etc.

I’ve thought about voltage dividers, but it seems that it would be best done using optocouplers. This should allow me to use digital inputs on the Arduino, and even some interrupts. I do not need to know how much voltage is on each circuit, just that they are on or off.

My question here is to verify if this would make sense in order to use not just one, but several optocouplers connected to different input pins, and if not, how I would need to modify it. This diagram shows 3 optocouplers (PC817) receiving input from 3 different 12v circuits, and connected to the car’s ground. Each opto has a resistor for the LED, and there’s a 10k resistor on the 5v source from the Arduino. Also added a diode for protection on the car’s ground connection.

Thanks for any tips.

As shown in another thread, I am still learning about optoisolators. :confused:

Your drawing above looks like you are powering the LED input side of the PC817 from 12 volts. I’d be interested in the resistor value you are using- I tried to get an answer to resistor values with a PC817 with no success.

Then it looks like you want to read the output side of the optoisolator to see if the input circuit is energized.

It looks like in your drawing that your digital inputs are on the high side (powered side of the transistor in the PC817) and will always be high. I think you want to read form the low side, after the transistor, to determine when it flips on and off.

With my limited understanding, I would suggest your idea will work. I wish you luck in either calculating or getting a suggestion for proper resistor values on either side of the PC817.

You need a resistor to Vcc on the opto outputs, otherwise the smoke will come out. An example.

dougp:
You need a resistor to Vcc on the opto outputs, otherwise the smoke will come out. An example.

The output side of that opto is rated to 35 volts and 50 mA. Would LOVE a suggestion as to a resistor value. I am not OP.

dougp:
You need a resistor to Vcc on the opto outputs, otherwise the smoke will come out. An example.

Note that there is a 10k resistor on the VCC supply to the optocouplers, see on the left. Is that what you mean?

The OP's circuit has several errors. You need individual resistors for each opto transistor, you cannot gang them together through one resistor. If you were trying to make an OR gate you could do that... because the first opto transistor that turns on, pulls all three inputs low. But that's not what you want.

Normally, you could just use the internal pull-ups on a '328 input with "pinMode(n,INPUT_PULLUP)" but that is a rather weak (~20K) pull-up and an automobile is a rather noisy environment - so I'd go with external pull-ups, 1K should be a good.

You show 470 ohm resistors on the input LED's. That's too low, you'll eventually loose some optos that way since spikes on the 12 volt supply can surpass 50 volts. I would raise the led resistors value to about 1.2K, that should give you about 10 ma in the diode which a max limit of 50ma. Given the current transfer ratio of the pc817 can be as low as 50%, the 10ma in will still give you the required 5ma out (5v/1000r).

You also have a single diode in series with the 12v ground. It's not needed for reverse polarity protection since all you're powering is diodes.

bigred1212: As shown in another thread, I am still learning about optoisolators. :confused:

Your drawing above looks like you are powering the LED input side of the PC817 from 12 volts. I'd be interested in the resistor value you are using- I tried to get an answer to resistor values with a PC817 with no success.

Then it looks like you want to read the output side of the optoisolator to see if the input circuit is energized.

It looks like in your drawing that your digital inputs are on the high side (powered side of the transistor in the PC817) and will always be high. I think you want to read form the low side, after the transistor, to determine when it flips on and off.

With my limited understanding, I would suggest your idea will work. I wish you luck in either calculating or getting a suggestion for proper resistor values on either side of the PC817.

On my sketch I used 470 ohm (5%) resistors for the LEDs. That is what is currently used in the existing circuit in the van to power some of the LEDs. I suppose it could be 220. I'm not sure. For the VCC, I think I've seen 10k commonly used while reading online.

avr_fred: The OP's circuit has several errors. You need individual resistors for each opto transistor, you cannot gang them together through one resistor. If you were trying to make an OR gate you could do that... because the first opto transistor that turns on, pulls all three inputs low. But that's not what you want.

Normally, you could just use the internal pull-ups on a '328 input with "pinMode(n,INPUT_PULLUP)" but that is a rather weak (~20K) pull-up and an automobile is a rather noisy environment - so I'd go with external pull-ups, 1K should be a good.

You show 470 ohm resistors on the input LED's. That's too low, you'll eventually loose some optos that way since spikes on the 12 volt supply can surpass 50 volts. I would raise the led resistors value to about 1.2K, that should give you about 10 ma in the diode which a max limit of 50ma. Given the current transfer ratio of the pc817 can be as low as 50%, the 10ma in will still give you the required 5ma out (5v/1000r).

You also have a single diode in series with the 12v ground. It's not needed for reverse polarity protection since all you're powering is diodes.

Thanks, avr_fred. That is exactly what I was looking for. Your first point was my main question as it looked like it could work but didn't feel quite right. So I'd use a 10k resistor for each "leg" going to an opto from the VCC supply? Will that be ok when more than one is on?

Regarding the pull-ups, that would be between the Vcc from the Arduino and each input, right?

Thanks for the suggestions for the input resistors and diode. I had a feeling that extra diode was not necessary but I thought I read somewhere that there could still be a risk without it.

So I’ve redone the diagram based on comments. I’m a bit fuzzy on the pull-up resistor connection, but I’ve moved the input pin connections to the ground side of the optocoupler output on each and connected a 1k resistor from Vcc to that. Does that seem right?

Also made the other changes. It’s a 1k ohm resistor on each input as that’s what was available on the fritzing app.

That’s going to be a bit cramped in the end, but if that works…

Wouldn't the 10k resistors on each leg be enough though, if the inputs are also on that side?

If your circuit is as shown in post #8 it still will not work. You have the Arduino inputs connected to ground. What you need is a hookup as shown in example #2.

The signal to the Arduino is taken at the junction of the opto collector and the pullup resistor.

Yes, I had it on that side first, but then why use an additional resistor if there is one already on that side?

Opto_bb3.png

Slightly simplified:

Opto_bb4.png

KISS.

Opto transistor between input pin (opto collector) and ground (opto emitter). NO 5volt to the opto, NO resistors.

Opto LED with 10k current limiting resistor to a 12volt source.

Enable the internal (= inside the MCU) pin pull up resistor with pinMode.

pinMode(optoPin, INPUT_PULLUP);

A 10k opto LED CL resistor is about 1mA LED current. Enough for the ~250uA current of the internal pull up. Leo..

I'm lost.

Per what I've read supplying 5v from the Arduino to the optocoupler without a resistor is going to make it run hot and fail, no? I haven't yet seen any diagram that doesn't use a resistor there.

Re-reading avr_fred's post, I think I now understand that he meant 1k resistors instead of the 10k ones that I've been placing on each branch from the Arduino (and the original unique one in my first nonsense diagram). The term "pull-up" threw me off.

Thanks all, I think I have a handle on how this works now. I'll try on the breadboard with a couple circuits before committing.

LeChuck: I'm lost.

Per what I've read supplying 5v from the Arduino to the optocoupler without a resistor is going to make it run hot and fail, no? I haven't yet seen any diagram that doesn't use a resistor there.

What I have explained in post#12 is electrically the same as the diagrams in post#11, but using the pull up resistors inside the processor. If you enable those internal resistors in your code, then you don't need external ones. And therefore also no 5volt to the optos. Leo..

Hi,

I am working on a very similar setup, so wanted to ask if you made it work? if so is the last drawing you posted the correct one?
Thanks :slight_smile:

This an old thread.

It would be best for you to start your own thread and explain your requirements.

It wiuld make things much simpler if you would just grab a black pen and a blank sheet of printer paper and draw a PROPER schematic.