hello , i am working on an AC dimmer project , the zero cross detector is workin and delivering a square signal but the arduino doesnt read it . i used a code to count the change in the interrupt pin but it kept showing a zero . here is the code i used :
#define triacpulse 8
int dimming = 128;
volatile int count = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(A0,INPUT);
pinMode(triacpulse, OUTPUT);
pinMode(2, INPUT_PULLUP);
}
void incrementCount() {
count++; // Increment the count whenever there is a change on pin 2
}
void loop() {
int sensorValue=analogRead(A0);
dimming=75*sensorValue;
attachInterrupt(digitalPinToInterrupt(2),acon,CHANGE);
attachInterrupt(digitalPinToInterrupt(2), incrementCount, CHANGE);
Serial.println(count);
delay(1000);
}
void acon(){
delayMicroseconds(dimming);
digitalWrite(triacpulse,HIGH);
delayMicroseconds(10);
digitalWrite(triacpulse,LOW);
}
the thing i need help with right now is how to read the signal from the zero cross because without it the triac pulse wont come .
any help would be great.
best regards,