Arduino UNO R4 - MOSFET Module

In this guide, we will learn how to use a MOSFET module as a power switch with the Arduino UNO R4. In detail, we will learn:

Arduino UNO R4 and AOD4184, LR7843 or FR120N MOSFET module

Overview of MOSFET Module

A pin of the Arduino UNO R4 gives only 5V and a very small current. That is fine for a small LED, but not for a 12V LED strip, a fan or a pump. A MOSFET module sits in the middle: the Arduino UNO R4 sends a weak signal, and the module opens or closes a strong 12V path for the load.

There are three popular modules: AOD4184 (sometimes sold as D4184), LR7843 and FR120N. The boards look the same. They have the same size, the same pins and the same wiring, and they use the same code. The only change is the MOSFET chip on top.

Why use a MOSFET module and not a relay?

  • It is silent. Nothing moves and nothing clicks.
  • It switches very fast, so it can do PWM. This means you can dim a light or slow down a fan. A relay can only do full ON or full OFF.
  • It has no contacts to wear out, so it lasts a long time.
  • The limit: it works with DC loads only. Never use it with AC mains power. For AC devices, see the Arduino UNO R4 - Relay tutorial.
AOD4184 LR7843 FR120N
MOSFET chip AOD4184A (N-channel) IRLR7843 (N-channel) IRFR120N (N-channel)
Max load voltage (chip rating) 40V DC 30V DC 100V DC
Max current (chip rating) 50A 161A 9.4A
On-resistance RDS(on) about 7 mΩ about 3.3 mΩ about 210 mΩ
Real current without heatsink about 10–15A about 15A about 2A
Control signal 3.3V / 5V, active HIGH 3.3V / 5V, active HIGH 3.3V / 5V, active HIGH
Isolation PC817 optocoupler PC817 optocoupler PC817 optocoupler
PWM yes, up to about 1 kHz yes, up to about 1 kHz yes, up to about 1 kHz
Load type DC only DC only DC only

How to pick one:

  • LR7843: it has the lowest resistance, so it stays the coolest when a big current flows. Choose it for strong 12V or 24V loads, like a long LED strip or a big motor. Its limit is 30V.
  • AOD4184: a good choice for most projects. It handles up to 40V and a strong current, so 12V, 24V and 36V loads are all OK.
  • FR120N: it accepts the highest voltage (up to 100V), but its resistance is high. Keep the current small, about 2A without a heatsink. It suits small 24V or 48V loads.

※ NOTE THAT:

The big numbers like 50A or 161A are the limits of the chip alone. The small module cannot carry that much, because heat is the real limit. After a few minutes of running, touch the MOSFET. If it is too hot to touch, lower the current or add a heatsink.

How It Works

The signal from the Arduino UNO R4 does not touch the MOSFET directly. It goes through a PC817 optocoupler first: pin 9 → PWM pin → small resistor → LED inside the PC817 → light → phototransistor inside the PC817 → MOSFET gate. The MOSFET is an N-channel type and sits between the LOAD and − terminals (a low-side switch). Your device sits between + and LOAD.

So what happens for each signal on pin 9? Let's look at the three cases.

Pin 9 Is LOW (0V): The Device Is Off

  1. No current goes into the LED inside the optocoupler. It stays dark.
  2. The phototransistor stays off, so a resistor on the gate keeps the MOSFET gate at 0V.
  3. The MOSFET is OFF. It works like an open switch between LOAD and −.
  4. The − wire of the device has no path to ground. No current flows, and the device gets 0V.

In code: digitalWrite(MOSFET_PIN, LOW) or analogWrite(MOSFET_PIN, 0).

Pin 9 Is HIGH (5V): The Device Gets Full Power

  1. A few mA flow into the LED inside the optocoupler, and it lights up. It is inside the chip, so you can't see it.
  2. The phototransistor turns on. Now the MOSFET gate gets about half of the load supply, about 6V from a 12V adapter.
  3. The MOSFET turns fully ON. It works like a closed switch with a very low resistance: a few mΩ for the AOD4184 or LR7843, about 0.2Ω for the FR120N.
  4. Current flows in a loop: adapter + → + terminal → device → LOAD terminal → MOSFET → − terminal → adapter −.
  5. The device gets almost the full 12V and runs at full power.

In code: digitalWrite(MOSFET_PIN, HIGH) or analogWrite(MOSFET_PIN, 255). A 3.3V board can do the same job, because the optocoupler LED needs only a small current.

Pin 9 Sends PWM: The Device Gets Part of the Power

  1. Pin 9 flips between LOW and HIGH very fast, about 500 to 1000 times per second (500 Hz to 1 kHz).
  2. The MOSFET copies it: ON in every HIGH part, OFF in every LOW part.
  3. The device gets short 12V pulses. The duty cycle is how much of the time the signal is HIGH. Average voltage and average power = duty cycle × full value.

With analogWrite(MOSFET_PIN, value), the value goes from 0 to 255, and the duty cycle is value / 255. Some examples with a 12V adapter:

  • analogWrite(MOSFET_PIN, 0): 0%, always off, 0V average.
  • analogWrite(MOSFET_PIN, 64): about 25%, on a quarter of the time, about 3V average, about a quarter of the power.
  • analogWrite(MOSFET_PIN, 128): about 50%, on half of the time, about 6V average, about half the power.
  • analogWrite(MOSFET_PIN, 191): about 75%, on three quarters of the time, about 9V average.
  • analogWrite(MOSFET_PIN, 255): 100%, always on, 12V, full power.

What you see: an LED strip gets dimmer (it flickers, but too fast for your eyes). A fan, motor or pump turns slower, because its spinning part smooths out the pulses.

Why the frequency matters: the PC817 is a slow part. If the PWM is too fast, the MOSFET can't switch fully. The device doesn't get clean pulses, and the MOSFET gets hot. The default analogWrite() frequency of the Arduino UNO R4 is already in the safe range, so you don't need to change anything.

Other Points

  • The optocoupler isolates the Arduino UNO R4 side from the 12V side. The signal GND and the load GND are not joined on the module.
  • The gate voltage comes from the load supply, so the load supply must be about 6V or higher. A 5V load supply will not work well. If the load takes more than a few amps, use 9V or more.
  • The board has no flyback diode. Motors, pumps, solenoids and relay coils need one. Add a diode such as 1N5819 or 1N4007 across the load: the stripe side (cathode) goes to the load +, and the other side (anode) goes to the load −.

Pinout

AOD4184, LR7843 and FR120N MOSFET module pinout

The control side is a 2-pin header (2.54mm pitch):

  • PWM pin: connect to a pin of the Arduino UNO R4. This pin receives the ON/OFF or PWM signal.
  • GND pin: connect to GND of the Arduino UNO R4.

The power side has three screw terminals:

  • + pin: connect to the positive wire of the load power supply (for example, 12V) and to the positive wire of the load. Both wires share this one terminal.
  • LOAD pin: connect to the negative wire of the load. This is the side that the MOSFET switches.
  • − pin: connect to the negative wire (ground) of the load power supply.

The labels may look a little different from batch to batch. Always read the text printed on your own board.

Wiring Diagram

The Arduino UNO R4 only drives the PWM and GND pins, while the 12V adapter feeds the load through the screw terminals.

The wiring diagram between Arduino UNO R4  with AOD4184, LR7843 or FR120N MOSFET module

This image is created using Fritzing. Click to enlarge image

From To
Arduino UNO R4 pin 9 MOSFET module PWM
Arduino UNO R4 GND MOSFET module GND
12V adapter + (through DC power jack) MOSFET module +
12V adapter − (through DC power jack) MOSFET module −
LED strip + MOSFET module +
LED strip − MOSFET module LOAD

The optocoupler already sits on the module, so there's no need to add a transistor or a resistor. This makes wiring or soldering easier. Never connect the 12V wires to any pin of the Arduino UNO R4.

More Devices You Can Connect

What if you want to run a fan, a pump or a lock instead of the LED strip? Keep pin 9 and GND as they are. Only the screw terminal side changes. Here are the rules that stay the same for every device:

  • Power adapter: + goes to the + terminal, − goes to the − terminal.
  • Device: its + wire goes to the + terminal too (shared with the adapter +), its − wire goes to LOAD.
  • Voltage: match the adapter to the device (12V device, 12V adapter). Never go below 6V.
  • Current: the FR120N is OK for small devices only (about 2A without a heatsink). For bigger ones, pick the AOD4184 or the LR7843.
  • Diode: a device with a coil inside (fan, motor, pump, solenoid) needs the 1N5819 or 1N4007 flyback diode from the How It Works part. Stripe to device +, other end to device −.

You don't need new code. The code above works for all of them. The only change is for solenoids: use full power or off (100% / 0%), and skip the fade.

Wiring Example: 12V Fan

Arduino UNO R4 MOSFET module wiring with a 12V cooling fan

This image is created using Fritzing. Click to enlarge image

  • Red wire to +, black wire to LOAD.
  • Got a yellow third wire? That's the speed signal. Leave it free.
  • Add the diode. It costs almost nothing and can't hurt.
  • PWM changes the speed. Start above about 30%, because many fans won't spin at a very low duty cycle.

Wiring Example: 12V LED Strip

12V single-color LED strip connected to MOSFET module

This image is created using Fritzing. Click to enlarge image

  • Strip + (often labeled 12V) to +, strip − to LOAD.
  • No diode here. An LED strip has no coil.
  • PWM changes the brightness.
  • Long strips pull more current. Check the current of your strip before you pick the module.
  • Use a single-color strip. RGB and addressable strips need different wiring.

Wiring Example: 12V Water Pump

12V water pump connected to MOSFET module

This image is created using Fritzing. Click to enlarge image

  • Pump + to +, pump − to LOAD.
  • Put the diode across the pump.
  • PWM changes the flow.
  • Don't let the pump run without water.

Wiring Example: 12V DC Motor

12V DC motor and MOSFET module wiring

This image is created using Fritzing. Click to enlarge image

  • Motor + to +, motor − to LOAD.
  • Put the diode across the motor: stripe on the motor + side.
  • PWM changes the speed.
  • The motor spins one way only. Need to reverse it? Use a motor driver like the L298N. See the Arduino UNO R4 - DC Motor tutorial.

Wiring Example: 12V Solenoid Lock

12V solenoid lock wired to MOSFET module

This image is created using Fritzing. Click to enlarge image

  • Lock + to +, lock − to LOAD.
  • The diode is a must.
  • Full ON or OFF only. No PWM.
  • Don't leave it ON for long, or it heats up. Give it a short ON pulse to unlock.

Wiring Example: 12V Solenoid Valve

Normally closed 12V solenoid valve with MOSFET module

This image is created using Fritzing. Click to enlarge image

See The best way to supply power to the Arduino Uno R4 and other components.

  • Valve + to +, valve − to LOAD.
  • The diode is a must here too.
  • This is a normally closed valve: ON opens it, OFF closes it.
  • Switch it ON or OFF only. Don't use PWM.

How To Program For MOSFET Module

No library is needed. The code uses only built-in functions.

  • Set the pin on Arduino UNO R4 that connects to the PWM pin of the module:
const int MOSFET_PIN = 9;
  • Make the pin an output:
pinMode(MOSFET_PIN, OUTPUT);
  • Turn the load fully on or fully off:
analogWrite(MOSFET_PIN, 255); // full power analogWrite(MOSFET_PIN, 0); // off
  • Set a power level in percent. Convert 0–100% to the 0–255 range first:
int duty = map(percent, 0, 100, 0, 255); analogWrite(MOSFET_PIN, duty);

If you only need ON and OFF, digitalWrite(MOSFET_PIN, HIGH) and digitalWrite(MOSFET_PIN, LOW) also work.

Arduino UNO R4 Code - MOSFET Module

The code below runs one cycle again and again:

  • The load is at full power for 2 seconds.
  • The load is off for 2 seconds.
  • The power goes up from 10% to 100%, 10% more every 0.5 seconds.
  • The power goes down from 90% to 0% in the same way.
  • The code waits 1 second, then starts again.
/* * This Arduino UNO R4 code was developed by newbiely.com * * This Arduino UNO R4 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-r4/arduino-uno-r4-mosfet-module */ const int MOSFET_PIN = 9; // Arduino UNO R4 pin connected to the PWM pin of the MOSFET module void setup() { Serial.begin(9600); pinMode(MOSFET_PIN, OUTPUT); analogWrite(MOSFET_PIN, 0); // start with the load OFF } void setLoad(int percent) { int duty = map(percent, 0, 100, 0, 255); // convert 0-100% to 0-255 analogWrite(MOSFET_PIN, duty); Serial.print("Load power: "); Serial.print(percent); Serial.println("%"); } void loop() { // turn the load fully ON, then fully OFF Serial.println("Load: ON"); setLoad(100); delay(2000); Serial.println("Load: OFF"); setLoad(0); delay(2000); // increase the power step by step (PWM) for (int percent = 10; percent <= 100; percent += 10) { setLoad(percent); delay(500); } // decrease the power step by step (PWM) for (int percent = 90; percent >= 0; percent -= 10) { setLoad(percent); delay(500); } delay(1000); }

Detailed Instructions

Follow these instructions step by step:

  • If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
  • Wire the components according to the provided diagram. Leave the 12V adapter unplugged for now.
  • Connect the Arduino UNO R4 board to your computer using a USB cable.
  • Launch the Arduino IDE on your computer.
  • Select the appropriate Arduino UNO R4 board (e.g., Arduino UNO R4 WiFi or Arduino UNO R4 Minima) and COM port.
  • Copy the code above and paste it into the Arduino IDE.
  • Click the Upload button to send the code to the Arduino UNO R4.
  • Plug in the 12V power adapter.
  • Open the Serial Monitor and set the baud rate to 9600.
  • Watch the LED strip: it is fully bright for 2 seconds, then dark for 2 seconds. After that, it becomes brighter little by little, and then dimmer little by little. With a fan, you will hear the speed go up and down.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino Uno R4 WiFi
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno R4 WiFi' on 'COM15')
New Line
9600 baud
Load: ON Load power: 100% Load: OFF Load power: 0% Load power: 10% Load power: 20% Load power: 30% Load power: 40% Load power: 50% Load power: 60% Load power: 70% Load power: 80% Load power: 90% Load power: 100% Load power: 90% Load power: 80% Load power: 70% Load power: 60% Load power: 50% Load power: 40% Load power: 30% Load power: 20% Load power: 10% Load power: 0%
Ln 11, Col 1
Arduino Uno R4 WiFi on COM15
2

If the LED strip does not light up at all, check the 12V supply first. Then check that the PWM and GND wires go to pin 9 and GND of the Arduino UNO R4.

To learn more about PWM dimming, see the Arduino UNO R4 - Fade LED tutorial.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!