enter image description here

I want to design a simple circuit to monitor AC mains voltage and take simple decisions if the voltage falls below a specific reference voltage.

It's important to mention that accuracy isn't an issue at all.

Circuit description : The input voltage is stepped down to 9 V peak voltage and rectified, the rectifier plus the capacitor is intended to act like a peak detector and the output voltage at C1 would represent the peak input voltage (of course after stepping down).

This voltage is scaled via R1 and R2 then compared to a reference voltage using hysteresis comparator (using LM358 but not found in ltspice).

Is this a valid concept ?


2 Answers 2


For reference and to protect against future edits, here is your circuit that will be discussed:

The basic idea is OK, but there are some things to consider:

  1. Powering the opamp from the same signal you are trying to measure is asking for trouble.

  2. I don't like how this circuit looks at peaks instead of more a average. Ideally you probably want RMS, but that's difficult to do. You know the voltage is mostly a sine, so the average tells you what you need to know.

    The problem with grabbing peaks is that it's quite susceptible to noise. You're only getting information from the waveform at two points each cycle. This means you have little opportunity to filter out noise.

    Worse yet, the susceptibility to noise is non-linear. One positive glitch at a peak will make the measurement read high for quite a while. A single negative glitch at a peak will go largely unnoticed.

    Put a resistor before the capacitor so that you get low pass filtered absolute value, not recent max peaks.

  3. You may not need a opamp or comparator at all. If the output of OP07 is going into a microcontroller, then you might as well feed the filtered and clipped analog signal to the micro directly instead. The micro can trivially compare the result to some threshold in firmware. Then changing the threshold is a firmware change, not a hardware change.

  • \$\begingroup\$ I'm sorry but I'm kinda lost at the "clipped" voltage thing, You said that I may not need an op-amp at all if the output of OP07 is going to a microcontroller, how is that? the OP07(in the schematic) is supposed to be the comparator and its output would be my output digital signal. and what do you mean by the clipped voltage in the circuit? (my mind goes to clipping circuit using zener diodes.) I know i have missed something so please hold out my ignorance :D . \$\endgroup\$
    – iMohaned
    Commented Jun 30, 2017 at 23:15
  • 1
    \$\begingroup\$ @iMo: I mentioned clipping to protec the rest of the circuit from unusual but large voltage spike. Those sometimes happen on power lines. I was suggesting that if your digital signal would go into a micro, feed the analog signal into a A/D input of the micro, then the rest is firmware. Some micros have comparators built in too. You can arrange to scale the rectified and filtered AC signal so that the threshold is about the midpoint of the micro's power supply, then feed such a midpoint signal into the other comparator input. \$\endgroup\$ Commented Jun 30, 2017 at 23:30

EDIT: The question now mentions a transformer, so this answer is somewhat unfitting.

Your circuit hasn't potential separation so it's a safety nightmare. Experienced engineers can build such things safely but there has to be some justifaction to do so, e.g. a self-contained circuit in a extension lead not heaving any connections to outside but 120/230V circuits anyways.

I recommend you to make the 120/230V part as simple as possible, and put the whole other circuit behind an optocouple.


simulate this circuit – Schematic created using CircuitLab

The values 1kΩ, 100nF of the RC pair depend on the CTR of the optocouple you are using. Pick the correct voltage range and power rating. The 1MΩ resistor is there to discharge the capacitor when the device is unplugged, it's uncritical. Pick the correct voltage rating for the rectifier, too (your 1n914 aren't useable for mains voltage.)

Don't even think of leaving the fuse out!

The current through the photodiode (or phototransistor) follows the current through the LED, but safely seperated. As that one depends on the mains voltage, you can measure it that way.

  • \$\begingroup\$ I'm using a 220 V /9 V transformer for isolation, is that what you mean? \$\endgroup\$
    – iMohaned
    Commented Jun 30, 2017 at 20:08
  • 2
    \$\begingroup\$ I don't see that transformer in your circuit. But yes, that would make the thing safe, too. \$\endgroup\$
    – Janka
    Commented Jun 30, 2017 at 20:10
  • \$\begingroup\$ Janka, actually the two conducting diodes among the bridge together with forward biased LED clamp voltage at bridge AC connection around a few volts peak. That's diodes VRM called for. \$\endgroup\$
    – carloc
    Commented Jun 30, 2017 at 20:12
  • \$\begingroup\$ I've edited the question to mention the transformer clearly. \$\endgroup\$
    – iMohaned
    Commented Jun 30, 2017 at 20:13
  • \$\begingroup\$ @carloc: yes, I thought about that, too, but it's not safe to rely on clamping. (But then, when the LED burns out, we may give up all hope and let the rectifier burn out, too?) \$\endgroup\$
    – Janka
    Commented Jun 30, 2017 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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