Arduino - MOSFET Module
This is a compact build guide. The full tutorial, with the wiring diagram and a line-by-line walkthrough of the code, is here: https://arduinogetstarted.com/tutorials/arduino-mosfet-module
An Arduino pin only gives 5V and a tiny current, not enough to run a 12V LED strip, fan or motor. A MOSFET module (AOD4184, LR7843 or FR120N) sits between Arduino and the load, letting a small PWM signal switch and dim the full 12V power. This guide wires the module to an Arduino Uno and drives a 12V LED strip, with code to turn it on and off and fade its brightness.
Supplies
Everything below is what the build uses. The links go to the parts we make and test.
- Official Arduino Uno
- DIYables STEM V3, Fully Compatible with Arduino Uno R3
- USB 2.0 cable type A/B (for USB-A PC)
- USB 2.0 cable type C/B (for USB-C PC)
- 12V LED Strip
- 12V DC Cooling Fan
- DC Power Jack
- Jumper Wires
- Screw Terminal Block Shield for Arduino Uno
- Sensors/Servo Expansion Shield for Arduino Uno
- Breadboard Shield for Arduino Uno
- Enclosure for Arduino Uno
- Prototyping Base Plate & Breadboard Kit for Arduino UNO
- DIYables STEM V3 Starter Kit (Arduino included)
- DIYables Sensor Kit (18 sensors/displays)
Wiring
The module has a 2-pin control header and three screw terminals on the power side. Connect Arduino pin 9 to the PWM pin and Arduino GND to the module's GND pin. Connect the 12V adapter, through the DC power jack, to the + and − screw terminals. Connect the LED strip's positive wire to the + terminal (shared with the adapter +) and its negative wire to the LOAD terminal. Never connect the 12V line to any Arduino pin.
How It Works
The PWM signal feeds a resistor and the LED inside the module's PC817 optocoupler. Light crosses to a phototransistor that drives the MOSFET gate, so the Arduino side and load side stay isolated; their GNDs are not connected. The MOSFET is an N-channel, low-side switch between LOAD and −, so it switches the load's negative wire. A gate resistor holds the gate at 0V when the optocoupler is off. With no signal, the LED stays dark, the phototransistor stays off, and the MOSFET is OFF, acting like an open switch between LOAD and −.
Code
No library is needed. Pin 9 is set as a PWM output and starts at 0 (load off). The sketch turns the load fully on for 2 seconds, then off for 2 seconds, then ramps power up from 10% to 100% in 10% steps every half second, then back down from 90% to 0%, waiting a second before repeating. A setLoad() function converts a percent value to a 0-255 duty cycle with map() and sends it with analogWrite(), printing the percentage to the Serial Monitor at 9600 baud.
arduino-mosfet-module.ino - the sketch from the tutorial, unchanged.
Things That Go Wrong
Match the adapter voltage to the device, a 12V device needs a 12V adapter, and don't go below 6V. The FR120N only handles small current (about 2A without a heatsink); for bigger loads use the AOD4184 or LR7843. The 50A/161A chip ratings don't apply to the small board, the real limit is heat, so touch the MOSFET after a few minutes and add a heatsink or lower the current if it's too hot. Keep the 12V line away from any Arduino pin.
Full Tutorial
The complete tutorial, wiring diagram and code explanation: https://arduinogetstarted.com/tutorials/arduino-mosfet-module