## how to sense 220v input -solved- I hope

rosomak
Posts: 3
Joined: Thu Sep 05, 2013 8:06 pm

### Re: how to sense 220v input -solved- I hope

Another cheap and small.
Attachments
LTV-814A.png (9.28 KiB) Viewed 15430 times

Mortimer
Posts: 914
Joined: Sun Jun 10, 2012 3:57 pm

### Re: how to sense 220v input -solved- I hope

Is the power rating of the resistor high enough? I don't think so.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

[email protected]
Posts: 1991
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

### Re: how to sense 220v input -solved- I hope

Mortimer wrote:Is the power rating of the resistor high enough? I don't think so.
Indeed. Especially as this was "solved" months back!

Needing a brain diversion this morning, so I'll do the calcs...

The data sheet for that opto isolator suggests 20mA at 1.2v for the LED side, so to drive that from 230v you need to drop 228.8v. R = V / I -> 228.8 / 0.020 = 11400Ω. Power dissipated: P = IV -> 0.020 * 228.8 = 4.58 watts.

So that ¼watt resistor will overheat and burn out (although it's 100K in your diagram, not the 12K actually needed to drive the LEDs) Using a 100K resistor reduces the current through the LEDs to ~2mA which may not be enough to actually light them up. (and will still dissipate over ½ watt)

So, with the 12K resistor to drive the LEDs properly, it's going to draw more power than a Pi draws - just to sense mains...

There is no easy solution though - as all the above messages testify to. Cheap and cheerfull (and arguably safest) is an old "wall wart" producing 5v which you can drop via a pair of resistors to 3.3v - however that's still going to idle away at 1-3 watts, depending on the design. (And may maintain output voltage with no load for many seconds, even minutes after power goes!) The next best solution is the R+C dropper but you need to get the soldering iron out then.

I don't think the original poster actually gave many more details of their setup or actual needs, but one thing I'm looking at shortly is using a Pi as a burglar alarm in a remote shed and also having it sense the mains and auto-switch to battery when it fails (rural location) - that makes it slightly easier for me as I can take a low-voltage output from the mains fed power supply which is feeding the Pi & charging the battery. (The Pi's doing a lot more than just an alarm, else an ATmega would be much more suitable, but since the Pi is there anyway...)

-Gordon
--
Gordons projects: https://projects.drogon.net/

rosomak
Posts: 3
Joined: Thu Sep 05, 2013 8:06 pm

### Re: how to sense 220v input -solved- I hope

Mortimer wrote:Is the power rating of the resistor high enough? I don't think so.
Its working fine for 6 months, constantly powered up. No heat at all.

rosomak
Posts: 3
Joined: Thu Sep 05, 2013 8:06 pm

### Re: how to sense 220v input -solved- I hope

[email protected] wrote:
Mortimer wrote:
So that ¼watt resistor will overheat and burn out (although it's 100K in your diagram, not the 12K actually needed to drive the LEDs) Using a 100K resistor reduces the current through the LEDs to ~2mA which may not be enough to actually light them up. (and will still dissipate over ½ watt)

-Gordon
1mA its enough to make them working fine.

I use that circuit in my project.

[email protected]
Posts: 1991
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

### Re: how to sense 220v input -solved- I hope

rosomak wrote:
[email protected] wrote:
Mortimer wrote:
So that ¼watt resistor will overheat and burn out (although it's 100K in your diagram, not the 12K actually needed to drive the LEDs) Using a 100K resistor reduces the current through the LEDs to ~2mA which may not be enough to actually light them up. (and will still dissipate over ½ watt)

-Gordon
1mA its enough to make them working fine.

I use that circuit in my project.

100K @ 230V - assuming worst case - the LED is shorted will pass I = V / R -> 230 / 100000 = 2.3mA.

Power dissipated: P = IV -> 0.0023 * 230 = 0.529 watts.

You really should have a 1 watt resistor there, not a ¼ watt one.

You're getting away with it - for now, but you have something that's potentially a fire risk at lethal voltages.

-Gordon
--
Gordons projects: https://projects.drogon.net/

PiGraham
Posts: 3415
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

### Re: how to sense 220v input -solved- I hope

This is only a rough sketch, but it should allow detection of mains with low dissipation. Posted for discussion.
Mains detector_schem_s.png (52.38 KiB) Viewed 15338 times
R1 is not matched to the opto, which was just plucked from the Fritzing library.

To read the state use GPIO change callback to restart a 100ms timer. When you want to test for mains test if the timer is active or timed-out. If it's running the mains is on and >200 Vac.

tenochtitlanuk
Posts: 155
Joined: Fri Jul 06, 2012 8:51 pm
Location: Taunton, Somerset, UK
Contact: Website

### Re: how to sense 220v input -solved- I hope

Must say that the general level of electrical knowledge of many users of the Pi forums is abysmal. Most seem convinced a 5V 2A psu will somehow push 2A through anything connected...

I recently took the trouble to disassemble a mains ( 240V) LED lamp. Instead of a resistive current limiter with attendant power loss, it limits the current by using a suitably rated series 1uF 400Vw capacitor. Reactive impedance 1/( 2 pi f C). There's a bleeder resistor across it of 1M. No I-squared R power loss- just a phase shift.
This feeds a 4-diode bridge rectifier, 'smoothed' by a 1uF electrolytic, and then the LED chain ( series/parallel).
Only problem is that the bayonet plug base is non-polarised, so you have a 50-50 chance that the live feed is only one diode drop away from touchable contacts ( many of these bulbs have no plastic or glass cover.... heaven only knows if that is widely known!

Since this bulb brightness is equivalent to a 50W tungsten filament lamp, a MUCH lower capacitor could be used to detectably light a LED or switch an optocoupler.

PiGraham
Posts: 3415
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

### Re: how to sense 220v input -solved- I hope

If you only want to detect if mains is on you don't need full wave rectification or smoothing and can use fewer components.

tenochtitlanuk
Posts: 155
Joined: Fri Jul 06, 2012 8:51 pm
Location: Taunton, Somerset, UK
Contact: Website

### Re: how to sense 220v input -solved- I hope

Yes- as I implied.
The idea is to avoid losses- hence a series cap. is easiest. No resistors. Cheap diode paralleled across LED to catch the 'reverse' phase. Cheaper than a lossy zener..

hampi
Posts: 223
Joined: Fri May 31, 2013 11:29 am
Contact: Website

### Re: how to sense 220v input -solved- I hope

I was thinking about capacitive sensing too, but then it still needs a ground (neutral) connection if I understand correctly. Or is the circuit self-capacitance (or displacement current) enough?

PiGraham
Posts: 3415
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

### Re: how to sense 220v input -solved- I hope

tenochtitlanuk wrote:Yes- as I implied.
The idea is to avoid losses- hence a series cap. is easiest. No resistors. Cheap diode paralleled across LED to catch the 'reverse' phase. Cheaper than a lossy zener..
Yes, a series cap is a good solution, but the lossy zenner is only lossy for a small part of the cycle (a few microamps reverse leakage for most of the cycle) , so average dissipation is low. Keeping the coupler LED lit for the whole cycle is unnecessary.

I'll calculate dissipation later.

pointy56
Posts: 3
Joined: Mon Jun 04, 2012 6:07 pm

### Re: how to sense 220v input -solved- I hope

You might want to consider using the HCPL-3700 Logic Interface Opto-Isolator as an alternative - it combines a bridge rectifier, opto-isolator and a Darlington in a single package that can be configured using a couple external components to switch a logic output at various voltage levels, AC or DC. To sense 230V mains voltage I use two 27K 2 Watt resistors and a 22uF 16V electrolytic - this switches reliably at 160V RMS. The HCPL-3700 itself can be run off 2V to 18V, and I have used it successfully at 3.3V, 5.0V and 12V.
From my point of view a significant benefit is that the whole thing can be built on a small piece of prototype board (e.g. Vero) and one or more can be sealed in a small box with potting compound to avoid any mains isolation problems.

Here's a link to the manufacturer website:

http://www.avagotech.com/pages/en/optoc ... hcpl-3700/

Application Note 1004 (available on the website) gives much more information on how to use the device.

Hope this helps.

Martin

nullx8
Posts: 20
Joined: Wed Jan 15, 2014 1:33 pm
Location: Bangkok, Thailand
Contact: ICQ Website Yahoo Messenger

### Re: how to sense 220v input -solved- I hope

just our of couriosity,
aren't there optocoupler's avaiable hold the Balast and capacities already inside the chip ?
for a more straightforward setup ?

i did some short digging but found nothing so far ..

runfastman
Posts: 10
Joined: Thu Oct 18, 2012 1:12 am

### Re: how to sense 220v input -solved- I hope

anddr wrote:http://www.simple-electronics.com/2012/ ... rface.html

I used the resistor values from that site, threw away the 4N25 and transistor for a H11AA1, and voila!

Works really well on my Arduino, to use it on RPI just feed it 3.3v instead of 5v.
Why did you replace the 4N25 and transistor with a H11AA1?
Did you keep the D1 diode? It looks like the specs of the H11AA1 has a diode for both directions unlike the 4N25.

ratbagz
Posts: 1
Joined: Fri Jun 13, 2014 6:44 am

### Re: how to sense 220v input -solved- I hope

if you want simple ,i am a sparky and i have been for over 35 years and i think all your solutions to complicated if i was asked to provide a indication of 220v supply to a plc . i would use a simple hold in contact

when 220v is present the contacts are closed and supplys 3v or what ever voltage is required to indicate supply
Attachments
simple.jpg (22.93 KiB) Viewed 13901 times

Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

### Re: how to sense 220v input -solved- I hope

Why don't you use a current transformer and detect a load?

\$1.50 for the transformer
another \$1 in parts.

You can't get more isolated than a complete air gap.

56000 series from Murata
Attachments
zero-loss-ttl-adj-gpio.JPG (21.54 KiB) Viewed 13842 times
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:

cregganna
Posts: 1
Joined: Sun Oct 27, 2013 1:34 pm

### Re: how to sense 220v input -solved- I hope

I agree with Richard-TX - I prefer no connection with the mains voltage and I was thinking of adapting something I built from Everyday Practical Electronics mag 2004/04 issue. It uses a fly wire that you wrap around the mains cable, a darlington pair and a bit of smoothing to provide a 0 or 1 signal to drive the reset signal of a Timer IC.

Have been reading up on Current Transformers and it seems that because there are so many turns you have to be careful with the induced current and make sure that you always have a load connected. This scares me and a fly wire / darlington pair only requires a few turns so the currents induced are negligible. The good thing about the CT is that it is nicely packaged - but you have to break the mains wire to run it through the center.

My application is a heating system monitor. The control board is all mains signalling through relays. I have built a display panel with simple mains LED signal lamps and intend to wrap fly wires around their leads - a bit worried about cross talk between the fly wires.

Please note I am novice level with electronics. Any experts please step in with comments / corrections.

Attached is a portion of the circuit from the mag - copyright is Everyday Practical Electronics http://www.epemag3.com/.
Attachments
CCI05072014.jpg (43.09 KiB) Viewed 13347 times

Phil_S
Posts: 1
Joined: Mon Apr 06, 2015 8:04 am

### Re: how to sense 220v input -solved- I hope

Reference the relay solution by ratzbag.

The diagram proposed is not a "hold-in" contact in the accepted sense (coming from industrial control panel design background).
A hold-in contact refers to a self-latching method of wiring an additional N/O contact on a relay that closes when the coil is activated and maintains the coil supply when the initial coil activating voltage is removed. It is a neat way of controlling things like pumps with high and low level float switches so that the pump runs when the high level is reached (or vice versa) and stays running until the low level switch is reached (or vice versa). So, the hold-in solution needs at least two sets of contacts (DPCO), one for latching, the other to signal.

I suspect that most of the solutions here are specifically designed to do away with relays and all the problems of contact bounce, snubbers etc. In any other situation where a micro is not involved, the relay would be fine

4est
Posts: 3
Joined: Mon Jan 16, 2017 7:12 pm

### Re: how to sense 220v input -solved- I hope

rosomak wrote:Another cheap and small.
rosomak, thanks for the ideea. I did a 8 channel 220V sensor. I used LTV-844, because it has 4 channels (2 pcs)

https://goo.gl/photos/CUMet74d181U45779

https://goo.gl/photos/8FpXU61kd9DUzCLUA

Mortimer
Posts: 914
Joined: Sun Jun 10, 2012 3:57 pm

### Re: how to sense 220v input -solved- I hope

Nice chip, but I wouldn't be happy about using stripboard at mains Voltages for anything other than prototyping. I don't think the clearances on stripboard are adequate for long term use.
--------------
The purpose of a little toe is to ensure you keep your furniture in the right place.

4est
Posts: 3
Joined: Mon Jan 16, 2017 7:12 pm

### Re: how to sense 220v input -solved- I hope

one one side I have mains, and on the other low voltage, but the 2 are separated by quite some space.
Only L/N are not very well separated, but I think at worst the mains fuse would jump

rurwin
Forum Moderator
Posts: 4248
Joined: Mon Jan 09, 2012 3:16 pm
Contact: Website

### Re: how to sense 220v input -solved- I hope

Whenever I use stripboard for mains I always remove at least one full track between live and neutral and I make sure to break the live and neutral tracks with wide gaps so that they are as short as I can reasonably make them. The low voltage stuff is in a different part of the board and those tracks are cut before they reach the mains area. That makes it fairly safe but it is still an electrocution risk if you handle the board. A better methodology is to use rail- or chassis-mounted equipment for all mains wiring.

4est
Posts: 3
Joined: Mon Jan 16, 2017 7:12 pm

### Re: how to sense 220v input -solved- I hope

well, this is my first strip board design

However it will be mounted in the main electric panel, so this takes care of electrocution risk.

jimbo72
Posts: 4
Joined: Thu Feb 07, 2013 11:27 am

### Re: how to sense 220v input -solved- I hope

Hi all,

I am stupid in electronics, and my english is bad, then sorry for that !

I give a try to LTV-844 (because I need 4 channels).
(The 100K resistor is a 1W to be safer...)

What shall happen ?! I was assuming that if 220V is there the GPIO should be at ground, while if no 220V gpio should be at VCC, right or not ? Or the GPIO shall detect something else ?
I did it with a 5V VCC because I planned to plug it to an arduino... Can it be a problem ?
Because I always get GPIO at 5V if 220V at input or not.