Using Arduino with high voltages

Here is a circuit that worked very well for me:

For 220V, I'd use a 0.1µF 400V capacitor instead. Note that this circuit is meant to interrupt the MCU at the mains frequency. It's a pretty straightforward interrupt to deal with, but if a simple high/low logic level input were preferred, some RC circuit on the output side of the optocoupler could accomplish that, although there would be a bit of a delay involved due to the RC time constant.