You casn use a standard optocoupler with its diode connected to 220V through a capacitor (searchg this forum on how to connect a LED to 220V) or you can employ a very small transformer to step down voltage, which after rectification can be directly fed to a microcontroller. Both methods are safe as both ensure mains isolation.
Regards,
IanP