Arduino MOSFET Wiring: Driving a 12V LED Strip

Projects Beginner 10 min read Published:
Arduino MOSFET wiring: driving a 12 V LED strip with the IRLZ44N, cover image

To drive a 12 V LED strip with an Arduino, place an N-channel MOSFET between the strip’s negative lead and ground, and connect its gate to an Arduino PWM pin through a 220 Ω resistor. What matters is that the MOSFET fully turns on at a 5 V gate voltage. The IRLZ44N datasheet guarantees a maximum on-resistance of 0.025 Ω at 5 V. The widely used IRF540N, on the other hand, only specifies a value at 10 V, so it can run hot when driven by an Arduino. This article covers the parts list, wiring diagram, heat calculation and an example PWM sketch.

The topic comes from a question that keeps coming up on the Arduino forum. A user was driving four PC fans from a Nano through an IRF540N and asked which gate resistor to use. The replies pointed out that the IRF540N does not fully turn on with a 5 V gate and that switching to a logic-level MOSFET was the real fix. All MOSFET values in this article are taken from Infineon’s IRLZ44NPbF, IRL540NPbF and IRF540NPbF datasheets.

Schematic for driving a 12 V LED strip with an Arduino: pin D9 through a 220 ohm resistor to the IRLZ44N gate, 10 kiloohm gate-source resistor, strip negative lead to the drain, source to ground and a common GND connection
Arduino LED strip driver circuit. The MOSFET works as a low-side switch on the strip’s negative side; the Arduino GND and the negative of the 12 V adapter are tied together.

Why can’t an Arduino pin drive the strip directly?

The output pins of an Arduino Uno or Nano deliver 5 V and are designed for currents in the range of a few tens of milliamps. An LED strip needs 12 V and, depending on its length, draws several amps. The pin can supply neither that voltage nor that current. The solution is a switch that carries the strip current, leaving the Arduino with only the job of turning that switch on and off.

An N-channel MOSFET suits this job. When a voltage is applied between gate and source, the channel between drain and source starts conducting. The gate itself behaves like a capacitor, so once the gate capacitance is charged it draws no steady current. All the Arduino has to do is charge and discharge that capacitance.

What is a logic-level MOSFET?

A logic-level MOSFET is a MOSFET whose on-resistance (RDS(on)) is also guaranteed at logic-level gate voltages such as 4 V or 5 V. The feature lists in the IRLZ44N and IRL540N datasheets include “Logic Level Gate Drive” (written “Logic-Level Gate Drive” for the IRL540N), and both datasheets give RDS(on) separately for 10 V, 5 V and 4 V. The IRF540N datasheet has a single RDS(on) row, and that row is specified at VGS = 10 V.

A common mistake is to look at the threshold voltage (VGS(th)) and conclude that “5 V is enough.” The threshold voltage is the point where the MOSFET only just starts to conduct. For the IRF540N it is between 2 and 4 V at a drain current of 250 µA (with VDS = VGS). Under that condition the datasheet only defines a current of a quarter of a milliamp. It says nothing about the resistance at which several amps would flow. You need to check the RDS(on) row guaranteed at the gate voltage you will actually apply.

Bar chart comparing the datasheet maximum RDS(on) values of the IRLZ44N, IRL540N and IRF540N MOSFETs at 4 V, 5 V and 10 V gate voltage; no 4 V or 5 V value is given for the IRF540N
Maximum RDS(on) values from the datasheets (TJ = 25 °C). The IRF540N has no guaranteed value at 4 V or 5 V.

IRLZ44N vs IRL540N vs IRF540N

All three MOSFETs come in a TO-220 package with the same pinout. The table below shows the values that matter for use with an Arduino. The RDS(on) values are the maximums given at a junction temperature of 25 °C and at the datasheet test currents (21–25 A for the IRLZ44N, 15–18 A for the IRL540N, 16 A for the IRF540N).

Parameter IRLZ44N IRL540N IRF540N
V(BR)DSS (drain-source breakdown voltage) 55 V 100 V 100 V
ID continuous (TC = 25 °C, VGS = 10 V) 47 A 36 A 33 A
RDS(on) max., VGS = 10 V 0.022 Ω 0.044 Ω 0.044 Ω
RDS(on) max., VGS = 5 V 0.025 Ω 0.053 Ω Not specified
RDS(on) max., VGS = 4 V 0.035 Ω 0.063 Ω Not specified
VGS(th) (at 250 µA) 1.0 – 2.0 V 1.0 – 2.0 V 2.0 – 4.0 V
VGS absolute maximum ±16 V ±16 V ±20 V
Total gate charge Qg max. 48 nC (VGS = 5 V) 74 nC (VGS = 5 V) 71 nC (VGS = 10 V)
Junction-to-ambient thermal resistance RθJA 62 °C/W 62 °C/W 62 °C/W

The continuous current ratings of 47 A, 36 A and 33 A in the table apply with the case held at 25 °C and VGS = 10 V. In a circuit without a heatsink, the limit is set by the heating we calculate below, not by these numbers.

Pinout: gate, drain, source

On all three MOSFETs, with the marked side facing you and the leads pointing down, pin 1 is the gate (G), pin 2 the drain (D) and pin 3 the source (S), from left to right. The metal tab on the back is connected to the drain. So when you screw the MOSFET to a metal enclosure or to a heatsink shared with other parts, you need to insulate the tab; otherwise the drain shorts to the enclosure or to the other parts.

TO-220 N-channel MOSFET pinout: 1 gate, 2 drain, 3 source, metal tab connected to the drain; N-channel MOSFET symbol next to it
Pinout of the IRLZ44N, IRL540N and IRF540N in the TO-220 package. The metal tab is connected to the drain pin.

Parts list

  • Arduino Uno or Nano (a board that runs at 5 V)
  • 1 × IRLZ44N (IRL540N for higher-voltage loads)
  • 220 Ω resistor (gate series resistor)
  • 10 kΩ resistor (between gate and source)
  • Single-color, non-addressable 12 V LED strip
  • 12 V adapter rated for the strip current
  • Hookup wire with a cross-section suited to the strip current

Wiring step by step

  1. Connect the positive of the 12 V adapter to the positive lead of the LED strip.
  2. Connect the strip’s negative lead to the MOSFET drain (pin 2).
  3. Connect the MOSFET source (pin 3) to the adapter’s negative.
  4. Also connect the Arduino GND pin to the adapter’s negative. Without this common ground, the voltage the Arduino applies to the gate has no reference to the MOSFET source, and the circuit will not work.
  5. Run a 220 Ω resistor from Arduino pin D9 to the gate (pin 1).
  6. Connect the 10 kΩ resistor between gate and source.

The high-current loop closes through the adapter, the strip, the drain and the source. Build this loop with short, heavy wire. On the Arduino side there is only the gate signal and the common ground.

What do the 220 Ω and 10 kΩ resistors do?

The 220 Ω series resistor limits the instantaneous current drawn from the pin while the gate capacitance charges. At the moment 5 V is applied to an uncharged gate, the current is at most 5 V / 220 Ω ≈ 23 mA, and it falls as the gate charges. Without the resistor, this initial current is limited only by the pin’s own internal resistance.

The 10 kΩ gate-source resistor keeps the gate from floating while the Arduino powers up or resets and the pin has not yet been configured as an output. A floating gate can pick up noise and hold the MOSFET partially on. This resistor pulls the gate to the source level, so the strip stays off.

Example PWM sketch

Brightness is set by the PWM duty cycle given with analogWrite(). On the Uno R3 and the classic Nano, PWM works only on pins 3, 5, 6, 9, 10 and 11. The sketch below slowly fades the strip up and down:

const int MOSFET_PIN = 9;

void setup() {
  pinMode(MOSFET_PIN, OUTPUT);
}

void loop() {
  for (int d = 0; d <= 255; d++) {
    analogWrite(MOSFET_PIN, d);
    delay(8);
  }
  for (int d = 255; d >= 0; d--) {
    analogWrite(MOSFET_PIN, d);
    delay(8);
  }
}

According to the Arduino documentation, the PWM frequency on the Uno R3 and the classic Nano is about 490 Hz on most pins and about 980 Hz on pins 5 and 6. At these frequencies one period lasts between 1 and 2 ms. The total gate charge of the IRLZ44N is at most 48 nC at 5 V. Assuming an average gate current of 10 mA, the transition time is roughly 48 nC / 10 mA ≈ 5 µs. This is short compared with the period. In the 12 V, 3 A example below, the energy lost at each turn-on and turn-off is roughly 0.5 × 12 V × 3 A × 5 µs; at 490 Hz that amounts to a switching loss of about 0.1 W, and about 0.2 W at 980 Hz. Because the 48 nC figure in the datasheet is specified at a 25 A, 44 V test condition, the actual transition time in this example is somewhat shorter.

Worked example: how hot does the MOSFET get?

A strip labeled 12 V, 36 W draws 36 / 12 = 3 A. With the strip at full brightness, the power dissipated in the MOSFET is P = I² × RDS(on).

We leave margin in two places. The first is the gate voltage: the 220 Ω and 10 kΩ resistors form a small voltage divider, so the gate sees 5 × 10 000 / 10 220 ≈ 4.9 V. On a USB-powered board the 5 V rail is also often slightly below 5 V. For this reason we use the datasheet’s 4 V row instead of the 5 V row. The second is temperature: RDS(on) rises with temperature. According to Fig. 4 in the datasheets, at a junction temperature of 100 °C the resistance reaches about 1.5 times its 25 °C value for the IRLZ44N and about 1.6 times for the IRL540N. These curves are drawn for VGS = 10 V; we apply the same factors to the 4 V value.

Step IRLZ44N IRL540N
RDS(on) max., 4 V, 25 °C 0.035 Ω 0.063 Ω
With temperature margin × 1.5 = 0.0525 Ω × 1.6 ≈ 0.101 Ω
Conduction loss (3 A) 9 × 0.0525 ≈ 0.47 W 9 × 0.101 ≈ 0.91 W
Temperature rise (× 62 °C/W, no heatsink) ≈ 29 °C ≈ 56 °C

The switching loss of about 0.1 W from PWM adds to these values. For the IRLZ44N the total loss is about 0.57 W and the temperature rise about 35 °C; in a 25 °C room the junction stays around 60 °C and no heatsink is needed. The IRL540N heats up noticeably but stays below its 175 °C junction limit. You can also run the same calculation in reverse to find the limit without a heatsink. With a 40 °C ambient and a target junction temperature of 100 °C, the allowed total dissipation is (100 − 40) / 62 ≈ 0.97 W. Leaving room for the switching loss, this corresponds to about 4 A for the IRLZ44N and about 3 A for the IRL540N. Use a heatsink for higher currents.

We cannot do the same calculation for the IRF540N, because its datasheet gives no guaranteed RDS(on) at 5 V. Even if the circuit seems to work on the bench, how hot it gets at a given current is unknown. Unless you have a driver stage that drives the gate at 10 V, choosing a logic-level MOSFET is the safer option for Arduino projects.

Common mistakes

  • Using a MOSFET that is not logic level: Parts such as the IRF540N can stay partially on at 5 V, heat up, and the strip may not reach full brightness.
  • Forgetting the common ground: If the Arduino GND is not connected to the adapter’s negative, the MOSFET behaves unpredictably.
  • Putting the MOSFET on the strip’s positive side: In this circuit the N-channel MOSFET’s source must be at ground. On the positive side, the source sits at about 12 V, and turning the MOSFET on requires the gate to rise a few volts above 12 V. The Arduino’s 5 V cannot provide this.
  • Using a MOSFET for an addressable strip: Strips such as the WS2812 have a driver in every LED and are controlled directly from the data line. The MOSFET method in this article is for single-color or analog RGB strips.
  • Skipping the diode on inductive loads such as motors and relays: A coil produces a reverse voltage when its current is interrupted. Connect a reverse-biased diode across the load. You can find which diode to use where in our 1N4007, UF4007 and 1N5819 comparison. An LED strip is not an inductive load and does not need a diode.
  • Mounting the tab without insulation: The tab is connected to the drain; if it touches a metal enclosure, it causes a short.

Frequently asked questions

Does the IRF540N work with an Arduino?

It may appear to work at low currents, but its datasheet does not guarantee an RDS(on) at a 5 V gate voltage. Because the threshold voltage can be as high as 4 V, some parts will not turn on enough at 5 V and will heat up. For circuits driven directly from an Arduino, use a logic-level MOSFET such as the IRLZ44N or IRL540N.

Can the IRLZ44N be driven by 3.3 V boards such as the ESP32?

The IRLZ44N datasheet specifies RDS(on) down to a minimum gate voltage of 4 V. No value is guaranteed at 3.3 V. To drive it reliably from a 3.3 V board, either use an intermediate stage that drives the gate at a higher voltage, or choose a MOSFET whose datasheet specifies RDS(on) at 2.5 V or 3.3 V.

Is a gate resistor required, and what value should it be?

With short wiring and low frequencies, the circuit often works without one, but a resistor between 100 and 220 Ω limits the pin’s instantaneous current and is cheap insurance. Making the resistor too large (for example, several kΩ) slows the transitions and lengthens the time the MOSFET spends in the in-between region during PWM.

How do you drive an RGB strip?

On a common-anode 12 V RGB strip, the common lead connects to 12 V. The red, green and blue leads each go to the drain of a separate MOSFET. The gates of the three MOSFETs are driven from three separate PWM pins, using the resistor arrangement in this article.

Do I need a heatsink?

According to the conservative calculation above, the IRLZ44N can be used without a heatsink up to about 4 A at a 40 °C ambient. For higher currents, in a closed box or at high ambient temperatures, add a heatsink and remember to insulate the tab.

Conclusion

When driving an LED strip, fan or small motor with an Arduino, the yardstick for choosing a MOSFET is the RDS(on) row the datasheet gives for a 5 V (or at least 4 V) gate voltage. The IRLZ44N, at no more than 0.025 Ω at 5 V and 0.035 Ω at 4 V, carries loads of several amps without a heatsink. The IRL540N’s 100 V rating leaves margin in higher-voltage systems, but its on-resistance is about twice that of the IRLZ44N. The IRF540N is suited to circuits that drive the gate at 10 V. When wiring, remember the common ground, the 220 Ω series resistor and the 10 kΩ gate-source resistor.

IRLZ44NPBFInfineon Technologies · ETS4939920108$2.17Lead timeView

You can find other options in the Single MOSFETs category. You can check whether a MOSFET you have is working with the steps in our MOSFET testing article. If you want to drive smaller loads with a single IC, take a look at our ULN2003 article.

Sources

Products in this article

More from Projects