Problems with zero cross detect light dimmer

hey guys, reviving the topic…

I’m trying to correctly detect the zero cross but not succeding.
Waiting for my photons to arrive, I’m trying to implement the following circuit with the arduino uno… (trying with VCC=3.3V)

I tried to access the link here but I have no auth here whatsoever, can someone PS for me please?
Not really sure what is not working: the resistor values, not having the bridge rectifier, …

Code here:

#include <TimerOne.h>
// Triacs
#define AC_LOAD 4
int dimming = 5;
void setup() {
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(0, zero_crosss_int, RISING);  // Choose the zero cross interrupt # from the table above
  Timer1.initialize();
}

 void loop() {
    for (i=5; i <= 120; i++){
        dimming = i;
        delay(100);
    }
 } // Loop

//the interrupt function must take no parameters and return nothing
void zero_crosss_int()  //function to be fired at the zero crossing to dim the light
{
  Timer1.attachInterrupt(gateTRIAC, 65.0651*dimming);  //fires gateTriac when over
  Timer1.start();  // start counting for timer1

}

void gateTRIAC() { 
  digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
  delayMicroseconds(8.33);       // triac On propogation delay (for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

Maybe use two H11A1M with input pins reversed of each other, so output will be produced on both sides of the wave, and only during (near ) zero crossing will there be no output. That should be easy to measure the duration of no output, and take the center point of that calculation as Zero cross.
Just a thought.

@gcats did you actually read the entire thread? It pretty well deals with getting the circuit working with the Core at 3.3v. Are you trying to getting things to work on a 3.3V Arduino or on a Core?

For now I need the 3.3v triac dimmer working in arduino, so I can easily port to spark/photon later…
I’ve made some changes to the 5v circuit I’ve created from the datasheets/tutorials but it’s really flickering.

Just wanted to compare my circuit and the one being used here, or get some help from you guys… sorry for bothering

@gcats, did you drop the H11A1M resistor as @bko suggested:

I do think that 10K is too large for the collector resistor for 3.3V. I would shoot for a collector current of 1mA and would pick around a 2700 ohm resistor instead.

Typically, when you run an arduino at 3.3v, its clock is dropped to 3.3v unless you are using a Due. This may affect some of the timing assumptions so you'll need to check for that.

2 Likes

Here is another site I found with the circuit and board schematics. Keep in mind, this is the original 5v version and the schematic is designed specifically for the board you see. The arduino code associated with this is at the second url.

http://svn.roberttwomey.com/eagle/ACDimmer/

Also keep in mind, as @123peekay can elaborate on if need be, Particle devices don’t support the TimerOne library, so most likely the Timer Interval library will be your weapon of choice.

Still no success…
Tested the zero detector alone, and after 60 pulses it blinks with a 1Hz frequency, as expected.
Tested the triac triggerer alone and it lights the lamp as it should.

I even added the bridge rectifier circuit and made the circuit exactly as this one… (changing the collector 10k to a 2k2)

But it still flickers, it is so strange. Going to grab a spark from my friend and try again with this code

int AC_LOAD = D5;    // Output to Opto Triac pin
int dimming = 128;  // Dimming level (0-128)  0 = ON, 128 = OFF
void setup()
{
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(A1, zero_cross_int, RISING);  
}
void zero_cross_int()  //function to be fired at the zero crossing to dim the light
{
  int dimtime = (65*dimming);    // For 60Hz =>65    
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC
  digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
  delayMicroseconds(8.33);         // triac On propogation delay (for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop()  {
  for (int i=5; i <= 128; i++){
    dimming=i;
   delay(10);
   }
}

Is this code right?
Thanks again

Hi @gcats

This should be milliseconds not microseconds. The half-wave period of a 60 Hz sine wave is 8.333 milliseconds, not microseconds. Try multiplying this by 1000 in your code.

8.33 microseconds is the triac propagation delay, to make sure it actually triggers.

There’s a good explanation here:

I’m using the 8-channel module by Krida Electronics and was only able to make it work using digital pins for the zero-crossing detection.

Also, if I fire the triac faster than about 250 microseconds, it does not activate. I’m on 60Hz.

Here’s a tiny little blinking example:

bool on = false;

void setup() {
    pinMode(D7, OUTPUT);
    pinMode(D2, INPUT_PULLDOWN);
    attachInterrupt(D2, zero_cross, RISING);
}

void zero_cross()
{
    if (on) {
        delayMicroseconds(250); // Works with 250 up to 8000 (60Hz)
        digitalWriteFast(D7, HIGH);
    }
    delayMicroseconds(8);
    digitalWriteFast(D7, LOW);
}

void loop() {
    on = false;
    delay(700);
    on = true;
    delay(300);
}
1 Like

Hi all,

Also using the Krida dimmer like elecnix. I can turn the lights on and off - and can dim with serious flickering if I ignore the sync pin as a trigger. However, it doesn’t seem like the “attachInterrupt(D2, zero_cross, RISING);” is working for me. I have this on D4. It just never triggers. Maybe it’s because the Krida is a 5v board and the Photon is 3.3?

Any tips @elecnix ?

Best,
Rob

Is one of these a typo, or do you have the board hooked up to the wrong pin?