# Detect 230VAC or 12VDC in the same pin [closed]

I'm designing an input interface for a microcontroller (uC). Want to detect signals (only want to know if there is voltage or not) of different typology, so you can have in the same input to the board:

• 0-12 VDC
• 0-24 VDC
• 0-230 VAC (Vpp)

Between the uC and the input (as it can be AC), i would like to use an optocoupler. On the other side of the optocoupler there will be the auxiliary circuits to adapt the signal to TTL to the uC.

The following schematic is the design of the interface between the input signal and the optocoupler led. The 230V AC on the Schematic represents the signal (in this case is 230VAC, but it must work with 12VDC too). There will be 12 input interfaces to detect voltage and operate 12 digital inputs on the uC side.

The common of the 12 different signals will be grouped by 4 signals (each 4 signals will share the ground. So, for example, you will be able to connect 230VAC signals in a group of 4 inputs, 4 signals of 48VDC on another group, etc.

The design I have developed needs op-amp, so I need to supply it with another power supply to keep it independent from the power supply on the uC side. That means too much components (op-amp, isolated power supplies for each group...).

The diode on the bottom line avoids the reverse current of the AC source to going into the output drain of the op-amp.

The values and exact parts to use are not defined completely, it's more a conceptual design than a final design.

The uC will be programmed to identify pulsing signal of the AC signals (because in the design below, it will only pass half of the sine waveform), and take it as Voltage AC detected.

simulate this circuit – Schematic created using CircuitLab

(the red point is the led of the optocoupler).

So here my question:

Is there any way to do this interface to the optocoupler, using only passive components? (taking into account the different voltage sources... from 5VDC to 230VAC).

If my design makes no sense, please, forget it, what I really want is to know if there is any possible combination of passive components that will allow to detect voltage on such wide possible values.

UPDATE

After days reading and checking information, taking into account all answers here. I declined to do an universal AC/DC detector due to complexity (and consecuently, cost of the components). What I will do is to implement an standard input to covers DC, and depending on the final user necesities (AC or DC), I will add to the input a capacitor for limiting current.

Thanks to Transistor and everybody for helping me.

## closed as unclear what you're asking by Bimpelrekkie, Olin Lathrop, Dmitry Grigoryev, laptop2d, Andy akaJul 9 '18 at 13:07

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• (1) What does "The design I have developed needs AO" mean? (2) What does the schematic you have posted represent? What is the Zener voltage and why is there a diode in the bottom line? How do you suppose this will work. (3) There is a proper internationally understood symbol for the LED. There is a CircuitLab button on the editor toolbar if you need it to add a better schematic. (4) Do you need isolation between the twelve channels or can they share a common? Clarify your question rather than add information via the comments. – Transistor Jul 1 '18 at 12:46
• For exact measurements over an optocouple, you need a compensated (servo) one, e.g. the IL300, or calibrate every single piece. Lookup the IL300 datasheet and application examples. – Janka Jul 1 '18 at 12:47
• @Janka: OP says, "Want to measure signals (on/off) of different typology" so it seems to be a digital on/off to me. – Transistor Jul 1 '18 at 12:49
• why not use the avalaunch current of the zener to feed the opto LED. NOTE: if you are wanting this to work for 12V and 230V (ie 325V)... the power being dissipated is going to be high and the dynamic range to ensure something "turn on" is wide... – JonRB Jul 1 '18 at 12:51
• Huh? What's a "AO"? Also, what is the current range the LED in your opto needs to be driven with to indicate asserted? What kind of power is available on the input side of the opto? Do all the channels need to be isolated from each other, or only from the output side of all the optos? – Olin Lathrop Jul 1 '18 at 13:08

There are many problems with your design.

1. You are using an op-amp for an application that requires a comparator.
2. You have no reference between your power supply and any ground in the rest of the circuit. This means that ...
3. There is no return path for the LED current. You are expecting the amplifier to provide current from the positive supply but there is no return path from the LED cathode to the power supply.
4. "The diode on the bottom line avoids the reverse current of the AC source to going into the output drain of the op-amp." It might provide some protection on one half-wave of the AC but will not on the other. You will have full mains voltage between the non-inverting input and the bottom of R2.
5. D1 / R1 don't do anything.

One of the most common applications for digital signal isolation is industrial PLCs. None of the major manufacturers offer a universal input type of the type that you are trying to design. The usual offerings are AC 120/240 V or DC 24 V with AC/DC options sometimes. If it was a realistic option then someone would be selling it by now.

I suggest that to do what you want you are going to need two inputs for each channel - one low-voltage DC and one mains AC.

simulate this circuit – Schematic created using CircuitLab

Figure 2. Probably what you were trying to draw.

The circuit of Figure 2 might work for you but doesn't solve your power-supply problem.

• A comparator is used rather than an op-amp.
• R1 / D1 now clamp the input voltage between -0.7 V and +5.1 V.
• The switching threshold is set at 2.5 V by R2 and R3.
• Everything is properly ground-referenced and the opto-LED current can make it back to the PSU.
• Thank you very much. Your help is very appreciated. As you say, I would like to use it in industrial PLC. Could It be solved with pasive components (maybe a high current zener and resistor) if I reduce the gap from 24VDC to 230VAC?. Thanks in advance – Fran H Jul 1 '18 at 19:25
• Draw your circuit. Thank afterwards by up-voting or accepting answers. – Transistor Jul 1 '18 at 19:38

Aside from functionality, that approach looks pretty complex. Consider something more along these lines (concept only). Use the one-shot to stretch the input pulse beyond 1/2 cycle, which will slow the response down. If you need to avoid that you'll have to consider adding a bridge rectifier at the input and doubling the dissipation of M1, so you'd want to use a bigger MOSFET or an opto with higher CTR.

simulate this circuit – Schematic created using CircuitLab