Detect presence of 230v - not measure

Hi Everyone,

I'm looking at using an Arduino for a project and this involves looking for the presence of mains voltage from a number of inputs - for this project its 10.

I've considered using PCB mount packaged AC-DC converters but this gets quite expensive and I was wondering if I could do this with opto-couplers instead?

Can anybody assist me in a schematic that would work - I've seen some basic ones that basically are a resistor and capacitor with an opto but surely some AC-DC conversion would be needed too?

Thanks in advance,

Joel.

Why not small inexpensive reed relays with 240 vac coils. The arduino would just read the relay contact status so fully isolated from the mains voltage.

The relay sounds like the simplest way. Don't forget, read the contacts on the Arduino exactly the same way you'd read a pushbutton.

Using an optocoupler requires either a very large resistor and bridge rectifier, or a small transformer (to step down the voltage) and the optocoupler.

polymorph:
Using an optocoupler requires either a very large resistor and bridge rectifier, or a small transformer (to step down the voltage) and the optocoupler.

Actually not. With this circuit driving an interrupt, the mains cycles can be counted. A 1/4W type for the 1K resistor is more than adequate. For 230V, the capacitor should probably have a 600V rating, and would probably be 0.05-0.1µF.

That is a valid design but it really should utilize a cap that is designed and rated for direct mains connection, not just that it's working voltage is high enough, but that if it does fail it fails in a safe manner.

retrolefty:
That is a valid design but it really should utilize a cap that is designed and rated for direct mains connection, not just that it's working voltage is high enough, but that if it does fail it fails in a safe manner.

I've used general purpose metallized polyester types and they seem to work with no problems. Not sure why they wouldn't be suitable, but I can't disagree, better safe than sorry.

Is there a particular spec or type that should be used?

Is there a particular spec or type that should be used?

I've never actually needed to connect directly to mains with a cap but do recall the safety issue. Perhaps this will explain better then I can from memory:
http://myte.trendsetter.com/images/d/d5/JDI_Safety_Caps.pdf

I had just found these, which are the X2 type.

I've always thought it would be interesting to do some testing on that circuit, simulate a shorted capacitor, etc. :smiley:

Well 168 ma (peak) would make short order on a 1/4 watt resistor but perhaps the led and diode would blow open first. :~

If you can, get James C4S's attention. The dude lives and breaths capacitors. I suspect he can recommend the perfect part. As an added bonus, you would be (indirectly) financially supporting him.

Good tips from retrolefty.

Worst case for that circuit is if it is disconnected when the voltage is at one peak of the sine wave and reconnected when it is at another.

That puts about 170V charge on the capacitor. Plus 170V from the powerline in the opposite polarity, putting 340V on the 1k resistor and 340mA through either the 1N914 or the optoisolator. It might not fail right away.

polymorph:
Good tips from retrolefty.

Worst case for that circuit is if it is disconnected when the voltage is at one peak of the sine wave and reconnected when it is at another.

That puts about 170V charge on the capacitor. Plus 170V from the powerline in the opposite polarity, putting 340V on the 1k resistor and 340mA through either the 1N914 or the optoisolator. It might not fail right away.

What will the current be if the circuit is energized with no initial charge on the capacitor?

Hang on... someone pointed out either here or the Electronics_101 Yahoogroup that the maximum current starting with no charge on the capacitor is actually if you connect right at the zero crossing. I even did an LTSpice simulation, which agreed with him.

If powered up at a peak with no charge on the capacitor, the current should be at about 170mA for a very short time.

But as I pointed out above, the current peak is actually higher, albeit a bit later, if started at the zero crossing. I can't fire up LTSpice right now.

polymorph:
Hang on... someone pointed out either here or the Electronics_101 Yahoogroup that the maximum current starting with no charge on the capacitor is actually if you connect right at the zero crossing. I even did an LTSpice simulation, which agreed with him.

It's actually slightly after the zero crossing. (Think about it, how could there be any current if there are no initial voltages in the circuit and the applied voltage is zero?) It's slightly after, and no larger than the peaks during steady-state. See "sine.png", attached.

If powered up at a peak with no charge on the capacitor, the current should be at about 170mA for a very short time.

LTspice begs to differ, see "cosine.png", attached. Not sure where the 170mA is coming from, I might check my component values.

But as I pointed out above, the current peak is actually higher, albeit a bit later, if started at the zero crossing. I can't fire up LTSpice right now.

Try it with the attached model when you can. It's basically just a simple RC circuit, the diodes actually have little effect on overall circuit behavior.

opto.asc (856 Bytes)

Hi.
If you are going to use an optocoupler then there is a nice explanation under answer #4 at this link:

Still your code has to take care of disappearing input signal during zero crossing and in that case the part with two antiparallel LED's would provide you higher percentage of ON time. It would be also a good precaution to have a board slotted under the optocoupler between high/low voltage side.

Edit: If possible stay far below the maximum rated input current in order to be able to handle at least 1.2kV voltige spikes in the mains lines. Otherwise the thing may be good until the next thunderstorm. If the circuit is "mission critical" then it would be perhaps even better to also include a varistor across the input line.

I said if you -connect- at the zero crossing. I apologize for not being more clear, I did not mean that the max current happens at that time.

I'll take a look at your LTSpice file later, and see if I can find the one I made.

polymorph:
I said if you -connect- at the zero crossing. I apologize for not being more clear, I did not mean that the max current happens at that time.

I think I understand what you meant now, but I still disagree. The initial peak occurs at about 0.9ms, and is actually slightly less than the maximums reached on each subsequent cycle. If I'm still not understanding then I may need a picture :wink:

retrolefty:
Why not small inexpensive reed relays with 240 vac coils. The arduino would just read the relay contact status so fully isolated from the mains voltage.

I am fascinated by this.

Can you give me a link to a reed relay with a 240VAC coil?

Can I interest you in a discussion about some frisky angels and a pin?

If you run a simulation that is sufficiently clever as to factor in the threshold voltage of the LED and the resistor, clearly the current will not peak until there is enough voltage across these two components; we are not talking about a capacitor and a short circuit.

This is however, absolutely irrelevant to the discussion here. A current surge will occur if the circuit is connected while the AC voltage is non-zero and this will be greatest if connected at the peak of the waveform. It will be even more if the capacitor should happen to have a residual voltage in the opposite direction and given a 1k resistor, it is quite easy to calculate the possible peak values. It is equally possible to calculate the time constant of this current surge as 100µs and that the current will drop back to the rated current of the optocoupler within 300µs worst case, so you can make your determinations as to how likely this is to cause damage, accordingly.

Finally, if you are going to count cycles, or merely to determine the presence of the mains, a half wave sensing is just fine.

Can you give me a link to a reed relay with a 240VAC coil?

Well a little goggling is the starting point. Here is one name brand on the first page of search results:
http://www.sourceresearch.com/CategoryLevOne.cfm?CatLevelOne=609&CategoryID=24&CatLevelTwo=275

Size, costs, availability are all things you would have to search out for but I'm sure they can be found.

Also keep in mind any reed relay, even with low voltage DC coils can be adapted by using a small diode bridge and series resistor to convert the 240 VAC to a low voltage current limited DC to operate the relay coil.

retrolefty:

Can you give me a link to a reed relay with a 240VAC coil?

Well a little goggling is the starting point. Here is one name brand on the first page of search results:

My apologies. I was being picky - you apparently didn't understand what I asked.