Zero cross with millis() problem

I want to control AC lighting dimmer module by timecount.
https://robotdyn.com/ac-light-dimmer-module-1-channel-3-3v-5v-logic-ac-50-60hz-220v-110v.html

in the example, Using delay() on zero cross have delay time count.
So I want to control it using micros().

But when I run it, the light fllickering.
Did I write the wrong code?

long current = 0;
long zeroCount = 0;

void setup() {
pinMode(9, OUTPUT);//PWM
attachInterrupt(digitalPinToInterrupt(8), zero_cross, CHANGE);
}

void zero_cross() {
//current = micros();
zeroCount = current + 5000;
}

void loop() {
current = micros();
if (zeroCount == current) {
digitalWrite(9, HIGH);
delayMicroseconds(50);
digitalWrite(9, LOW);
}
}

acPWM.ino (400 Bytes)

Google Translate identifies this as Korean

I want to control AC lighting dimmer module with timecount.
AC Dimmer Module, 1 Channel, 3.3V/5V logic, AC 50/60hz, 110V~400V - Robotdyn

Using delay() on zero cross as in the example delays the time count
So I want to control it using micros().

But when I run it, the light bulb flashes.
Did you write the code wrong?

Interesting but common problem. This dimmer will not work with LED lights. You have to fire the triac each zero cross, not 50/60 but 100/120. They state: "In Arduino, dimmer is controlled with RBD dimmer.h library, which uses external interrupts and process time interrupts. It simplifies the code writing and gives more processing time for main code. Which is why you can control multiple Dimmers from one microcontroller.

You can download RBD Dimmer.h library and a few examples in «Documents» or on GitHub. We are constantly updating our library, so we recommend to check for the website updates or subscribe to our newsletter.

Dimmer is connected to Arduino controllers via two digital pins. First (Zero) to control the passing of Phase Null of AC, which is used to initiate the interrupt signal. Second (DIM/PSM) to control (dim) current.

Note that Zero requires connection to designated microcontroller pins (which are different depending on the model of Uno, Nano, Leonardo, Mega), since it tied to microcontroller interrupts."
You might try there examples first. Also your Arduino has background tasks operating which can cause flickering if you are not careful.

A copy of your schematic would be helpful, preferably not a frizzy thing.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.