I have some H11AA1 and 4N25 optocouplers. What was thinking was to have the HOT 120 V AC go through 25ohm 1 W resistor (right now 4 100ohm 1/8w in parallel to test it out) to pin 1 of the H11AA1 and Pin 2 to AC neutral. Then pin 4 to GND and Pin 5 as an input with a 10K pullup to 5V.

But... its not working, and I think I might of fried the coupler. Any ideas? unfortunately I do not have a oscilloscope handy

Ok, so I was able to get the zero cross detection working. Now I am trying to do the light dimming and I am stuck. I know i need to fire the triac at a certain time past the zero cross. There are 120 zero crosses per second (for 60Hz power) that gives 8333 micros between crosses. If I use 128 steps that is 65 micros per step. So if I want 50% power I would need to fire the Triac at 65*64 micros after the zero cross??

don't count on the freq being 60Hz and instead, keep track of the 0-xing period yourself either every 0-xing or for some reasonable period(every couple of minutes maybe ). This way you're sure what your period is and then do the math to set what a percentage point is for that period.

I didn't look at the code but it seems your stated logic is right. For a 60Hz freq 1/60 is the full cycle period, so 1/2 that is the half cycle 0-xing period and it should be in the 8mS range. You divided your 0-xing period by the resolution(128) to get what part of the 0-xing period a 'tick' is. For a 50% cycle you'd want x number of ticks which when multiplied by the 'tick' period is closest to 50% of your 0-xing period.

maybe eliminate the interrupt and just use the standard loop() since the Arduino is running at 16MHz and you're dealing with 60Hz timing.

To debug, skip firing the triac for ever other period and append a string with data in critical sections. Print the string every few seconds during the unused period to be sure serial IO isn't causing you to miss anything. Hopefully you can print debug statements in less than 8ms.

You can also eliminate the triacs, pop in a red LED for the driver LED of the MOC part, and move driving the LED low to the beginning of the zero crossing detection. You'll have a PWM driven LED and you should see it dim or brighten depending on what your code is doing.

So, I managed to snag an old scope from work to verify a few things, and indeed the freq is 8.3 ish uS AND the interrupt pin is outputting what I want it to... However, there is one difference than the schematic. I am using a H11AA1 instead of a 4N25.

void light() // function to be fired at the zero crossing to dim the light{ int dimtime = (65*dim); // eval the proper pause to fire the triac delayMicroseconds(dimtime); // delay the dim time digitalWrite(AC_pin, HIGH); // fire the Triac delayMicroseconds(10); // pause briefly to ensure the triac turned on digitalWrite(AC_pin, LOW); // turn off the Triac gate (triac will not turn off until next zero cross)}

I am going to try to add some more features soon, and test it with an inductive load and see what happens. Thanks for all your help. I will try to post a video of the output of the phase control, its really cool looking!