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.
