Arduino Nano 33 IoT - MOSFET Module
This tutorial instructs you how to use the Arduino Nano 33 IoT to switch and dim a 12V DC load through a MOSFET module. The Nano 33 IoT has 3.3V pins, and they cannot power a 12V LED strip or motor on their own. The MOSFET module does the heavy work, while the board only sends a small signal. In detail, we will learn:
- How the AOD4184, LR7843 and FR120N MOSFET modules work, and how they differ
- How to connect the Arduino Nano 33 IoT to a MOSFET module and a 12V load
- How to program the Arduino Nano 33 IoT to turn the load ON and OFF
- How to program the Arduino Nano 33 IoT to set the load power with PWM
We suggest:
- Utilizing a relay if you are looking to switch an AC device. A MOSFET module works with DC loads only.
- Utilizing a PC817 optocoupler if you are looking to read a 12V or 24V signal instead of driving one.
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
A MOSFET module is an electronic power switch. The Arduino Nano 33 IoT sends a weak signal to it, and the module opens or closes the path of a much bigger DC current. With it, the board can control a 12V LED strip, a DC motor, a fan, a pump, a solenoid valve or a heater.
This tutorial covers three modules: AOD4184 (also sold as D4184), LR7843 and FR120N. They share the same board design, the same size, the same pins and the same wiring. Only the MOSFET chip on top is different. So the code and the wiring in this tutorial work with all three.
Unlike a relay, the MOSFET module has no moving parts. It does not click, it switches very fast, and it lasts a long time. The biggest plus is PWM support: the board can set the power of the load, not only turn it ON or OFF. The downside is that it handles DC loads only. Never use it with AC mains.
| 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 |
The MOSFET Module Pinout

The pins are split into two sides. The control side is a 2-pin header (2.54mm pitch, breadboard friendly):
- PWM pin: must be connected to a GPIO pin of the Arduino Nano 33 IoT. It receives the control signal.
- GND pin: must be connected to GND of the Arduino Nano 33 IoT. This is the signal ground.
The power side has three screw terminals:
- + terminal: must be connected 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 terminal: must be connected to the negative wire of the load. This is the switched side, linked to the MOSFET drain.
- − terminal: must be connected to the negative wire (ground) of the load power supply
※ NOTE THAT:
The arrangement of pins on a module may differ from one manufacturer to another, and the labels can change a bit between batches. It is essential to always refer to the labels printed on the module when using it. Take a close look!
How It Works With a 3.3V Board
The Arduino Nano 33 IoT is a 3.3V board. Many power parts need 5V or more to turn on, but this module is different. Its PWM pin does not go straight to the MOSFET. The signal takes this path:
PWM pin → small resistor → LED inside the PC817 optocoupler → light → phototransistor inside the PC817 → MOSFET gate
The board signal only needs to light the small LED inside the optocoupler. The gate voltage comes from the load supply, not from the Arduino Nano 33 IoT. This gives two results:
- The board side and the load side are electrically isolated. Signal GND and load GND are not connected on the module.
- The 12V stays on the power side. It never needs to touch the board.
The MOSFET is an N-channel, low-side switch. It sits between the LOAD terminal and the − terminal, and the load sits between the + terminal and the LOAD terminal. So the module switches the negative wire of the load, not the positive one. The logic is active HIGH. The three cases below show what happens inside the module, step by step.
Case 1: The PWM Pin Is at 0V (LOW)
- No current flows into the LED inside the optocoupler, so the LED stays dark.
- The phototransistor stays off. A resistor on the gate pulls the MOSFET gate down to 0V.
- The MOSFET is OFF. Between LOAD and − it acts like an open switch.
- The negative wire of the load is not connected to ground, so no current can flow. The load is OFF, with 0V across it.
- Code: digitalWrite(MOSFET_PIN, LOW) or analogWrite(MOSFET_PIN, 0).
Case 2: The PWM Pin Is at 3.3V (HIGH)
- 3.3V is a valid HIGH for this module. No level shifter is needed. A 5V board works in the same way.
- The reason: the optocoupler LED needs only a few mA. A 3.3V pin of the Nano 33 IoT gives this current with no problem. The LED lights up inside the chip, where you cannot see it.
- The phototransistor turns on. The MOSFET gate gets about half of the load supply (about 6V from a 12V supply).
- The MOSFET turns fully ON. It acts like a closed switch with very low resistance: a few mΩ for the AOD4184 and LR7843, about 0.2Ω for the FR120N.
- Current flows: adapter + → + terminal → load → LOAD terminal → MOSFET → − terminal → adapter −. The load gets almost the full 12V and runs at full power.
- Code: digitalWrite(MOSFET_PIN, HIGH) or analogWrite(MOSFET_PIN, 255).
Case 3: A PWM Signal Is on the PWM Pin
- The pin switches between 0V and 3.3V very fast, about 500 to 1000 times per second (500 Hz to 1 kHz).
- The MOSFET follows the signal. It is ON during each HIGH part and OFF during each LOW part, so the load gets 12V pulses.
- The duty cycle is the share of time the signal is HIGH. The average voltage and the average power are equal to the duty cycle times the full value.
- In code, analogWrite(MOSFET_PIN, value) takes a value from 0 to 255. The duty cycle is value / 255.
| Duty cycle | analogWrite() value | What the 12V load gets |
|---|---|---|
| 0% | 0 | Always OFF, 0V on average |
| 20% | 51 | ON 1/5 of the time, about 2.4V on average |
| 40% | 102 | ON 2/5 of the time, about 4.8V on average |
| 60% | 153 | ON 3/5 of the time, about 7.2V on average |
| 80% | 204 | ON 4/5 of the time, about 9.6V on average |
| 100% | 255 | Always ON, the full 12V |
- An LED strip looks dimmer. It really flickers, but too fast for the eye to see.
- A motor, fan or pump runs slower. Its spinning mass smooths the pulses.
- The PWM frequency must stay low, because the PC817 is slow. If the frequency is too high, the MOSFET does not switch fully. The load does not get clean pulses, and the MOSFET gets hot.
Wiring Diagram
The example circuit uses a 12V LED strip, powered by a 12V adapter through a DC power jack, with pin D9 of the Arduino Nano 33 IoT sending the signal.

This image is created using Fritzing. Click to enlarge image
| From | To |
|---|---|
| Arduino Nano 33 IoT D9 | MOSFET module PWM |
| Arduino Nano 33 IoT GND | MOSFET module GND |
| 12V adapter + (via DC power jack) | MOSFET module + |
| 12V adapter − (via DC power jack) | MOSFET module − |
| LED strip + | MOSFET module + |
| LED strip − | MOSFET module LOAD |
WARNING
The Arduino Nano 33 IoT works with 3.3V logic. Never connect the 12V supply, or any wire from the power side of the module, to a pin of the board. Only the PWM and GND pins of the module go to the Nano 33 IoT.
A few rules for the power side:
- The load supply must be at least about 6V, because the gate is fed from half of this voltage. A 5V load supply will not work well. Use 9V or more if the load draws more than a few amps.
- The supply voltage must match the load. A 12V device must be powered by a 12V adapter.
- The module must be chosen by the load current. The FR120N is suited to small loads only (about 2A without a heatsink). For bigger loads, the AOD4184 or the LR7843 must be used.
Connecting Other 12V Loads
The LED strip is only one option. The board side never changes: D9 goes to PWM, and GND goes to GND. Only the screw terminal side is different from one load to another. In every example below, the 12V adapter + is connected to the + terminal, and the 12V adapter − is connected to the − terminal. The load + wire shares the + terminal with the adapter +. The tables show the load wires only.
The module has no flyback diode. A coil load, such as a motor, a fan, a pump or a solenoid, must have an external diode (1N5819 or 1N4007) placed across its two wires:
- Cathode (the side with the stripe): to the load + wire
- Anode: to the load − wire
Without it, the voltage spike from the coil can damage the MOSFET.
The same code works with every load in this part. For a solenoid, only HIGH and LOW (100% or 0%) must be used, not the fade.
Example 1: Single-Color 12V LED Strip

This image is created using Fritzing. Click to enlarge image
| Load wire | Module terminal |
|---|---|
| LED strip + (often marked 12V) | + |
| LED strip − | LOAD |
- No diode is needed. An LED strip is not a coil load.
- The PWM duty cycle sets the brightness.
- A longer strip draws more current. Its current must be checked before a module is chosen.
- This wiring is for single-color strips. RGB and addressable strips are wired in a different way.
Example 2: 12V Cooling Fan

This image is created using Fritzing. Click to enlarge image
| Load wire | Module terminal |
|---|---|
| Fan red wire (+) | + |
| Fan black wire (−) | LOAD |
| Fan yellow wire (speed signal, if present) | Not connected |
- Add the flyback diode as described above. It is cheap and does no harm.
- The PWM duty cycle sets the fan speed.
- Some fans do not start at a very low duty cycle. Begin above about 30%.
Example 3: 12V DC Motor

This image is created using Fritzing. Click to enlarge image
| Load wire | Module terminal |
|---|---|
| Motor + | + |
| Motor − | LOAD |
- A flyback diode is required: stripe to motor +, other side to motor −.
- The PWM duty cycle sets the motor speed.
- The module can turn the motor in one direction only. To reverse it, a motor driver such as the L298N must be used. See the Arduino Nano 33 IoT - DC Motor tutorial.
Example 4: 12V Water Pump

This image is created using Fritzing. Click to enlarge image
| Load wire | Module terminal |
|---|---|
| Pump + | + |
| Pump − | LOAD |
- The pump has a motor inside, so the flyback diode is required.
- The PWM duty cycle sets the water flow.
- The pump must never run dry.
Example 5: 12V Solenoid Valve (Normally Closed)

This image is created using Fritzing. Click to enlarge image
| Load wire | Module terminal |
|---|---|
| Valve + | + |
| Valve − | LOAD |
- The valve coil requires the flyback diode.
- Full ON opens the valve. OFF closes it.
- Only ON and OFF must be used. PWM is not suited to a valve.
Example 6: 12V Solenoid Lock

This image is created using Fritzing. Click to enlarge image
| Load wire | Module terminal |
|---|---|
| Lock + | + |
| Lock − | LOAD |
- The lock coil requires the flyback diode too.
- Only 100% or 0% must be used. Do not dim it with PWM.
- The lock gets hot if it stays ON for a long time. Turn it ON for a short moment to unlock, then turn it OFF.
How To Program Arduino Nano 33 IoT for MOSFET Module
No library is needed. The built-in digitalWrite() and analogWrite() functions are enough.
- The first step is to specify the Arduino Nano 33 IoT pin that is connected to the PWM pin of the module:
- Then, the pin is configured as an output in setup():
- To switch the load fully ON or fully OFF, the pin is set to HIGH or LOW:
- To set the load power, a PWM value from 0 to 255 is written to the pin. The code converts a percentage to this range with map():
As explained in the How It Works part, the PWM frequency must stay low. The default analogWrite() frequency is fine, so there is nothing to change.
Arduino Nano 33 IoT Code for MOSFET Module
The code below turns the load ON for 2 seconds and OFF for 2 seconds. Then it raises the power from 10% to 100% in 10% steps, one step every 0.5 second. After that, it lowers the power from 90% back to 0%, waits 1 second, and repeats.
Detailed Instructions
If this is the first time you use Arduino Nano 33 IoT, see how to set up the environment for Arduino Nano 33 IoT in Arduino IDE.
- Wire the components as shown in the diagram. Keep the 12V adapter unplugged while you wire.
- Connect the Arduino Nano 33 IoT board to your computer using a Micro USB cable.
- Open Arduino IDE on your computer.
- Select the Arduino NANO 33 IoT board and its COM port.
- Copy the code above and paste it into the Arduino IDE.
- Click the Upload button to compile and upload the code to the board.
- Plug in the 12V power adapter.
- Open the Serial Monitor and set the baud rate to 9600.
- Watch the LED strip: it shines at full brightness for 2 seconds, turns off for 2 seconds, then slowly gets brighter, and then slowly gets dimmer.
If you use a 12V fan instead of the LED strip, the fan spins at full speed, stops, then speeds up and slows down in the same pattern. Remember the flyback diode for a fan or motor.
Additional Knowledge
AOD4184 vs LR7843 vs FR120N
All three boards plug in the same way, so the choice depends only on the load:
| Module | Best for | Limits |
|---|---|---|
| LR7843 | 12V/24V loads with big current, such as high-power LED strips and big motors. Lowest resistance, so it runs coolest. | Max 30V |
| AOD4184 | A good all-rounder for 12V/24V/36V loads with strong current | Max 40V |
| FR120N | 24V/48V loads with small current | Highest resistance, about 2A without heatsink |
It is evident that the LR7843 is the best pick for high current at 12V or 24V, while the FR120N is the only one of the three for loads above 40V.
Keep in mind that the rated current (50A for AOD4184, 161A for LR7843) is the limit of the chip, not of the small board. The real limit is heat. After a few minutes of running, touch the MOSFET carefully. If it is too hot to touch, lower the current or add a heatsink.
MOSFET Module vs Relay
| MOSFET Module | Relay | |
|---|---|---|
| Moving parts | None, silent | Yes, it clicks |
| Switching speed | Very fast | Slow |
| PWM (speed / brightness) | Yes | No |
| Lifetime | Long | Limited by the contacts |
| Load type | DC only | DC or AC |
It is evident that the MOSFET module is the better choice for DC loads, especially when you need dimming or speed control. For AC devices, use a relay instead.