My English not so good, sorry. I say about low voltage on Atmega. There should be not less than 3.3v. If it is less then may not be enough current to open the optocoupler.
D1 i not problem. The zero crossing detect works correctly. You see it on LEDs.