dimming LED bulb (compatible only with leading-edge dimmers)

im using optocoupler(4N35) to control the power through the 12V LED spotlight using arduino uno and it works. but the gain of optocoupler(4N35) was too low.. should i use optotriac (MOC3042)?.. or just use optocoupler (4N35) together with a triac?

Why do you think the gain is too low? Too low for what? You said it works. Please clarify. If it's a 12VDC circuit you can use a power transistor such as a FET instead of a triac (if what you're having difficulty expressing, is that the optocoupler won't handle the current requirements).

when i try use optocoupler(4N35) alone, the bulb dims but it doesnt reach the max voltage(12v). so i tried combining it with FET, connecting the emitter of 4N35 to the GATE of FET. But it only flickers when i tried to reduce the voltage; and i come to realize that the LED bulb im using is only dimmable when using leading-edge dimmers. so i guess i have to use triac instead of FET.

but i also found out that there's an optotriac(MOC3020). so, do i have to buy triac and use it together with 4N35 or buy optotriac(MOC3020) only or buy both or is there any other alternative?

im using this simple code btw,

int ledPin = 9;
void setup()
{pinMode(13,OUTPUT);
digitalWrite(13,LOW);

Serial.begin(9600);
}

void loop(){
 String msg="";
 
 if(Serial.available()>0)
 {
   while (Serial.available()>0){
   msg += char(Serial.read());
 delay(250);

 
if (msg == "off"){
   analogWrite(ledPin,0);}
   
   else if (msg == "half"){
     analogWrite(ledPin,50);}
   else if (msg == "half1"){
     analogWrite(ledPin,100);}
   else if (msg == "on"){
   analogWrite(ledPin,255);}
 
}
Serial.println(msg);
 }}

You have left too many unknowns for anyone to give a good answer. For example, leading edge dimmers are usually 120VAC devices. This doesn't reconcile with the rest of what you say.

We need to see a schematic. Please edit your post to put the code inside code tags to conform to the forum guidelines. But I suspect the problem is not with your code.

but i also found out that there's an optotriac(MOC3020). so, do i have to buy triac and use it together with 4N35 or buy optotriac(MOC3020) only or buy both

A triac will only work with AC. Where is your AC in this circuit?

Please post a schematic.

Grumpy_Mike: Where is your AC in this circuit?

My bet is that it's in the PWM signal. But of course that isn't 50 or 60Hz line frequency. But yeah, where are the schematics?

im not really sure which circuit i could use but i tried a PWM circuit below…
im using “12V 4W LED MR16 GU5.3 Spotlight” from torchstar and it was indicated on the box that it is dimmable when using leading-edge dimmers.

Untitled.png

Thanks for the schematic. I repeat, a leading edge dimmer is a 50 or 60Hz device. The PWM output from your Arduino is not. From the reference that is available from the help tab on your IDE, look up AnalogWrite(). It says, " The frequency of the PWM signal is approximately 490 Hz. ". Can you see that there is a potential problem here?

What happened when you tried the circuit?

The ROOT PROBLEM is you don't have a simple LED. You have a consumer "LED bulb" which has UNKNOWN ELECTRONICS inside.

Lots of unknowns and assumptions....

I assume you want to dim it with the Arduino, so a light dimmer from the home improvement store won't work for you?

I assume it's designed to run from 12VAC. That would be a simple transformer to step-down the line voltage. A traditional AC light dimmer on the line-voltage side will work if you have a transformer and a regular incandescent/halogen bulb. Presumably, that works with this particular LED bulb too...

This one is dimmable, but most "LED bulbs" are not dimmable and many have regulated supplies and are designed to run from 85VAC to 270VAC 50-60Hz, and the voltage does not affect the brightness.

Assuming this is an AC bulb, the 4N25 does not work with AC and the 4N35 is rated for 100mA (0.1 Amps). 4W @ 12V is about 3 Amps.

You can build a traditional line-voltage phase-controlled 50/60Hz AC dimmer with a TRIAC, build a similar TRIAC dimmer for 12VAC, or start-over with a "raw" LED and build or buy a PWM LED dimmer.

It it was me, I'd get a normal "raw" LED.

What happened when you tried the circuit

it doesnt work.. :sob: :sob:

but i tried to remove the capacitor and diode and connect the bulb in series with the 12V DC and it kinda works.. though it reach the max brightness at analogWrite(ledPin,100); .. it has the same brightness as analogWrite(ledPin,255);.. im not sure if its safe..

but i tried to remove the capacitor and diode and connect the bulb in series with the 12V DC and it kinda works.. though it reach the max brightness at analogWrite(ledPin,100); ..

If it's dimming between 0-100, I don't see a problem with that... Just change your sketch accordingly. I would suggest jumping to full-on at PWM=100 though to save unecssary MOSFET switching.

im not sure if its safe..

I'm not sure what you mean by "safe". The worst thing that could happen is your MOSFET, power supply, or LED burns-up. And, if the MOSFET is not overheating it's probably not going to burn-up. You're not dealing with dangerous voltages and if nothing overheats you probably aren't going to burn the house down. :smiling_imp:

I found the [u]TorchStar website[/u] It says 12VDC. That's good.

It also says, "DIMMABLE when working with electronic dimmers". That's vague... Most LED dimmers are constant current (actually controlled current, since they are dimmable) and they won't work with a "12V" constant-voltage bulb. And, most normal wall-dimmers (that would work with halogens, etc.) are AC. So.... I don't know what "electronic dimmers" means.

dazmehard: it doesnt work.. :sob: :sob:

but i tried to remove the capacitor and diode and connect the bulb in series with the 12V DC and it kinda works.. though it reach the max brightness at analogWrite(ledPin,100); .. it has the same brightness as analogWrite(ledPin,255);.. im not sure if its safe..

Please post an updated schematic.

It also says, “DIMMABLE when working with electronic dimmers”

it was stated on the box that it is dimmable when using leading-edge dimmers; but it seems like it also works with trailing edge dimmer, which is the one im trying to use now.
i wonder if it can be supplied by 12V AC too…

Untitled.png

dazmehard: it was stated on the box that it is dimmable when using leading-edge dimmers; but it seems like it also works with trailing edge dimmer, which is the one im trying to use now. i wonder if it can be supplied by 12V AC too..

Trailing edge dimmer? You're hard to keep up with. I thought you were using the circuit in the schematic. You're calling it a trailing edge dimmer, or you are connecting it to other circuits? :)

You want to know if it will work with AC? Turn it around.

Trailing edge dimmer? You’re hard to keep up with. I thought you were using the circuit in the schematic. You’re calling it a trailing edge dimmer, or you are connecting it to other circuits? :slight_smile:

You want to know if it will work with AC? Turn it around.

i believe the one im using in schematics was a trailing edge dimmer, since it was using a FET instead of triac…

btw, there’s a mistake on the diagram… this is the right one

Untitled.png

dazmehard: i believe the one im using in schematics was a trailing edge dimmer, since it was using a FET instead of triac..

No, the edge terminology refers to pulse position relative to AC line phase, you aren't using that.

btw, there's a mistake on the diagram.. this is the right one

Want to bet?

It is an appalling circuit. 1) What is that 1M resistor doing? - Nothing remove it. 2) Why is the 5R resistor in the source and not in the drain? Move it. 3) Using a resistor to control the current in a high power LED is not going to cut it. But as this is not just an LED it has some electronics in it already then what is that resistor doing anyway?

And as mentioned it is not and "anything" edge dimmer.

No, the edge terminology refers to pulse position relative to AC line phase, you aren't using that.

oh ok.. so PWM is for DC while edge dimmers are for AC..

It is an appalling circuit. 1) What is that 1M resistor doing? - Nothing remove it. 2) Why is the 5R resistor in the source and not in the drain? Move it. 3) Using a resistor to control the current in a high power LED is not going to cut it. But as this is not just an LED it has some electronics in it already then what is that resistor doing anyway?

yeah i just copy this circuit... i tried it, and yes u are right.. thanks..