Arduino Nano - MOSFET Module
This tutorial instructs you how to use Arduino Nano to switch and dim a 12V DC load through a MOSFET module. The small Nano sits on a breadboard and only gives a 5V signal, while the MOSFET module handles the heavy 12V side. In detail, we will learn:
- How to connect Arduino Nano to the MOSFET module (AOD4184, LR7843 or FR120N)
- How to connect a 12V LED strip and a 12V power adapter to the module
- How to program Arduino Nano to turn the load ON/OFF and to set its power level with PWM
We suggest:
- Utilizing a relay if you are looking to switch an AC mains device. A MOSFET module works with DC loads only.
- Utilizing a PC817 optocoupler if you are looking to do the opposite job: read a 12V or 24V signal with Arduino Nano.
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of MOSFET Module
An Arduino Nano pin can give only a few milliamps at 5V. That is enough for a small LED, but not for a 12V LED strip, a fan or a pump. The MOSFET module sits between the two worlds. The Nano sends a small signal, and the MOSFET on the module opens or closes the path for the big 12V current.
This one tutorial covers three modules: AOD4184 (also sold as D4184), LR7843 and FR120N. They use the same board design, with the same size, pins, wiring and code. Only the MOSFET chip on the board is different.
| AOD4184 | LR7843 | FR120N | |
|---|---|---|---|
| MOSFET | AOD4184A (N-channel) | IRLR7843 (N-channel) | IRFR120N (N-channel) |
| Max load voltage (MOSFET rating) | 40V DC | 30V DC | 100V DC |
| Max current (MOSFET rating) | 50A | 161A | 9.4A |
| On-resistance RDS(on) | about 7 mΩ | about 3.3 mΩ | about 210 mΩ |
| Practical current without heatsink | about 10–15A | about 15A | about 2A |
| Control signal | 3.3V / 5V logic, active HIGH | 3.3V / 5V logic, active HIGH | 3.3V / 5V logic, active HIGH |
| Isolation | PC817 optocoupler | PC817 optocoupler | PC817 optocoupler |
| PWM | yes, keep ≤ ~1 kHz | yes, keep ≤ ~1 kHz | yes, keep ≤ ~1 kHz |
| Load type | DC only | DC only | DC only |
Why pick a MOSFET module and not a relay? It makes no clicking sound, it has no moving parts, it switches very fast and it lasts a long time. Most of all, it supports PWM, so the Nano can dim a LED strip or slow down a fan. A relay can only do ON and OFF.
The MOSFET Module Pinout

The module has two groups of pins. The control group is a small 2-pin header with 2.54mm pitch, so it drops straight into a breadboard next to the Nano:
- PWM pin: must be connected to a PWM-capable Arduino Nano pin (D9 in this tutorial). This pin receives the control signal
- GND pin: must be connected to the GND pin of Arduino Nano (signal ground)
The power group has three screw terminals, because it carries the load current:
- + pin: must be connected to the positive (+) of the load power supply, for example 12V, and to the positive wire of the load. Both wires share this one terminal
- LOAD pin: must be connected to the negative wire of the load. This is the switched side, and it goes to the MOSFET drain
- − pin: must be connected to the negative (−) of the load power supply
※ NOTE THAT:
The arrangement of pins on a module may differ from one manufacturer to another. The labels can also change a little between batches. It is essential to always refer to the labels printed on the module when using it. Take a close look!
How the Module Works
The signal from the Nano does not go to the MOSFET directly. It takes this path: Nano pin D9 → PWM pin → small resistor → LED inside the PC817 optocoupler → light → phototransistor inside the PC817 → MOSFET gate. A pull-down resistor on the gate keeps it at 0V while the optocoupler is off. The MOSFET sits between the LOAD terminal and the − terminal, and the load sits between + and LOAD.
The module reacts in three different ways, depending on what the Nano puts on the PWM pin.
Case 1: The PWM Pin Is LOW (0V)
- No current flows into the optocoupler, so its LED stays dark.
- The phototransistor stays off. The pull-down resistor holds the MOSFET gate at 0V.
- The MOSFET is OFF. Between LOAD and −, it behaves like an open switch.
- The − wire of the LED strip has no path to the adapter −, so no current flows. The strip gets 0V and stays dark.
- In code: digitalWrite(MOSFET_PIN, LOW) or analogWrite(MOSFET_PIN, 0).
Case 2: The PWM Pin Is HIGH (5V)
- The 5V pin pushes a few mA through the optocoupler LED. It lights up inside the chip, where you cannot see it.
- The light turns on the phototransistor. Now the MOSFET gate gets about half of the load supply, about 6V with a 12V adapter.
- The MOSFET turns fully ON. It behaves like a closed switch with a very low resistance: a few mΩ for the AOD4184 and LR7843, about 0.2Ω for the FR120N.
- The current flows in a loop: adapter + → + terminal → LED strip → LOAD terminal → MOSFET → − terminal → adapter −.
- The strip gets almost the full 12V and shines at full brightness.
- In code: digitalWrite(MOSFET_PIN, HIGH) or analogWrite(MOSFET_PIN, 255).
Case 3: The PWM Pin Receives a PWM Signal
- The pin flips between 0V and 5V about 490 times per second (the default analogWrite() rate on D9).
- The MOSFET follows each pulse: it is ON during every HIGH part and OFF during every LOW part.
- The load receives 12V pulses. The duty cycle is the share of time the pin is HIGH, and the average voltage and power equal the duty cycle times the full value.
- In code: analogWrite(MOSFET_PIN, value), where value is 0 to 255 and the duty cycle is value / 255. The tutorial code goes from 10% to 100% in steps.
| Duty cycle | analogWrite() value | Load is ON | Average voltage (12V supply) | Power |
|---|---|---|---|---|
| 0% | 0 | never | 0V | off |
| 25% | 64 | 1/4 of the time | about 3V | about a quarter |
| 50% | 128 | half of the time | about 6V | about half |
| 75% | 191 | 3/4 of the time | about 9V | about three quarters |
| 100% | 255 | all the time | 12V | full |
- An LED strip looks dimmer. It still flickers, but too fast for the eye to notice.
- A fan, motor or pump runs slower, because its spinning mass smooths out the pulses.
- The PC817 is a slow part, so the PWM frequency must stay at about 500 Hz to 1 kHz. At a much higher frequency, the MOSFET does not switch fully, the load does not get clean pulses, and the MOSFET gets hot. The 490 Hz of pin D9 is fine.
A few more points are important for your project:
- Isolated grounds: Signal GND and load GND are NOT connected on the module. The Nano side and the 12V side are electrically separated by the optocoupler.
- Low-side switch: The MOSFET is an N-channel type. It switches the negative wire of the load, not the positive wire.
- Load supply of at least about 6V: As shown in Case 2, the gate voltage comes from the load supply through a voltage divider. Because of this, the load supply must be at least about 6V. Use 9V or more if the load draws more than a few amps. The module will NOT work well with a 5V load supply, so do not use the Nano's 5V pin to power the load.
- Small control current: The optocoupler LED needs only a few mA, so a Nano pin can drive it directly with no extra transistor.
- No flyback diode on board: For motors, pumps, solenoids and relays (inductive loads), add an external flyback diode (for example 1N5819 or 1N4007) across the load. The cathode (the side with the stripe) goes to load +, and the anode goes to load −.
Wiring Diagram
The Nano and the module share only two wires (signal and GND), and the 12V adapter feeds the load side through the DC power jack, as shown below.

This image is created using Fritzing. Click to enlarge image
| From | To |
|---|---|
| Arduino Nano pin D9 | MOSFET module PWM pin |
| Arduino Nano GND | MOSFET module GND pin |
| 12V adapter + (via DC power jack) | MOSFET module + |
| 12V adapter − (via DC power jack) | MOSFET module − |
| LED strip + | MOSFET module + (same terminal as the adapter +) |
| LED strip − | MOSFET module LOAD |
WARNING
Never connect the 12V wires to any pin of the Arduino Nano. The 12V goes only to the screw terminals of the MOSFET module.
Wiring the MOSFET Module to Other 12V Devices
The LED strip is only one option. The examples below show other common 12V loads. On the Nano side, nothing changes: D9 goes to PWM and GND goes to GND. Only the screw terminal side is different. The table gives a quick overview:
| Device | Flyback diode | How to control it |
|---|---|---|
| 12V LED strip (single color) | Not needed | PWM (brightness) |
| 12V DC motor | Needed | PWM (speed) |
| 12V cooling fan | Needed | PWM (speed) |
| 12V water pump | Needed | PWM (flow) |
| 12V solenoid lock | Needed | ON/OFF only |
| 12V solenoid valve | Needed | ON/OFF only |
For every device, the adapter voltage must match the device voltage (a 12V device needs a 12V adapter), and it must be at least 6V. Also check how much current the device draws. The FR120N module is only for small loads of about 2A without a heatsink. For bigger loads, select the AOD4184 or LR7843 module.
The same Arduino Nano code works for all of these devices. For the solenoid lock and the solenoid valve, use only HIGH and LOW (100% or 0%) in place of the fade.
The 12V LED Strip Wiring Example

This image is created using Fritzing. Click to enlarge image
- The + wire of the strip (often marked 12V) must be connected to +, and the − wire must be connected to LOAD.
- A LED strip is not a coil load, so it does not need a flyback diode.
- PWM sets the brightness.
- This example is for a single-color strip only. RGB and addressable strips are wired in a different way. A longer strip draws more current, so check its current before choosing the module.
The 12V DC Motor Wiring Example

This image is created using Fritzing. Click to enlarge image
| From | To |
|---|---|
| Motor + | MOSFET module + |
| Motor − | MOSFET module LOAD |
| 1N5819 or 1N4007 diode, cathode (stripe) | Motor + |
| 1N5819 or 1N4007 diode, anode | Motor − |
A motor is a coil load. The diode across the motor wires protects the MOSFET from the voltage spike when the motor turns off (see "No flyback diode on board" above). PWM sets the speed. The module can drive the motor in one direction only. To change the direction, use a motor driver such as the L298N, as in the Arduino Nano - DC Motor tutorial.
The 12V Cooling Fan Wiring Example

This image is created using Fritzing. Click to enlarge image
- The red wire is +, and it must be connected to +. The black wire is −, and it must be connected to LOAD.
- If the fan has a third wire (yellow, the speed signal), leave it unconnected.
- Add the flyback diode in the same way as for the DC motor. It is cheap and causes no harm.
- PWM sets the speed. Some fans do not start at a very low duty cycle, so start above about 30%.
The 12V Water Pump Wiring Example

This image is created using Fritzing. Click to enlarge image
- Pump + goes to +, and pump − goes to LOAD.
- A pump has a motor inside, so the same flyback diode is required.
- PWM sets the flow. Never let the pump run dry.
The 12V Solenoid Lock Wiring Example

This image is created using Fritzing. Click to enlarge image
- Lock + goes to +, and lock − goes to LOAD. The coil inside also requires the flyback diode.
- Drive it only fully ON or fully OFF. Do not use PWM dimming.
- The lock gets hot if it stays ON for a long time. Turn it ON only for a short moment to unlock, then turn it OFF.
The 12V Solenoid Valve Wiring Example

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Nano and other components.
- Valve + goes to +, and valve − goes to LOAD, with the flyback diode across the coil.
- This is a normally closed valve: fully ON opens the valve, and OFF closes it.
- Use ON/OFF only, not PWM.
How To Program For MOSFET Module
No library is needed. The module is driven with the built-in Arduino functions.
- The first step is to specify the Arduino Nano pin that is connected to the PWM pin of the module. It must be a PWM pin (marked with ~ on the Nano, such as D9):
- Set the pin as an output in setup():
- To turn the load fully ON or fully OFF, a simple digital write is enough:
- To set a power level, write a PWM value from 0 to 255. It is easier to think in percent, so the percent value is converted with map():
Arduino Nano Code for MOSFET Module
The code below does the following in a loop:
- Turns the load fully ON for 2 seconds, then fully OFF for 2 seconds
- Raises the power from 10% to 100% in 10% steps, one step every 0.5 seconds
- Lowers the power from 90% back to 0% in the same way
- Waits 1 second, then starts again
Detailed Instructions
- If this is the first time you use Arduino Nano, see how to set up the environment for Arduino Nano in Arduino IDE.
- Wire the components as shown in the diagram. Do not plug in the 12V adapter yet.
- Connect the Arduino Nano board to your computer using a USB cable.
- Open Arduino IDE on your computer.
- Select the Arduino Nano board and its COM port.
- Copy the above code and paste it into Arduino IDE.
- Click the Upload button to upload the code to the Arduino Nano.
- 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, off for 2 seconds, then it slowly gets brighter and slowly gets dimmer.
- See the result on the Serial Monitor:
If you use a 12V fan in place of the LED strip, the fan runs at full speed, stops, then speeds up and slows down step by step.
Additional Knowledge
AOD4184 vs LR7843 vs FR120N: Which One to Choose
All three modules connect to the Arduino Nano in the same way. The choice depends on your load voltage and current.
| AOD4184 | LR7843 | FR120N | |
|---|---|---|---|
| Max load voltage | 40V DC | 30V DC | 100V DC |
| On-resistance | about 7 mΩ | about 3.3 mΩ | about 210 mΩ |
| Practical current without heatsink | about 10–15A | about 15A | about 2A |
| Good for | 12V/24V/36V loads | 12V/24V loads with big current | 24V/48V small loads |
- LR7843: It has the lowest resistance, so it runs coolest at high current. It is best for high-power 12V/24V LED strips and big motors. The limit is 30V.
- AOD4184: It is a good all-rounder. It works up to 40V and handles strong current.
- FR120N: It handles the highest voltage (up to 100V), but its resistance is the highest. It is only for small currents, about 2A without a heatsink.
It is evident that the LR7843 is the best pick for heavy 12V/24V loads, while the FR120N is the only choice above 40V.
※ NOTE THAT:
The big current numbers (50A for AOD4184, 161A for LR7843) are the limits of the MOSFET chip. They are NOT what the small module board can carry. The real limit is heat. After a few minutes of running, touch the MOSFET carefully. If it is too hot to hold, reduce the load or add a heatsink.
MOSFET Module vs Relay
| MOSFET Module | Relay | |
|---|---|---|
| Load type | DC only | DC or AC |
| PWM (dimming, speed control) | Yes | No |
| Noise | Silent | Clicks |
| Moving parts | None | Yes |
| Switching speed | Very fast | Slow |
For a Nano project on a breadboard that controls a 12V LED strip, fan or pump, the MOSFET module is the better choice. For AC mains devices, use a relay.