MarkT:
Use a capacitive/resistive dropper to power an optocoupler, not just a resistor, then you don't have
to dissipate lots of heat.A 68nF X-class cap in series with 10k 0.5W (fusible resistor) will bring 240V down to 5mA or so with
only 0.25W dissipation. If the cap fails short the resistor will fuse before the opto-coupler is damaged
(it will take 6W or so and pass 25mA). You must ensure the opto coupler is AC or has a backwards diode across it.Reducing the heat loss is usually important as mains circuitry is enclosed for safety and little cooling
is available. Using the right rated components (like X-class caps) is very important in preventing
risk of fire.A single resistor across the mains is a bad idea as if it fails an arc could envelop it and cause huge
fault currents - having several components in series limits the chance of heavy arc unless something
like lightning is involvedIn evaluating safety assume every semiconductor will fail, rely on passive components if you can.
The datasheet for a fusible resistor should explain the circumstances under which it fails (open) without
causing a fire. Typically 10x -- 30x overload or so. For instance http://www.farnell.com/datasheets/2045763.pdf
Dang, Excellent idea! I should have thought of that -- it's not like I haven't designed, and built, such things!
So, here's a capture of these ideas:
Be sure to configure the Data Pin, that you connect to the Opto, as INPUT_PULLUP!
Thank you to MarkT for catching the pointless 4k7 pull-up to +5V in my previous diagram. As he pointed out, by using the internal Arduino pull-up (20k to 50k), the Opto's internal LED can be driven at much lower current, and thus C1 and R1 get smaller (and probably less expensive)!
And, because the diagram in my original previous post presents a possible fire hazard -- I removed it!
