# Safety design on mains detector

I've designed a simple mains detector which I have drawn below. The theory of operation is pretty simple. A capacitor is used to reduce the current so that my optocoupler can operate (represented by the LED below). With LTSpice, I get a nice sine wave @60Hz with ~3.5mA. I have omitted the other side of my opto for simplicity's sake. Now I'm interested in doing some safety analysis.

The first thing that comes to mind would be to add a high resistor in parallel with the capacitor to reduce the risk of someone getting a discharge from the capacitor, but I've purposely omitted that because it would burn a lot of heat and ultimately I can put this whole thing in a place where no fingers should be reaching it. The fuse should protect me against the case where the capacitor fails with a short. An open circuit would simply fail nicely. Any other thoughts I may have missed in my safety design?

simulate this circuit – Schematic created using CircuitLab

• (1) Put your fuse in the live wire rather than in neutral. (2) Check in your simulator what happens if you switch on the mains at 90° into a cycle (peak voltage). I suspect that you will get a very high current spike through the LED. (3) Do your calculation on power dissipated in your high value capacitor discharge resistor. You can make its value high enough that it's not a problem. Sep 7, 2018 at 9:35
• Your device should be able to handle quite high voltage spikes between live and neutral, few kilovolts are typical EMC requirements, so some transient protection is a good idea. Sep 7, 2018 at 11:00
• What opto-coupler have you chosen? Sep 7, 2018 at 11:53
• I've chosen the 4N37 in this case and yes the C1 is a 7kV X2 cap which should handle the spikes. Does it mater where the fuse is? I'd love to understand the reasoning :) Sep 9, 2018 at 7:45

## 2 Answers

The first thing that comes to mind would be to add a high resistor in parallel with the capacitor to reduce the risk of someone getting a discharge from the capacitor, but I've purposely omitted that because it would burn a lot of heat and ultimately I can put this whole thing in a place where no fingers should be reaching it.

Bad idea. If this is a pluggable device (not permanently wired to the mains), then anyone can touch the two prongs of the plug and get a discharge from the capacitor. And in any case, a 1MΩ resistor, which would discharge the capacitor in a fraction of a second, would only dissipate 15 mW @ 120VAC in normal operation. (Pay attention to the voltage rating of this resistor — use multiple resistors in series if necessary.)

Second, as Transistor pointed out in the comments, the capacitor limits the current at 60 Hz, but has little effect on higher frequencies, including those produced during switch-on, as well as fast transients on the line caused by nearby lightning, other equipment switching, etc. Such currents might blow your fuse, but not before destroying your LED.

So, at a minimum, I would suggest:

• Add the 1MΩ resistor in parallel with the capacitor
• Raise the series resistance (R1) to 10kΩ (it will dissipate about 130 mW in normal operation)
• Raise the value of the capacitance (C1) to 100 nF in order to compensate for the increased drop across R1.
• Thanks for the reply. I tried making the suggested changes and it seems a little problematic. According to my spice simulation anyhow, the 1M resistor would burn around 31.5mW (it would be connected to the main where no fingers could touch it - still dangerous if someone opens the box). When I make the other suggested changes, the 10k resistor starts to take 385mW which is pretty darn high. Would you mind explaining how you arrived at 10k? BTW: I'm planning to use a 4N37 opto for this project. The other side is a simple pull-up GPIO detection circuit. Sep 9, 2018 at 7:42
• First of all, 31.5 mW is NOT dangerous in any way. The 10K resistor has the same RMS current as the LED flowing through it, so I don't see how you're getting 385 mW (6.2 mA). I picked 10k based on keeping the LED current the same as your original design (3.7 mA) and the dissipation around 125 mW -- approximately half of the rating of a 250 mW resistor. Sep 9, 2018 at 12:13
• Ah I just realized my mistake. I was testing and using Spice to calculate power dissipation and realized now that my voltage was set at RMS instead of peak while LTSpice requires Peak. Yes your math is indeed correct. Now that I'm fixing everything, I realized that I need 2.6mA (not 3.X) which makes my choice of C1 & R1 appropriate now. That makes R1 dissipate roughly 1.4mW and adding a parallel resistor would add ~14mW which is low enough. Sep 10, 2018 at 7:00

This is something like what I made in 1975 as a " green weeny" grad. (What we were called).

I quickly read all the Mil Stds on passive components characteristics to dispel the title. ( plastic X vs Y rated, ceramic, NPO vs XR7, electrolytes, ferrite, crystals etc.)

• Take note the 1M act as 250V rated bleeder Rs and the 1K act as fuses and it was only rated for about 4x Vpeak inductive 100us transient and about 3kV lightning powerline transient or PLT (1~10us).
• Surface creepage is critical with a 2.5 to 3mm air gap between AC and DC onm FR4 (G10 back then)

simulate this circuit – Schematic created using CircuitLab

An X cap is line to line rated plastic film cap that wont short out, but I used R's as a fuse.

• You can raise C1 to 300nF for 30mA peak half wave. Sep 7, 2018 at 14:50
• If you raised C1 to 300n however, you would need some dissipate a lot of power through your resistors. It would have to go from ~9mW to ~1W (Total - 3 resistors). Sep 9, 2018 at 7:55