I’m building a mains sensor that should be able to operate safely at a voltage of up to 650VAC. I’ve already built one before, that operated with 130VAC, which I successfully monitored with a MCU, and printing the results onto the serial monitor on my laptop. Later I built it on a PCB with copper dots, same schematic, but this time I connected it to my dads computer, and guess what, it blew up. But it worked on my laptop (although it was a breadboard version), which is because the laptop is battery powered, right? I UNDERSTAND THAT EXTREME CARE SHOULD BE TAKEN WHILE DEALING WITH SUCH HIGH POWER/VOLTAGE. AND THAT IT CAUSE SERIOUS BURNS AND DEATH! I KNOW IT SOUNDS LIKE I DID NOT TAKE CARE WHEN THE COMPUTER BURNED, BUT IT WAS MY LACK OF KNOWLEDGE. I AM WILLING TO ACCEPT ANY ADVICE YOU GIVE ME. SECURITY IS PRIORITY. Schematic I used I used a bridge rectifier capable of 800VAC 1A. The capacitor is electrolytic 1000uF 16V. The resistors are 2W (I use 4, schematic shows only 2 for simplification) and values are chosen to get specific voltage. So do I only need a Zener Diode or do I need more? Optocouplers?

Edit I want to use this sensing to monitor the voltage and if it goes under the preset value of a pot, it should cut the supply to the device or motor that is connected. Any positive advice is greatly appreciated!😃

  • 2
    \$\begingroup\$ WHY ARE YOU SHOUTING? \$\endgroup\$ – winny Mar 14 '18 at 18:55
  • \$\begingroup\$ Welcome to EE.SE. Why use a zener diode? As an over-voltage clamp? Else you want the output to be 10% or 1% of the input, *0.707 to get the rough RMS value. \$\endgroup\$ – Sparky256 Mar 14 '18 at 18:56
  • \$\begingroup\$ @ElizandroPeters. No need to shout mate. We can hear you just fine... \$\endgroup\$ – Sparky256 Mar 14 '18 at 18:58
  • \$\begingroup\$ Sorry, not shouting though. \$\endgroup\$ – Elizandro Peters Mar 14 '18 at 18:59
  • \$\begingroup\$ The Zener should clamp the over voltage. The output should be 650=3.3V. I want to monitor under-Voltage \$\endgroup\$ – Elizandro Peters Mar 14 '18 at 19:00

I suggest this arrangement using a small transformer with 10:1 ratio. The transformer is used as a current transformer NOT a voltage transformer. It is the reactance of C2,C3 in series with R5*(turns-ratio) that sets the current. You can change R5 to give you a lower voltage e.g 22 ohms will give ~1VAC.

In this arrangement, the transformer probably can be an ordinary 240V transformer, as it is only exposed to ~VAC/2.

Small transformers (eg wall-warts) commonly have a split bobbin arrangement i.e. the windings are side by side with the moulded plastic bobbin between. (rather than wound on top of each other with paper separating. A split bobbin probably has a very good withstand voltage and is ideal.

C2,C3 are split and therefore require less voltage rating.

R6,R7 are shown to limit the current to 25mA (non-lethal) in the event of a total failure of T1.

C2,C3,R6,R7 could all be split into 2 series parts to further improve voltage rating / make them easier to get . (i.e. C2 becomes 100nF+100nF in series)

I leave the voltage sensing to you.

(I have not considered any LC issue with transformer leakage reactance.)


simulate this circuit – Schematic created using CircuitLab


The mains isn't a floating AC source, one side of the mains (the "neutral") is tied to the general mass of the earth and to the protective earth connection on your socket.

Your laptop most likely is floating, it is certainly floating when running off batteries and is probablly floating even when plugged in (most laptop power bricks are floating output).

Your dads desktop on the other hand most likely has it's ground line tied to the protective earth on your socket.

Now look at those diodes on the left side of your schematic. When you plugged the device into your dads desktop then on the negative half cycle of the mains current flowed.

  • From the protective earth connection on the desktops plug.
  • Through the desktop's power supply to the DC ground of the desktop.
  • Through the ground line of your signal cable to your board.
  • Through one of the diodes on the left of your scehematic.
  • Back to the mains.

The current flow would have been substantial. Likely the resistance of the path was less than an ohm leading to an initial current over a hundred amps.


Your laptop is floating, so there was no bang but there would have been a significant electric shock hazard if you touched a metal part of the laptop at the same time as touching something protectively earthed.

So you want to build a mains voltage monitor that doesn't blow things up. There are a few of approaches.

  1. Use a transformer up front, to both isolate the mains and reduce the voltage to a safe level.
  2. Use a linear optocoupler in combination with a capacitive dropper.
  3. Make your circuit referenced to the mains and then isolate it's signal lines using optocouplers.

All are feasible in general. The first is probablly the easiest and safest for a beginner as the only thing connected to the mains is the transformer primary. The downside is that the upfront transformer is likely to be relatively bulky and expensive.

The issue with the second approach is that gain repeatability of optocouplers is apparently poor, you can work around this by "servoing" them but that comes at the cost of much more complex circuitry on the mains side.

The issue with the third approach is that you have a bunch of circuitry on the mains side. This circuitry will need to be powered (more components) and programmed (be careful you don't create a hazard by connecting the programmer).

  • \$\begingroup\$ Is there a way to isolate the already posted picture of the schematic? \$\endgroup\$ – Elizandro Peters Mar 14 '18 at 20:00
  • 1
    \$\begingroup\$ The simplest way would be to insert a transformer between the incoming mains and the rest of the schematic. This would also allow you to work at a lower voltage making the whole system easier to work on. \$\endgroup\$ – Peter Green Mar 14 '18 at 21:16
  • \$\begingroup\$ Downside is you would need to find a transformer with a primary rated for your highest working voltage, not sure what the cost/bulk on transformers with 600V primaries is. \$\endgroup\$ – Peter Green Mar 14 '18 at 21:22

A simple, safe way to do this is using an optocouple.


simulate this circuit – Schematic created using CircuitLab

EDIT: Added a transient protection resistor, as per Peter's advice.

The antiparallel diode is needed because the reverse breakdown voltage of LEDs is generally only in the 5V range. It may be a 1N4148, which has a reverse breakdown voltage of 50V only, because they protect each other.

The 100nF capacitor limits the current to 8mA@230V~50Hz, enough for the optocouple. It has to withstand about 1.5 times the mains voltage. Also, if your mains voltage is higher, you need a smaller cap.

  • 2
    \$\begingroup\$ That works if you just want to detect on/off. It's not so good for detecting undervoltage. Also you want a resistor in the circuit to prevent transiants frying your LED. \$\endgroup\$ – Peter Green Mar 14 '18 at 19:14
  • \$\begingroup\$ Can a optocoupler with integrated photocell be used to sense the amount of voltage instead? I want an analog voltage to be read. \$\endgroup\$ – Elizandro Peters Mar 14 '18 at 19:18
  • \$\begingroup\$ You have to use an optocouple with a defined CTR then. The current through the transistor then reflects the current through the LED (times a factor). As the LED current depends on the mains voltage, that would work as long as you stay within the linear range of the LED. The only problem you have is your output also varies with the mains phase. You have to detect the maximum or average the signal with a low-pass filter. \$\endgroup\$ – Janka Mar 14 '18 at 19:27
  • \$\begingroup\$ An AC opto-coupler would offer double the ripple rate, if it is to be converted to DC. \$\endgroup\$ – Sparky256 Mar 14 '18 at 19:33
  • \$\begingroup\$ Any suggestions which one? \$\endgroup\$ – Janka Mar 14 '18 at 19:34

This is a bit off topic, but relevant to what is going on with laptops being connected to measurement circuits. Laptops are a real traps for young players when you hook them up to an analog circuit.

A slightly simplified schematic of a laptop supply shows the totally counter-intuitive capacitors that are straight across the transformer. C1,C2 form a voltage divider that floats the laptop at 115V (when you are in a grounded-neutral mains system). These are the fat blue disc capacitors when you open up a laptop psu. (They are there so that RF energy can flow back out to the low impedance mains to get rid of it)


simulate this circuit – Schematic created using CircuitLab

If you connect the laptops ports to anything grounded, several hundred microamps with flow through the ground/microphone/usb/data wire. There will be 115V available to force it to flow, if the connection happens to be a high impedance and poorly protected IC input.(Goodnight Nurse), or you get incurable hum in audio circuits (ground-loop)


(I'm an idiot - didn't read the 650V part, excuse me, but I will leave this if anyone is interested)

This is a voltage->time arrangement. Opto is only on for the upper part of the half cycle. Measuring the on time of the opto lets you work out the voltage. This is applicable to brownout sensing, but does not let you measure right down to 0V

This circuit uses the 3 terminal pseudo-zener IC TL430. It will have an accurate voltage threshold, and clean turn on of the opto.

TL430 conducts when the reference goes above 2.75V. With R1/R2 divider, the opto turns on at approx 232V. The peak voltage is 325V. So the time the opto is on, is a function of the peak voltage. The opto is on for the upper part of one half cycle.

R5,6,7 have fairly high values. These limit the current to ~20mA in the event of a failure of the opto - this is a non-lethal current for humans, and is a secondary protection.

R3 limits the inrush current. When you plug the circuit in at the worst time the voltage will be 325V and momentary current will be 325/12k=27mA

Note: I have not specified the opto type, and therefore its Current Transfer Ratio (CTR). CTR must be known to set the R7 (and R5), and to set the LED current (C1, R3)


simulate this circuit – Schematic created using CircuitLab


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.