12V LED Strip Not Getting to Max Brightness

Hey Guys -

I've got an LED strip (non-RGB) which I'm trying to control via a NodeMCU. I'm currently using Blynk for the project. When the LED strip is connected directly to 12V, it's super bright, however; when controlling via PWM @ the max value of 1024, it's much dimmer. Below is the hardware layout I'm using. The code is simple as it simply adjusts the PWM of D0 between 0 & 1023 on a slider.

Any suggestions to achieve max brightness when slider is at the top (PWN = 1024)?

Thanks!

Simple, that mosfet isn't suitable to drive with just 3v3. You have to get yourself some proper logic level mosfet :slight_smile:

however; when controlling via PWM @ the max value of 1024

The maximum value of the PWM is 255. After that it cycles every 256 you add to it. So a PWM of 1024 is the equivalent of a PWM of 0.

The code is simple as it simply adjusts the PWM of D0 between 0 & 1023 on a slider.

But you said 1024 before. A value of 1023 is the equivalent of PWM 255.

septillion is spot on. The IRF520 is a Power Mosfet with 9.2A drain current and 100V breakdown voltage. The mosfet has a low gate threshold voltage of 4V and hence commonly used with microcontrollers like Arduino for switching high current loads. Note the 4V is not a logic level voltage compatible with the 3.5 output of your controller. The MOSFET will partally enhance but not fully hence there is a voltage drop across the MOSFET causing your dim LEDs. Heat the MOSFET and the brightness will change. This is temperature dependent so keep it below 100C.

@Grumpy_Mike On a ESP8266 PWM is 10-bit :slight_smile: So I assumed (but something with mother of all...) his mention of 1024 was just a typo after mentioning 0-1023.

On an ESP32 the PWM can be generated by several sources. Mainly PWM for LED's are driven by the ESP32 LED API.

#include "esp32-hal-ledc.h"

void setup()
{
  ledcSetup( 6, 12000, 8 ); // ledc: 4  => Group: 0, Channel: 2, Timer: 1, led frequency, resoulition bits // blue led
  ledcAttachPin( GPIO_NUM_14, 6 );   // gpio number and channel
  ledcWrite( 6, 0 ); // write to channel number 6
}
//
void fDoRed( void * paramater )
{
  bool UpDown = true;
  int countUpDown = 0;
  for( ;; )
  {
     xEventGroupWaitBits (eg, evtDoRed, pdTRUE, pdTRUE, portMAX_DELAY );
     // send led data, increment led count, determine end stops and direction
    if ( UpDown )
    {
      countUpDown++;
    } else {
      countUpDown--;
    }
    if ( countUpDown <= 0 )
    {
      UpDown = true;
    }
    if ( countUpDown >= 255 )
    {
      UpDown = false;
    }
    //log_i( "red %d", countUpDown );
    ledcWrite( 6, countUpDown ); // write to channel number 4
    //
  }
   vTaskDelete( NULL );
}

This line of code ledcSetup( 6, 12000, 8 ); // ledc: 4 => Group: 0, Channel: 2, Timer: 1, led frequency, resolution bits // blue led, which, if using the ESP32 Arduino core is hidden, sets the number of bits at 8. If you want to use 1024 then use the API and set the bits to use as 10 instead of 8.

A look into the ESP8266 API might give hints on how to set 10 bits for the ESP8266 PWM.

Idahowalker:
A look into the ESP8266 API might give hints on how to set 10 bits for the ESP8266 PWM.

analogWrite(pin, value);

:smiley:

Thanks for all the replies, guys...

Yes, 1024 was a typo as I meant 1023 - must had been thinking resolution :slight_smile:

Assuming the only resolution is still the MOSFET, what should I replace the IRF520 with? I've got a few N-Channel RFP30N06LE's which are listed as having a logic level gate which I assume would work. If so, would a resistor or anything else need to be placed inline with it or would the below schematic work?

Note: Please ignore the label of the MOSFET in the image. I'd be using a RFP30N06L unless something else is required.

Thanks again!

That RFP30N06LE seems very suitable, wayyyy more than the IRF520 . Strictly speaking drive a gate directly can overload to output of a micro. So best practice is to use a 50-100Ω resistor in line to the gate. But usually I'm naughty and don't bother. And if you want to be sure the LED's stay of when the ESP is booting/resetting, place a 1k-100k pull down between gate and source.

Awesome - Thanks - Will try it out this afternoon...

Not too familiar with pull down resistors - are they just standard resistors used in a specific way or engineered differently? If I use one, I guess the below would be the final then, right?

Note: Resistor on gate being 100 & one between gate & source being 1k...

Thanks again!

If I use one, I guess the below would be the final then, right?

No very wrong. The resistor should be in series with the gate. Then the pull down goes from the Arduino output to ground.

Resistor on gate being 100 & one between gate & source being 1k...

Exactly the wrong way round as well.

Like this? If no, I may just leave that part out :slight_smile: Thanks!

The 150 Ohm resistor goes between the ESP output and the FET gate, it limits the current the ESP requires to charge and discharge the gate capacitance which is quite significant.

At power-up, until the ESP initialises, its GPIOs float so the random voltage on the FET gate may allow it to at least partially turn on. This may or may not matter in respect of the LED strip briefly flashing and the partially turned on FET dissipating some power whilst it does so. Likely no worse than the original situation you describe, however to avoid this you can put a 10k resistor between the ESP GPIO and ground, before the series 150 Ohm resistor. Like this:


(The motor and diode as the load are not relevant to your situation,)

bzowk:
Like this? If no, I may just leave that part out :slight_smile: Thanks!

That's not what I told you :wink:

septillion:
[...] So best practice is to use a 50-100Ω resistor in line to the gate. [...] place a 1k-100k pull down between gate and source.

In both drawings you have the resistor inline with the drain. In the last image you do have the pull down between gate and source though :slight_smile:

Thanks...

Turns out the reference article I was using had the pinout for the MOSFET incorrectly labeled with the gate being the middle pin which was the confusion. Good to go now, I think.

Thanks again!

@bzowk Tip, always go by the datasheet. And now you know why most of us don't like Fritzing :wink: Although it's possible to make a real schematic with Fritzing.

Turns out the reference article I was using had the pinout for the MOSFET incorrectly labeled with the gate being the middle pin which was the confusion.

Different FETs have different pin outs, as do transistors and many other components. Always check first. Your article was probably right but for the FET they used. Even some transistors have a suffix which denotes a different pin out.

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