ISSUE WITH LED DIMMING USING ARDUINO PWM

Hello all,

Greetings for the day!!!

I am new to Arduino and Arduino forum, apologies for any mistake.

I am working on a small project for the dimming of LED strip using PWM output of arduino. I am using MOSFET IRLB8748 to be driven from arduino pin 3 output, complete sketch attached. Dimming part of LED strip is working properly. But, LED Strip is not getting ON to its full intensity even i am pushing maximum value of 255 of analogWrite().

It can be clearly seen that while powering directly from 12V power source the intensity of LED Strip is different from using the MOSFET.

Please help me, am i missing something? One thing i have noticed that if i change the resistance of Gate to Source/Ground from the 220Ohm to 10KOhm the full ON intensity also get decreased but if i am changing from 220Ohm to 10Ohm the intensity remains same for full ON.

int led = 3;
int brightness = 0;

void setup() {
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

void loop() {

  if (Serial.available() > 0) {
    brightness = Serial.read();
    Serial.println(brightness);
    analogWrite(led, brightness);
  }
}

schemeit-project.png

The resistor from the gate to ground is to keep the input pulled low until the pinMode sets the pin to output. The pin defaults to (floating) input on reset. The resistor is typically 10K or more.

Which Arduino are you using? A 3.3V output may not turn the MOSFET on fully. Does the MOSFET get warm? That could indicate that it is not fully turned on (high Rds).

Hey, I am using Arduino UNO. NO, MOSFET is not getting Warm. I have placed 10K resistor from gate to ground in-result the intensity of LED Strip also gets decreased even at the value of 255 of analogWrite() PWM.

What is sending the value?
And do you really receive back "255" in the serial monitor? Not
2
5
5

?

PS Do note your title is considered to be very rude...

Hello septillion,

I have value of 255 on serial monitor as
255

When I run your code I get this in serial monitor:

50
53
53
13
10

Serial.read reads one character at a time so PWM is set to the last value received which is 10* (ASCII line feed). *If the line endings is set to no line ending in serial monitor, the last character received would be 53 (ASCII '5').

The serial input basics tutorial will show how to read a multi digit number in. Or Serial.parseInt(), but that is a blocking function and not as good as reading in the ASCII string and converting to a number ala serial input basics.

That's why I asked how the 255 was returned. But yeah, also asked how he sends it but as always the hard questions get ignored...

Try Serial.parseInt():

const byte led = 3;

void setup() {
  pinMode(led, OUTPUT);
  Serial.begin(9600);
}

void loop() 
{
  long brightness = Serial.parseInt();  // Returns 0 if timeout without input
  if (brightness > 0 && brightness < 256)
  {
    Serial.println(brightness);
    analogWrite(led, brightness);
  }
}

Thanks all for the advice. I got it.

Now, getting flickering issue on dimming. Please advise.

khan_yusuf:
Now, getting flickering issue on dimming. Please advise.

Please post code.

If you change your code or circuit, please post the new version so that we stay on the same page.

How to post an image so that we don't have to download it.