Thanks to the suggestions, I modified my circuit, hopefully making it a bit safer
I'm having trouble choosing R6 though, in the datasheet for the triac (L4004L3), this one datasheet
Igt = 3mA, so if I calculated the resistor value for peak voltage and 30mA current
R = Vpeak/I = 230/30mA = About 8k
But now lets say the triac is triggered when the AC voltage is 10V
I = V/R = 10/8k = 1.25mA
But since Igt is 3mA, the triac wont turn on
If I try choosing higher currents, the resistor power increases
Right now it's sitting at
P = I^2 * R = 0.03^2 * 8k = 7.2W peak power
And also whats the minimum current needed to turn the photocoupler on or activate the other side ?
For R2, I calculated it this way, for a chosen current of 10mA
R2 = Vpeak/I = 230/10mA = 23k
For R5, chosen current 10mA. I think the max the MCU can source is around 20mA
R5 = (V-Vled)/I = (5-1.2)/10mA = 380 ohms