Delay pulse (trigger) for a variable delay respectively to 0-5V input
simulate this circuit &ndash; Schematic created using CircuitLab

Figure 1. A rough layout of the standard way of controlling the triac. The schematic does not show the details of the triac snubber circuit.

How it works:


R1 / C1 provide a filter for the PWM input to convert it to a zero to 5 V analog input.
The micro resets a timer on every zero cross.
The output is switched on some time after the zero cross. For a 0 - 1023 analog input we can just take the input value and multiply by 10 to get the required number of microseconds delay to turn on the opto-triac.
The opto-triac provides the required electrical isolation between the microcontroller and the mains.


Do not take short-cuts with mains isolation. Do it properly or injury to personnel may occur or damage to equipment. Screw stuff into an insulated box. Terminate wires properly. Use fuses.