Control 24V LEDs with MOSFET (IRL540N)

Hello,

I want to control 4 24V LED spots with an Arduino and IRL540N mosfets, but I can't get it to work.
I connected the ground of the power supply and ground of the Arduino to the Gate pin, output to the LEDs to the Drain and the Arduino signal pin to the Source.

For the code I just set the Arduino signal pin from HIGH to LOW with a delay. The problem is the LEDs are only dimming a little bit and aren't turning off at all. Also if I disconnect power from the Arduino the LEDs stays a bit dimmed but still bright, like there is always power draining through the Arduino keeping the LEDs from completely turning off.

Is this because the MOSFETS I'm using aren't compatible for this usage? Or am I just doing something wrong?

How did you decide on your connections to the MOSFET? They're different from any MOSFET switching circuit I've ever seen. Try Googling "MOSFET as a switch".

Steve

slipstick:
How did you decide on your connections to the MOSFET? They're different from any MOSFET switching circuit I've ever seen. Try Googling "MOSFET as a switch".

Steve

You're right, I turned the MOSFET pins around in my head.. I connected it the right way, so still the same problem.

Also when I add a potentiometer instead of the Arduino the MOSFET seems to be working fine, I can dim the LED's all the way from 0 to 100%.

Did you try a new mosfet? You might have killed it.

septillion:
Did you try a new mosfet? You might have killed it.

I already tried a few, but the MOSFETs are fine. Like I said, they do what they should do with a potentiometer. So the Arduino is the problem, it seems like it's still outputting a little bit of power when the pin is LOW, or that there's still a connection between ground and the signal pin.

I also tried 2 different Arduino's, they behave exactly the same.

gfhoihoi72:
Like I said, they do what they should do with a potentiometer.

Wait, what? What are they suppose to do with a pot?

But two things:

  • Post a schematic. NO Fritzing breadboard mess please. Simple hand drawing will do.
  • Post code you tried to test it with. Should just be a tiny program I think :slight_smile:

septillion:
Wait, what? What are they suppose to do with a pot?

But two things:

  • Post a schematic. NO Fritzing breadboard mess please. Simple hand drawing will do.
  • Post code you tried to test it with. Should just be a tiny program I think :slight_smile:

The pot dims the LEDs using the MOSFET, like the Arduino should do.

I've quickly drawn a simple schematic:

This is the code I was using:

void setup(){
pinMode(13,OUTPUT);
}
void loop()
{
digitalWrite(13,HIGH);
delay(1000);
digitalWrite(13,LOW);
delay(1000);
}

And when I connect a variable resistor (like a potmeter) between the Arduino ground and signal wires, dimming the LED works fine like it should. Now the question is how to do this with an Arduino.

Here's a video of what it is doing now: Led Mosfet circuit - YouTube

When you use a potentiometer you’re using the MOSFET in it’s linear mode. That’s a bad idea, the MOSFET gets hot.

Have a look at analogWrite() and how to use PWM. That’s how most people do it.

Steve

slipstick:
When you use a potentiometer you’re using the MOSFET in it’s linear mode. That’s a bad idea, the MOSFET gets hot.

Have a look at analogWrite() and how to use PWM. That’s how most people do it.

Steve

I already tried analogWrite, but it does the same as digitalWrite… Also the Mosfet doesn’t get hot, but that’s probably because it’s rated for way more power then I’m currently sending through it.

gfhoihoi72:
I already tried analogWrite, but it does the same as digitalWrite.

No it definitely does not, if you're using it correctly.

Lets see the code where you use analogWrite(). For a start you can't use it on pin 13 because that's not a PWM pin (on most Arduinos). What PWM values have you tried?

Steve

Try adding a 1k current-limiting resistor between the Arduino and the MOSFET gate.

surveyranger:
Try adding a 1k current-limiting resistor between the Arduino and the MOSFET gate.

Sure, you could try that but it would be a waste of time.

If you’re concerned about exceeding the output current rating for an AVR pin for perhaps a millisecond or two, you can add a 100 to 150 ohm resistor in series with the gate. Anything more than that just slows down the switching of the mosfet and significantly increases the power dissipation in the device.

if you don't want to use a MOSFET driver, just use a logic MOSFET

hesam_m:
if you don't want to use a MOSFET driver, just use a logic MOSFET

He is using a logic level MOSFET. That's what an IRL540N is.

Steve

I ordered a digital potentiometer to do the job, since an analog one does exactly what I want and the MOSFET doesn't get hot. I hope that will work, otherwise I'll just use a solid state relais and forget about the dimming. I don't know what I'm doing wrong with the Arduino but nothing seems to work.

Well you've not posted any code that uses analogWrite(). You've not said anything about changing to a PWM pin. And you have not shown any code that even attempts to make changes to what is happening to the LED.

But we're only here trying to help. You are entitled to ignore the help you're given if that's what you prefer.

Steve

gfhoihoi72:
I ordered a digital potentiometer to do the job,

Will probably not, a digi pot is NOT a drop in replacement for a normal pot...

And when using a pot + mosfet, the dim region probably isn't very large. And it might not get hot with a light load, but try a meter of led strip and it will.

I do agree with slipstick you tend to only listen to what you want to hear. IRL540 connected with it's gate to an (5V) Arduino and a shared GND with the Source should do the job just fine. Thousands of people use it every day :wink:

What is that magically led you're driving?

And is there more then you are telling us?

I tried everything everyone said and nothing changes anything about the problem.

For the analogWrite code I used exactly the same but pin 9, for example:

analogWrite(9,255)

The LEDs I'm powering are 4 24V spots using approximately 1 amp at full power, and no, the Mosfet does not get hot with a potmeter.

If anyone has a working solution to get it working I would love to hear it, but I tried almost everything and it just keeps doing the same. It's still only dimming a little bit and not turning off completely like I showed in the video.

Okay, I just tried connecting it like this with a normal LED and the arduino 3.3v as power source and it worked perfectly.

So I guess it's something with connecting the powersupply of the LED spots I'm doing wrong. For the power supply I keep the positive wire directly connected to the leds, negative wire from the leds to the drain pin and negative wire coming from the power supply the source pin. Is that the right way?

EDIT: I tried the same circuit as I posted before (with the 24V led spots) but with a different mosfet I had laying around and it is working fine now! The mosfet I'm using now is a CR02A which is way underpowered to power the leds at full brightness but at least they are dimming and turning off.

So I guess the IRL540N mosfets just aren't the right ones for this use? But which ones are? They have to dim 24V LED spots from 0 to 100% brightness and work with 5/3.3v logic level.

gfhoihoi72:
...but with a different mosfet I had laying around and it is working fine now! The mosfet I'm using now is a CR02A

A CR02A is in the thyristor family and not the same as a MOSFET. They operate a little differently.