YYAC-3S dimmer module flickering

Hello, recently i bought the YYAC-3S AC dimmer module which is controllable via PWM.
I am having the issue that my lamp is flickering when dimming below 200 (analogWrite(pin, 200))
I have tested with both an LED and regular light bulb.
Both have flickering issues but the LED is more noticeable.
I have also noticed that when I upload a new sketch to my Arduino UNO the flickering stops and the dimming effect is as desired until the Arduino is done booting, then the flickering starts again.
Right now I'm not using any loops, I'm just setting a fixed value in the setup method for testing.

Does anyone have an idea what's going?

I couldn't find the official datasheet or application notes. Do you have any more information?

Sometimes dimming can be unreliable with low-wattage incandescent bulbs (maybe around 10 watts). The same thing might happen with LED bulbs, which are lower wattage for the same brightness.

Some LED bulbs are non-dimmable and some dimmable bulbs work better than others. And the dimming curve is different with different LED bulbs.

I've got some LED bulbs on a regular wall-dimmer and they flicker when dimmed below abut 50%. (They are special "globe-bulbs" and not easily-replaceable with something else.)

...Most microcontroller dimmers use zero-crossing detection fed-back into the microcontroller as an interrupt, instead of regular PWM, but it looks like your module doesn't work that way.

How can it work at all before the Arduino boots-up?

P.S.

That's good... And once you (hopefully) get it working you don't want to reset/restart the PWM constantly in a loop. It's OK to loop but you should only analogWrite() when you want to change the dim level.

Are you using pins 5 or 6?

Not much information unfortunately on this one, i found it on AliExpress.
I used to buy RobotDyn, these work like a charm.
However the seller blacklisted me after i was sent the wrong model and i messaged him about it. He then accused me of 'being dumb', and blacklisted me... Very professional, oh well.
The LED lamp is 4W and the regular light bulb is 100W. The LED is dimmable, i use them all around my house with dimmers.

Not sure, my guess is that something somewhere is remembering the last state it was in perhaps?
I am just debugging this issue with my Arduino connected to my PC and am changing the values by uploading a new sketch. I would have expected the lamp to turn off but instead it just kinda works for that moment.

All info that i can find is on the seller's page:
https://nl.aliexpress.com/item/1005006239315121.html?spm=a2g0o.productlist.main.9.1c7f30dfdE3Q7a&algo_pvid=b4281597-97af-4dcc-aaab-29bffcc6dd24&algo_exp_id=b4281597-97af-4dcc-aaab-29bffcc6dd24-4&pdp_npi=4%40dis!EUR!10.89!7.19!!!11.83!!%402103850917037803712855348e7e6d!12000036422493467!sea!NL!777775165!&curPageLogUid=bDeQMsyoOhwn

I've tried pin 3, 6 and 9.

EDIT:
I tried pin 5 as well, but no difference.
I did notice that pin 3 gives the least flickering though.

Then maybe the arduino PWM frequency is too high for the module.

Use pin 3 and try tone(3, 100);

That should generate a 50% duty at 100Hz.

I've tried using tone just by itself and combined with analogWrite.
The lamp is slightly dimmed and not flickering at all, only issue is i cannot dim it now.
Changing any of the values of analogWrite or tone does not change the brightness of the lamp, just using either separate or both combined.

EDIT:
Using values above ~500 will cause the light to start flickering, but has no effect on brightness.

Hm, almost no flicker if i manually set up zero-crossing:

void loop() {
  int cycleTime = 20000; // Microseconds for one AC cycle
  int offTime = map(brightness, 0, 255, cycleTime, 0);

  digitalWrite(dimmerPin, LOW);
  delayMicroseconds(offTime);
  digitalWrite(dimmerPin, HIGH);
  delayMicroseconds(cycleTime - offTime);
}

That is not zero crossing, as you are not in sync with the mains frequency. Also mains has 100 Hz zero crossings, not 50 Hz. You're just producing a 50 Hz PWM signal for the controller to handle. The listing says it can do up to 500 Hz, apparently it has trouble dealing with that.

The design of the circuit board, by the way, is beyond terrible. It's outright dangerous. There is NO high voltage separation to speak of. There are traces that belong to the mains side running right next to traces that belong to the low voltage side at the TRIAC. The PC817 optocoupler (likely for the zero crossing pulse) is placed right next to the bridge rectifier. The microcontroller is surrounded by components that are part of the mains circuitry, no spacing to speak of. I recall there should be about 8 mm of circuit board separation between the high and low voltage sides, this board has less than 1 mm separation, which can easily be bridged by mains voltage, especially when there are power spikes. Tracks of both the high and low voltage side run even under the MOC3020, which is ridiculous. There should be an anti-tracking slot under that opto instead.

With this level of isolation, the moment you connect your Arduino to this board, you should treat your Arduino and everything that it has connected to it as if it is mains connected. It's design is terrible, just terrible.

Probably the software running the thing is of similar quality, as your flickering issue indicates.

1 Like

Yeah sorry i meant to say zero-crossing in quotation marks, but 100Hz? I thought it was either 50 or 60 Hz?

Thanks for pointing that out, this board will be going straight to the trash.

Do you, or anyone else, perhaps know of any good dimmers i could use? I'm having trouble finding any. (Besides RobotDyn, i cannot buy those anymore)
I would prefer actually to have the zero crossing built in, but at this point any will do.

50 Hz is the full wave; you are triggering at each half wave (both the negative and the positive halves). There are two zero crossings per full wave, so 50 Hz AC has 100 Hz zero crossings.

A few years ago I started to develop a board based around an ATtiny412 that can handle two PWM inputs for two phase cutting AC outputs. Somehow I got stuck reading the zero crossing signal and PWM signals and creating the output waveform. Then I didn't have time any more. The board is still sitting on my desk :slight_smile: I should finish it; design of the PCB can also be improved. It does provide decent separation though, not like the board you got..

I recall seeing rather decent boards, providing zero crossing output and phase cutting input. No PWM so a little more work on the Arduino side.

Well if you do, maybe i could get some boards from you even :smiley:

Any brand name or link perhaps to point me in some sort of direction? All that keeps popping up for me are RobotDyn and this YYAC-3S board.

@merv-c
So as I suspected and as you have verified, you need to use a PWM frequency less than the UNO 490Hz.There is nothing wrong with the board, you just need to use a lower PWM by manually creating a PWM signal in your code.

If you find another module, you may have the same exact problem.

This thread is showing a 4-port TRIAC board that looks a lot better from an electric isolation perspective. The zero crossing circuitry could have benefited from a little more space away from the rest but at least it's not as cluttered and mixed up like the board you have.

It does however require you to do the phase cutting timing on the Arduino itself. Not particularly hard (use timer interrupts), but not as easy as PWM either.

I would recommend not using that, if it faults you could damage your computer or worse.

Also many times people try to do the zero cross, and forget about the background interrupts in the Arduinos. Those interrupts cause a timing error which causes the light to flicker. These must be considered when writing your code. Larger bulbs have a heaver filament that is thermally slower hence the flicker does not show so much.

Thanks, I'll check it out!

Then you're doing something very wrong, as in phase cutting the switching pulse to the TRIAC (through a timer interrupt) always comes at a different time from the zero crossing pulse (through a pin change or external interrupt). Even having that timing a little bit off will not cause flicker, for that you must be missing at least one half cycle and probably more than that.

What is more of an issue is that LED lights and phase cutting dimmers are not good friends. Unless specifically designed to use with such dimmers they may flicker, or simply switch on at full brightness from a specific point in the phase cutting.

Added to that: if you cause a shortcut, those tracks will burn in flames way before the 16A fuse... maybe this should be equipped with its own 2A fuse...

The very basics of a Triac or SCR is you can't turn it off once the triac/SCR is turned on it stays on until the voltage/current across it reaches zero, this is defined as the holding current. Once it is on with or without ao gate signal applied it will remain on until the AC current in the triac crosses zero. Some other external device that stops the current from flowing (like a relay somewhere else that disconnects the current) can be used to turn it off.

I know.
What's your point?