Dimmer PWM Led using Arduino Nano Every

Hi everyone, I just made this simple led dimmer using Arduino Nano Every and IRF520N mosfets.
I tried on breadboard and I never had any error or problem so I decided to make a real pcb as I need to use them in my house.
I've just soldered every component on one of them and after a bunch of minutes the led strips (3x 1m 12v white led strip) start flicker and randomly one of them switch off.

I share with you my schematic and code (the RTC module on them is used to make them dimming following the sun.

Errata corrige: I realized that pin D2 isn't PWM, so I bypass it (cut it from the Arduino Board) and connect the "Uscita1" output to pin D6 with a flying wire.




Code:

int led1 = 6;
int led2 = 3;
int led3 = 5;

int minimo = 70;
int a = minimo;
int delta = (12*60)/(255*2);
bool dec = false;

void setup() {
  // put your setup code here, to run once:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);
  digitalWrite(led3, LOW);
  
  delay(3000);
  Serial.begin(9600);
}

void loop() {
  Serial.println(a);
  analogWrite(led1, a);
  analogWrite(led2, a);
  analogWrite(led3, a);

  if(dec)
    a -= delta;
  else
    a += delta;

  if(a > 255)
    dec = true;
  if(a < minimo){
    dec = false;
  }
    
  delay(1000);
}

Change the 220 ohm resistors to 10k. Put resistors of some 180, or 220, between the gates and the controller output!

So just swap the 220 with a 10k resistor...
But how can i make a "clean" work to insert the 180 ohm res between the gate and the arduino PWM pin?

Just solder on the bottom of the board

But in this way it is in parallel with the pcb track (ideally short circuit) and the 220 ohm resistor is bypassed, right?

You can remove track. Draw schematic first of what you want. Then modify

But, just to understand, why I need to implement those resistors? I think that there were some pull up/down resistors already on the arduino pin...

1 Like

So I need to do this...
Screenshot from 2022-07-06 12-16-50

Not critical, but you have the 10k on the wrong side of the 220 Ohm resistor.

You do not want to pull down the FET gate. The 10k resistor is simply there to hold the Arduino pin LOW until the microcontroller boots and sets it to OUTPUT. The problem is the Arduino, so that is where you put the pull-down resistor. :+1:

So, your LED strip draws substantially less than one Amp? Because the IRF520 is not a logic-level FET and will not turn on fully at 5 V. :roll_eyes:
Selection_060

Are the MOSFETs getting hot? As they are not logic level i would think they would.

The 220 Ohm pull down is too strong. Making it weaker is a good idea. I doubt adding a Gate series resistor will do any difference.

Did you try to turn the LEDs on for some time with some minimal code? (Note delta "should be" about 1.4 but since it is an int it is 1.)

Hi Paul, I dont see why it makes ANY difference - can you explain please?
I've not much experience with MOSFETS - so can someone also exlpain why the 220 E resistor is needed as I understood MOSFETs are voltage driven and more or less infinite input resistance?

This seems to explain things quite well but nobody seems to have read it.

1 Like

The LED strip is 12 V and absorb about 200 mA/m.

Not at all.

The digital ON/OFF works fine also on this pcb, the "dimming" works great for a couple of minutes and then starts flicker as hell.

Yes I read it, and this evening I try to modify it

The flickering is strange. I don't know how it could be explained by a missing Gate resistor. IMO it is either a bug (but your code is so simple it seems nearly impossible) or some other HW problem. I suspect something heats up and works wrong. Power source or some contact? That is why I asked about the on/off control. If you turn the LEDs on and keep them on for "couple of minutes" there is no flickering?

Well, I did explain the reason for placing it correctly. It may make a difference if the two resistor values are within a couple of orders of magnitude, particularly when you are using the FET with a marginal gate voltage as you are with the IRF520. It is simply a matter of good engineering design.

As the article offered no doubt explains, and it is a point of common argument over the years here, the FET has more or less infinite input resistance but nevertheless substantial capacitance which matters when driven with AC (i.e., PWM).

What the article forgot to mention is the fact you want to (dis)charge the Gate capacitance as fast as possible particularly when PWMing. The article suggests 1k resistor as optimal Gate resistor. That is at least 5 times more than needed meaning 5 times slower switching and 5 times higher switching losses.
Of course LEDs are very forgiving load for a MOSFET (or other switch) and the switching losses are always low compared to motors and similar.

Well, of course I left that bit for you; I was only addressing my original point. :grin:

To be fair, it very much depends on how many LEDs. It's just a matter of the total current, or are you thinking of the extra Volt due to the commutation diode on an inductive load?