I want to detect an AC Line Voltage (230V RMS, 50 Hz) and interface it with a microcontroller.

I am aware about two solutions:

  1. Using an optocoupler like PC817 (datasheet)

  2. using MID400 (home page, datasheet)

Both are optocouplers, but the PC817 gives a pulse train (50 Hz pulses) at its output according to my testing.

The MID400 output, I have not tested yet but its datasheet indicates that it outputs a LOW when AC is detected and outputs a HIGH when AC is absent.

Now clearly there is a difference in PC817 and MID400 output.

So I would want to know whether really, practically, the MID400 gives a steady HIGH or LOW signal? Has anyone tried with MID400 ?

  • 2
    \$\begingroup\$ Add links to datasheets please. If you do that once it will save each of us having to search for them. Please don't assume that we are all familiar with every device. \$\endgroup\$ – Transistor Apr 23 '16 at 8:53
  • \$\begingroup\$ I have added the datasheet links \$\endgroup\$ – gaurav bhand Apr 23 '16 at 8:59
  • \$\begingroup\$ look at Test Circuit 1 and the waveform below...that's part of your answer.. then look at the tables to find the information about on and off times. \$\endgroup\$ – Spoon Apr 23 '16 at 10:13

Has anyone tried with MID400 ?

No I haven't, but...

So I would want to know whether really, practically, the MID400 gives a steady HIGH or LOW signal?

... the answer is explained in the Fairchild (now On Semi) Application Note AN-3007 MID400 Power Line Monitor on the IC.

There are several example circuits included. Your answer is that the MID400 can be (but does not have to be) used in a way that its output stays LOW during the zero-crossing of an AC input signal. Read about "Saturated" vs "Unsaturated" modes.

The application note explains that you need to keep the AC input current above 4mA (called Saturated Mode) so that the charge from the photodiode current will leak away slowly enough inside the device that pin 6 will remain a LOW output, even during the zero-crossing of the AC input voltage. See the below extract from the linked application note:

Explanation of Saturated vs. Unsaturated modes from Fairchild (now On Semi) application note AN-3007

(Image source: Fairchild (now On Semi) application note AN-3007)


Both these parts seem to be well described in their datasheets, so there really shouldn't be much question about what they do and how to use them.

The MID400 is specifically designed for detecting AC line voltage, but note that it requires 4 mA to turn on. That means at 240 VAC, a series resistor will dissipate over 950 mW. Yikes!

The PC817 isn't much better with a current transfer ratio of only 1/4. That's really poor, especially when speed is not a requirement.

I recently had to do this and used two FOD817D opto-isolators. The inputs were connected opposite in parallel and the outputs directly in parallel. Those have a minimum guaranteed CTR of 3, which makes them much easier to use in this application. They are also cheap and available. Two of these can often cost less than one fancier opto, especially if you are already stocking them.

In my case I needed the outputs to sink 2.2 mA. You can easily arrange for much less if the signal is only going into a microcontroller on the same board. Even so, I could use 120 kΩ series resistance for a worst case dissipation of 502 mW. For production and stocking reasons, I used 6x 20 kΩ resistors to make the 120 kΩ. That comes out to 56 V and 84 mW max per resistor. I could confidently spec the overall detector as being good for 90-240 VAC, 20-500 Hz.

The output will pulse at twice the line frequency. However, since this is going into a micro, that's no problem. In my case I used a 50 ms debounce time, although you could use less if speed is important and the lower frequency is known to be 50 Hz or just below.

Remember that speed of detecting AC is inherently limited by the cycle period. At 50 Hz, each cycle lasts 20 ms, and each half-cycle therefore 10 ms. At low voltages you may only get a short blip every 10 ms.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.