Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Detecting presence of mains - safely

Status
Not open for further replies.
Hi,
I'm looking to provide an input to a microcontroller which allows it to know when my Economy 7 (cheap rate UK night time electricity with dual meters & a powerCo owned switch) is enabled.
So I need to safely provide either a closed circuit or a 5v output. I'm thinking along the lines of an opto isolator, but don't know how best to drive that from 230V (250V in reality for me).
Main requirements are:
1. Safe
2. Minimal power consumption - it'll run 24*7*365
3. Reasonably inexpensive, but not at the expense of safety, at all.

I'm pretty appreciative of most of the risks of working at different voltages, reasonably competent at electronics, but totally unfamiliar with conmponent design at line voltages. The suck-it-and-see approach I would use at 5v seems innapropriate for this and I felt it better to collate the experience of the wider community.

Thanks in advance.
 
Hi,
I'm looking to provide an input to a microcontroller which allows it to know when my Economy 7 (cheap rate UK night time electricity with dual meters & a powerCo owned switch) is enabled.
So I need to safely provide either a closed circuit or a 5v output. I'm thinking along the lines of an opto isolator, but don't know how best to drive that from 230V (250V in reality for me).
Main requirements are:
1. Safe
2. Minimal power consumption - it'll run 24*7*365
3. Reasonably inexpensive, but not at the expense of safety, at all.

I'm pretty appreciative of most of the risks of working at different voltages, reasonably competent at electronics, but totally unfamiliar with conmponent design at line voltages. The suck-it-and-see approach I would use at 5v seems innapropriate for this and I felt it better to collate the experience of the wider community.

Thanks in advance.

hi,
One method is to use a mains step down transformer, say 240V down to 6V rated at 2-3VA, quite small, rectify the output and sense the DC level on a PIC pin..

You can do it with an opto-isolator with a few extra components to give a 50hZ pulse for the PIC.
 
Thanks Eric. I forgot to mention that I want to mount it within the existing box, so there may not be room for the transformer. For the opto- isolator, would I rectify & then put through a potential divider with the opto led in parallel with the lower resistor (which I guess would be hundereds of times smaller than the upper half of the divider. And if I wanted to turn the 50Hz into DC would it be best to put a resistor on the mains side or the transistor side to smooth it?
 
An opto-isolator will typically use 2VA.

A capacitive coupler can be designed to use 36µA@230V which is only 8.3mVA.

The MCU will see a 50Hz squarewave when the mains is present.

D3 might not be needed if the MCU has an internal protection diode but it's probably a good idea to add it anyway.

Here's an idea but both capacitors must be Y1 rated for safety reasons!

Do not use ordinary 1nF capacitors!
 

Attachments

  • Mains MCU input..PNG
    Mains MCU input..PNG
    1.8 KB · Views: 1,736
My first question to this forum was for an isolated mains indicator (120VAC 60Hz, US specs) My friend, Eric provided the solution, complete with simulation data:
 

Attachments

  • isoLine..gif
    isoLine..gif
    35.1 KB · Views: 860
I've just discovered a potential problem with my idea.

The neutral must be connected to C2 and the live to C1, otherwise it won't work if the DC supply becomes connected to the earth/ground connection which could be caused simply by touching the DC supply.

A simple workaround is to replace D1 and D2 with a bridge rectifier.

EDIT:
I've attached plots of the the circuit, note that the phase shift is nearly 90° due to the phase shift in C1 and C2.

Here's the MCU input voltage shown against the mains on the first circuit I posted.
Mains MCU input S&#1.PNG

Here's the MCU input to the MCU shown for the second circuit when the DC supply is not connected to earth/ground. I've not shown the mains waveform this time but just as the other plot, 0V occurs just afer the input voltage is 90°, when it's at its peak. I'll post a plot with the mains if you're interested.

The waveform changes to look like the one for the previous circuit when the DC supply is connected to earth/ground so the MCU needs to be capable of recognising both waveforms. Putting a 100nF capacitor across R1 smooths the wavefrom enough for it to stay above 4.8V regardless of which waveform is present.
Mains MCU input S&#1.PNG
 

Attachments

  • Mains MCU input..PNG
    Mains MCU input..PNG
    2.2 KB · Views: 752
Last edited:
Thinking about it a little more... I prefer the opto-isolator approach, merely because I understand it better & can be certain of isolation, even in the event of component failure.
Is it possible however to combine both suggestions & insert a bridge rectifier on the output of R1, outputting to the opto emitter - thereby turning it on for both halves of the cycle? I'm assuming I can then add a capacitor on the DC side (if necessary) to give me a continuously high output.
 
Thinking about it a little more... I prefer the opto-isolator approach, merely because I understand it better & can be certain of isolation, even in the event of component failure.
Is it possible however to combine both suggestions & insert a bridge rectifier on the output of R1, outputting to the opto emitter - thereby turning it on for both halves of the cycle? I'm assuming I can then add a capacitor on the DC side (if necessary) to give me a continuously high output.

hi,
If you add a signal diode at the output of my detector, it would be possible to charge a small capacitor to give a DC voltage for the PIC.

If you want to consider that method let me know, I can modify the circuit.
 
Thinking about it a little more... I prefer the opto-isolator approach, merely because I understand it better & can be certain of isolation, even in the event of component failure.
I had a feeling you'd say that and of course it's your decision but I'll briefly explain why my idea is perfectly safe.

Y1 rated capacitors are designed not to fail under any circumstances and if they do, they fail safe, i.e. open circuit.

A Y1 rated capacitor will be designed to withstand an 8kV spike and not be damaged.

Y1 rated capacitors are commonly used to connect the secondary side of switched mode power supply to the mains at high frequencies to remove and RF noise.

The capacitors used in the above circuit are very low value, at 50Hz the impedance of a 1nF capacitor is 3.18MΩ so the leakage current will be 72.3µA (at 230V) which is well under the maximum value allowed to pass the safety standards for domestic appliances in any country.

How the circuit works:

The tiny current through the Y1 capacitors is rectified by the diodes and the diode connected to the 5V supply (D3 in the first schematic, R1 in the second) clamps it to 0.6V over the supply voltage which protects the MCU input from the mains. R1 is simply a pull down resistor which ensures the output on the MCU I/O pin is 0V when the mains connection is removed.

In short the capacitive coupler has the advantage of taking less current from the mains but the disadvantage of requiring special Y1 capacitors.

Here's the final circuit with the smoothing capacitor which provides a continuous high when the mains is connected.

Mains MCU input..PNG

Is it possible however to combine both suggestions & insert a bridge rectifier on the output of R1, outputting to the opto emitter - thereby turning it on for both halves of the cycle? I'm assuming I can then add a capacitor on the DC side (if necessary) to give me a continuously high output.

A bridge rectifier can improve the op-to coupler circuit by reducing the current consumption by half.
 
I used this circuit for a zero-crossing unit to be connected to an ATtiny2313.

You might omit the Schmitt-Trigger.
 

Attachments

  • 0-DETECT-SCH..gif
    0-DETECT-SCH..gif
    13.1 KB · Views: 1,555
hey no need for all these... can you guys check on this circuit.?
it does'nt need a direct link with the mains for operation...!!

check it out..
 

Attachments

  • untitled..pdf
    7.9 KB · Views: 601
  • ckt..pdf
    13.1 KB · Views: 605
Boncuk;
I like your circuit. I'm fond of discrete circuits, even if its only because of nostalgia.
One question: What is the purpose of the capacitor in parallel with the collector resistor?
 
Last edited:
hey no need for all these... can you guys check on this circuit.?
it does'nt need a direct link with the mains for operation...!!

check it out..

How are you going to filter it to make sure it only picks up 50/60Hz and not a signal from a mobile phone?

What protects the CMOS input from static electricity?

Don't get me wrong, you can detect the mains like this, it just needs a bit of filtering.

The problem is, that will just detect whether there's power in the house which might be fine but he might want to check that the mains is physically connected to the circuit.
 
oh...
i used it for many applications..
thought might come in handy for him... but static problem was not an issue because i never touched the sensor and it was placed on the wall for checking.. it works fine with the mains from a distance of 15 c.m. Mobile phone issue.. never thought of that :)..!!
thanks hero..
 
i just read the thread heading and replied that's all.
 
so are you trying get a ac line sense to a battery operated unit??? if so, why???

if not then just bring a resistor across from the AC side of the bridge and clamp it to the power rail. instant line frequency.
 
Boncuk;
I like your circuit. I'm fond of discrete circuits, even if its only because of nostalgia.
One question: What is the purpose of the capacitor in parallel with the collector resistor?

Hi schmitt trigger,

I was in need of a very short pulse to automatically adjust triac firing between 46 and 54Hz mains frequency. The cap takes care of those short pulses.

Boncuk
 
Just another thought.

I wonder if it's possible to make a couple suitable Y1 rated capacitors using a double sided PCB?

Two solid plains on opposite sides of the PCB should have a considerable capacitance and if there's over 8mm clarance between all mains traces and DC side it should be safe, assuming the PCB has a high enough dielectric strength to withstand 8kV spikes, which it should.

Whether this is feasible or not depends on whether the dielectric constant is high enough to make a large enough capacitance to work without using up too much space.

The capacitance would obviously be lower than 1nF so the pull-down resistor (R1 in my schematic) could be increased to 10M.
 
Good idea Hero
FR4 should perfectly capable.
Layout here is key though, no sensitive components should be placed near the "hot" side of the circuit....
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top