Using an Opto-Isolator to detect 120VAC on a Microcontroller

I am designing a system where I need to know whether or not 120VAC is present on a specific wire.

The system is in line with a fuel pump system, and I need to check to see whether or not the pump is getting power, if not, make an alert that the Emergency Shutoff Switch has been pushed.

The line could be either 0v (Open), 0A @ 120VAC current (Pump powered but not running), 8A @ 120VAC (Pump powered and running).

I really only need to detect whether or not there is 120VAC present.

I have found multiple sources saying that I could use an OptoIsolator, would this suffice?

And how would one wire it? Is it as simple as 120VAC in, 5v out? Or is there additional circuitry that I require?

• Did you solve the problem? I'm curious what method you ended up taking. – Mr.Hardy Apr 7 '14 at 20:07

A opto-isolator is appropriate, but no, you don't just wire 120 V into one. The input of a opto-isolator is just a LED, or sometimes two LEDs in parallel with opposite polarity. The LED usually emits IR, so drops around 1.2 V and can handle maybe up to a few 10s of mA. The output is usually just a phototransistor that allows current to flow thru it when it receives light from the LED.

Since this power is low frequency, you don't need fast operation and can use relatively little forward current. Let's say 2 mA peak thru the LED is enough. You can easily find optos that have a current transfer ratio (how much current the output transistor can pass divided by how much current you run thru the LED) of 1 or more. That means the output transistor tied between ground and a 10 kΩ pullup will produce a good enough digital signal.

The peak voltage of a 120 V RMS sine wave is 170 V. A 82 kΩ resistor in series with the LED will light it well enough in that case. It should also be rated for at least 200 V. The LED can't handle 170 V in reverse, so you can put a ordinary diode rated for the voltage in series with it, like a 1N4004. That also cuts down on the power dissipation in the resistor since it is only conducting half the time. In this example the resistor only dissipates 90 mW with the diode in series. The limiting factor for the resistor will be its voltage standoff capability.

There are various tricks to reduce power consumption, like using a capacitive voltage divider before the resistor. If 90 mW is OK, then I'd just use the resistor and diode.

• Just to add to this thread since it comes up in google when searching for AC optocoupler microcontroller: You don't need a diode to protect an AC optocoupler from high peak inverse voltages. The diodes are wired opposed to each other. Therefor, one diode is always forward conducting ensuring the voltage across the diodes is never above the forward voltage. Putting a diode in series will hurt you as the input to the microcontroller will pulse on and off when the AC zero crosses and reverses. Your input will be more of a square wave which will not work properly. – Mister Tea Mar 4 '15 at 13:55
• @Mist: As I said, opto-isolators come in both types, with a single LED and with two LEDs back to back. The latter is sometimes referred to as a "AC" opto-coupler. I was describing using the single LED type with a series diode because this will cause only half the dissipation in the series resistor. The output will pulse at the line frequency. That may be a problem in some cases, but NOT when you have a micro, which can easily handle this. In fact it may be useful to see that the system is working, and can even allow the micro to determine 50 versus 60 Hz line frequency. – Olin Lathrop Mar 4 '15 at 16:52

Optoisolators have varying safety ratings in terms of isolation voltage. If the monitoring circuit could be touched by a person, you would need an optoisolator that provides at least 3750V isolation (preferably 5000V) to safely isolate the mains from the user.

As far as detecting the AC goes, the input of an optoisolator is generally a unipolar photodiode. You need to ensure that whatever waveform you're monitoring doesn't exceed the rated voltage and current of the diode. (10mA is generally 'safe' for most optos.) You cannot 'just connect it' to the AC.

You could rectify the AC coming past the cutoff switch, scale it with resistors to a safe current, feed it to the photodiode and monitor the pulse train generated by the isolated phototransistor, or you could add some capacitors and make it into a DC level, feed that to the opto and monitor the phototransistor for on/off.

You could use an optoisolator across the power line and end up with a very cheap < $1 solution. However, a very simple way to do this without getting involved in the details of optos, appropriate resistors, possibly rectification and filtering is to buy an off the shelf wall wart that will take in 120VAC and output 5VDC. Should cost about$5 and it will immediately (+/- a second or so for its internal capacitors to discharge) indicate whether or not you have power on the line. A 120VAC relay can also be used instead. Either of these is likely simpler than building an optoisolator circuit.

Now, you don't say how you plan to detect this signal. Is it an input to a microcontroller, an Arduino (or the like), or just light up an LED?

• This is exactly the method I was thinking of taking. How long do you think it will take for the wall wart to come up to voltage, and subsequently drop? – Mr.Hardy Mar 20 '14 at 11:54
• It will depend on the load applied, but honestly I have never timed it. – lyndon Mar 20 '14 at 20:48

Just use a 120VAC Relay and monitor the N/O or N/C pins on the relay.

• +1 Not the most elegant of solutions but it does have the virtue of simplicity AND with the right choice of relay it can provide the level of isolation that is needed between Live Mains equipment and the bits that a hobbyist human (or uninformed others/children/pets) might come in contact with. Note that this is also a "volt-free" solution in that there is no voltage levels associated with the switch/contact wires which means it is trivially simple to connect it to virtually any circuit configuration. The only downside is that the power requirements may be higher than a solid state solution. – SlySven Jan 4 '17 at 20:24

Opto Isolator is the correct solution for your purpose, as I can see a it is a AC supply of 120V, I suggest to use a bridge rectifier which gives you some sort of pulsating DC, the just use resistor for voltage drop, and connect it to cheap optocoupler form Vishay or Farichild. The transistor side of the optocoupler connect to lower power supply on which your board is running and monitor it. You get a high when 120VAC is present and a low when 120VAC is not present.