Triac Dimmer: transformer making noise

I have 220V. I’m trying to make a dimmer and using the following code.
I use a triac dimmer like this.

void zero_cross_int()  //function to be fired at the zero crossing to dim the light
// Firing angle calculation : 1 full 50Hz wave =1/50=20ms 
// Every zerocrossing : (50Hz)-> 10ms (1/2 Cycle) For 60Hz: (1/2 Cycle) => 8.33ms 
// 10ms=10000us 
// 10000 10 / 128 = 78 For 60Hz: (8333us - 8.33us) / 128 = 65 

int dimtime = (78*dimming);    // For 60Hz =>65    
delayMicroseconds(dimtime);    // Wait till firing the TRIAC
digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
delayMicroseconds(10);         // 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

and attachInterrupt(D4, zero_cross_int, RISING); in setup().
When I connect directly to a halogen lamp everything is working as expected. When I connect to a lamp with this transformer, the transformer is making a buzzing noise except for when the brightness is high. Flickers for some values.

What could be the problem? Feels like some frequency mismatch.

Here is the Full Code

What Triac are you using?
With inductive loads at low dimming levels you may need to hard-fire the triac as the “lagging” current might not reliably reach the threshold level in time.

Hi, Thanks for your reply.I use this. What do you mean by “hard-fire” I’m not an electronics person. How do I do that?

Since I can’t find any schematics it’s hard to say, but looking at the images there is a TRIAC DRIVER marked on the board which will probably do the hard-firing already.

But the buzzing noises might also come from resonances in your hardware setup which are hard to control/get rid of - for that reason I prefer electronic “transformers” (which require trailing edge dimming tho’).

Thanks. I can get this electronic transformer How do I do trailing edge dimming?

Also the one in the picture (the one I am using) says it’s an electronic one. I did not connect ground in the power supply. Could that be a problem?

Trailing edge dimming would be that the triac opens on zero-cross and your code switches it off after the desired time according to dimming level, while leading edge means that your code gets a sync on zero-cross, waits a while and then fires the triac which will then open till next zero-cross and shut after that till you fire it again.

Your dimmer is a leading-edge dimmer and I’m pretty sure this won’t let you do the trailing-edge dimming.

But for the unit to work at all, you should definetly have the signal GND lines connected (DC power supply, dimmer and µC) - but keep away from the AC side!!!

Thank you so much. I get the idea. I was talking about the ac ground.
Also, what would happen if electronic transformer is used with leading edge dimmer? Looks like that is happening.

This might provide some extra info

and reads for your question

Thanks. I get the idea. It looks like it is hard to find a trailing edge dimmer for my purpose. I’m going to remove the transformer and going to have 220V G4 dimmable bulbs instead of 12V G4’s. It Should work.

220v dimmable G4