An optocoupler used for sensing 240V AC with a 3.3v or 5v microcontroller

Please be very careful with mains electricity - it can kill!

Wire it up like this:

220V Live to L
220V Neutral to N

Microcontroller VCC 5V or 3.3V to VCC
Microcontroller GND to GND
Microcontroller digital pin to Out

Then use the button example code to sense the digital pin.