I am working on a DIY AC dimmer circuit with arduino. This project is part of the AC dimmer circuit as mentioned here

Since, I was stuck in so thought of retracing my steps and checking each part of the circuit and then only moving further ( to the triac part ).

Turns out I am not able to do zero crossing detection even.

My code in arduino :

int led_to_glow = 12;

void setup()
  attachInterrupt(digitalPinToInterrupt(2), zero_crosss_int, RISING);  // Choose the zero cross interrupt # from the table above

//the interrupt function must take no parameters and return nothing
void zero_crosss_int(){
  digitalWrite(led_to_glow, HIGH);
  digitalWrite(led_to_glow, LOW);

void loop()  {

Following is the circuit diagram : Circuit Image

Now, I am a newbie in DIY projects and since this circuit wasn't working so, I thought I would post my breadboard circuit here too.

Please have a look into the physical circuit.

Physical circuit

( I have erased the irrelevant parts of the circuit )

A little bit of explanation ( cause maybe the diagram isn't clear enough )

The yellow jumper wire from PC 817 is sent as interrupt to the arduino's digital pin 2 ( as can be seen in the diagram ).

The arduino detects the RISING signal on it and calls the ISR. I have checked the output on the pins of PC 817 going to the arduino ( using a multimeter ) , it gives ~10 V.

I have added a common ground and VCC from arduino , as later in the AC dimmer circuit it's going to be used ( and my understanding is that wherever VCC is of arduino , gnd also must be of arduino and not from somewhere else , right ? ).

Thanks. Sizu

Update 1 :

I have changed PC 817 to 4N25 ( as I found later that I had that component )

I have added a resistor to the input of 4n25 which inputs 2 V ( I am considering a higher resistor as the max forward voltage for 4n25 is 1.5V )

YELLOW Wire is directly connected to arduino digital pin 2 ( i.e. INT0 )

Updated circuit board

Update 2 :

As it turns out, when AC is switched off, voltage drop between yellow wire ( interrupt pin ) and gnd of arduino is 5V DC , whereas when AC is turned on it's 0.54-0.55 V , any reason why ?

I have also tried

attachInterrupt(digitalPinToInterrupt(2), zero_crosss_int, FALLING);  // Choose the zero cross interrupt # from the table above

I changed RISING to FALLING, it still didn't work.

Hopefully Solved :

I got to glow the LED, I forgot to define LED's pin as the output pin in the arduino code but then also it glows very faintly and even multimeter can't find the potential drop across the LED

So the new code looks like this :

pinMode(12, OUTPUT);
attachInterrupt(0, ledBlink, FALLING);  // Choose the zero cross interrupt # from the table above

Note :

Falling / RISING / CHANGE ( all 3 worked but I think FALLING should be used cause of the pull up resistor )

closed as off-topic by Juraj, VE7JRO, jsotola, gre_gor, Greenonline Nov 21 '18 at 23:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Arduino, within the scope defined in the help center." – Juraj, VE7JRO, jsotola, gre_gor, Greenonline
If this question can be reworded to fit the rules in the help center, please edit the question.

  • I am not ane expert in electronics, but I see a pull-up circuit on pin there and you have an interrupt for RISING. I would expect zero-crossing at FALLING – Juraj Nov 20 '18 at 8:00
  • Thanks Juraj, I tried FALLING too, didn't work though – Sizu Taylorventuresllc Nov 20 '18 at 8:31
  • try using volatile boolean to change an interrupt – abu-ahmed al-khatiri Nov 20 '18 at 9:28
  • Thanks abu-ahmed, I found my mistake ( as far as what it seems ), I didn't define the output pin for LED to glow. – Sizu Taylorventuresllc Nov 20 '18 at 9:45
  • 1
    @SizuTaylorventuresllc if your issue solved your self, try using Answer section!!! – abu-ahmed al-khatiri Nov 20 '18 at 9:51

Browse other questions tagged or ask your own question.