# detection of absence of 118V DC voltage using optocoupler

I want to use an phototransistor interfaced with microcontroller to detect absence of 118 dc voltage.The problem is how to calculate the right resistor value of the input(LED) circuit as well as output circuit(collector emmiter cct) thanks.

-

If you use the following circuit you'll get a high output voltage is the 118V is absent. Swap transistor and load resistor if you want a low output voltage.

Let's take a look at the CNY17 (though many other optocouplers will do). The CNY17 is available in different CTR (Current Transfer Ratio) classes. CTR tells us how much collector current there will flow in the phototransistor for a given LED current.

Let's assume a 5V $V_{CC}$, that we draw $200\mu$A from the output and that the output voltage for a high level should at least be 4V. Then the maximum value for the load resistor should be

$R = \dfrac{5V - 4V}{200 \mu A} = 5k\Omega$

Then the collector has to sink 5V/5k$\Omega$ = 1mA to drive the output down to 0V.
The CNY17-3 has a CTR of 100-200, that means that for the 1mA out you'll need between 0.5mA and 1mA in. Worst case is 1mA.
Then R1 should be 118V/1mA = 120k$\Omega$ (rounded to the nearest E12 value. I'm ignoring the 1.65V across the LED). That's it.

118V across a resistor is a lot, so let's see if it can handle that. Power = 118V $\times$ 1mA = 118mW, so a standard 1/4W PTH resistor is OK. This can also handle the voltage. If you want to use an SMT resistor you'll need at least an 0805.

The load resistor determines the current, and we can't use a value higher than 5k$\Omega$, otherwise the output voltage level will be too low. If that means that you have to drive the LED with a too high current (for instance in an optocoupler with a low CTR, CTRs much lower than 100% are common), you can use a voltage follower to limit the load current, so that you can use a larger resistor value.

-
118mW in a 1/4 W resistor will run pretty hot - nominal resistor power ratings should be treated with several pinches of salt. I'd go to at least a 1/2 or 1W in TH, with plenty of copper on the pads to spread the heat, and for SM, 2-4 series 0805s –  mikeselectricstuff Apr 14 '12 at 9:16
@mikeselectricstuff - 118mW isn't anywhere near the maximum, it's only half the rated value. Why wouldn't it be safe? Why would they rate a resistor at 250mW if even 118mW would be too much? –  stevenvh Apr 14 '12 at 9:26
The rated value works the other way round - if you put more than 250 mW into the resistor, it will blow up. It also assumes that you're operating the resistor in a nice cool environment with excellent heat removal. –  Optimal Cynic Apr 19 '12 at 6:26
@Optimal - No it won't. Just as an experiment I tried 1/4W resistors at 1W for tens of hours. They didn't fail. –  stevenvh Apr 19 '12 at 6:49
@stevenvh: That was pedagogical hyperbole. If you exceed the maximum rating, you are essentially voiding the manufacturer's guarantee that the resistor will be X ohms +/- Y%. It could also explode in a spectacular fireball and your colleagues will say "Well, it's your own silly fault". The real point is that it's extremely bad engineering practice to run a component too close to its maximum rating. –  Optimal Cynic Apr 19 '12 at 21:29

A simpler approach would be using a digital isolator such as the ADuM3210. Use a voltage divider to create a 5V input to side 1 of the isolator when the 118V supply is present. This will be communicated across the isolation barrier as a "1" on the output. When the 118V supply is absent the voltage will drop to 0V and a "0" will be observed on the output. You can power the isolator from a supply derived from the 118V supply if necessary. If the input supply is lost, the outputs will default to "0" by default and maintain the correct sense.

You won't have to worry about CTR temperature variation or degradation over time in the optocoupler, and the power consumption will be much lower. You can learn more about digital isolator solutions here:

An Alternative to Optocouplers

-