Optocoupler 220V to microcontroller
D2 - used to suppress negative impulses after  full-wave rectifier D1
It's seems that both LED1 and input-LED in EL817C assumed to work only by pulses after rectification. And, so, C1 - used as DC decoupler. But! In fact, that C1 is in wrong polarity.
And really I dont understand, why this schematic is so complicated. Meny times, for long years I use schem as below.
              ______  
~220V &gt;--D1--|  U1  |--&gt; MC pin with internal or ext. pull-up
      &gt;--R1--|______|--GND

Where:
D1 - 1N4007 or one of thousand types of rectifier diodes vith reverse voltage about 300V-1000V and forward current from 100mA.
R1 - 0.5W - 1W resistor about 150kOhm
U1 - your EL817C, most famos as PC817C or TLP621
If you whants AC-presents indicator - just add LED in chain D1-Optocoupler-in-R1
Hope, its helpfull.