unorganized zero crossing signals

Hello evryone, I am doing an end of study project and I have reached a point where I find myself with a problem whose cause I did not understand,I searched on google and I did not find clear answers on this subject.

I made a circuit of a zero crossing detector whose optocoupler is a 4n35 to control an optotriac "MOC3021" connected with a triac "BTA16" by the arduino, but when I visualize the detections I noticed that they are not periodically regularly as shown in the photo I think there are passages not detected.

the circuit is the same of this one just in the middle of the 55k resistors I put 47k and at the output of the rectifier bridge I put a 1.5k resistor.
C:\Users\Abdelghani\Desktop\picters
the code and the inputs from 4n35:

void setup() {
pinMode(2,INPUT);
Serial.begin(115200);
}
void loop() {
Serial.println(digitalRead(2));
Serial.print(" ");
}

I put the resistors without calculating just I looked at the circuits on google whose characteristics of the optocouplers are nearly the same of those of the 4n35, I think there is an error at the level of the resistors in addition I noticed that these heat up too much.

with this unorganized detection cycle, I tried a simple experiance with the code below where I sent an ammorassage angle of 1/4 of the full period "0.25 * 10 (ms) = 2.5 (ms) = 2500 (µs) "but finally the lamp illuminated 100% !!

void setup() {
attachInterrupt(digitalPinToInterrupt(2),aa_commande,FALLING);
pinMode(3,OUTPUT);
}
void loop() {

}
void aa_commande()
{
digitalWrite(3,HIGH);
delayMicroseconds(2500);
digitalWrite(3,LOW);
}

so i block here and i don't know where exactly the error is, so i'm waiting for yours answers, and thank you very much in advance.

How is anyone supposed to see something on YOUR C: drive ?!

i'm really sorry i'm new here

void aa_commande()
{
 digitalWrite(3,HIGH);
 delayMicroseconds(2500);
 digitalWrite(3,LOW);

You're immediately writing a high and triggering the TRIAC. You have to delay before triggering the TRIAC.

The logic should be:
Delay (depending on the dim level)
Write a high to trigger the TRIAC.
Maybe another short delay (to make sure the TRIAC gets triggered).
Write a low and wait for the next interrupt/trigger.

yes I tried this code as you said but got the same result the lamp always illuminates 100%

You are probably missing the pulses in the first sketch because they are too short - shorter than the Serial.write(). The interrupt should see them all.

Show you test code using what DVDoug suggested. He linked your own (wrong) code, not the right one.
Also the brightness difference between 100% and 25% is probably not so great. How do you "measure" it?
A non-dimmable LED bulb cannot be dimmed by any means (at least the one I have tried). It is either fully on, or fully off. If you do not provide enough power it blinks.

You have no resistors in either of the LEDs in the opto coupler or optically coupled triac. This might have already damaged them.

hi everyone thank you very much for your answers and explanations, but finally the circuit is correct the problem is that I have not understood the interrupt algorithm until now I tried this program and everything works fine.

void setup()

{

pinMode(3,OUTPUT);

attachInterrupt(digitalPinToInterrupt(2),aa_command,FALLING);

}

void loop()

{

}
void aa_command()

{

delayMicroseconds(5000);

digitalWrite(3,HIGH);

delayMicroseconds(10);

digitalWrite(3,LOW);

}
in my head I understood that we trigger the triac we wait for the time of the amorssage angle we want (ON) and after we extend the triac, the time after will automatically be one (OFF) until the next interuption like this code:

void loop()
{
// the triac is blocked

}
void aa_command()
{

digitalWrite(3,HIGH);
delayMicroseconds(5000); //the triac is passing
digitalWrite(3,LOW);

}

but it doesn't work!!

although I did not understand why this short ON (10µs) OFF at the end of the function I am happy to see the problem solved thanks for everyone.

The optocoupler has two resistors in front of the diode bridge and so it should be safe.
MOC3021 is rated for 60mA of continuous current, I doubt Arduino is able to damage it. But it should have some current limiting.

yes you are right, in the circuit in the picture they are forgotten the resistance in the out of the controller, but I put a resistor of 300 ohm in my circuit I didn't forget it, else the led go damaged without her.

thank you for your attention.