ESP32 S3 UNO - MOSFET Module
This ESP32 S3 Uno MOSFET module tutorial shows you how to switch and dim a 12V load from the ESP32 S3 Uno form board. You will use an AOD4184, LR7843 or FR120N module as a fast power switch, so a 3.3V signal can control a 12V LED strip, fan, pump or motor. In the end, your load turns on, turns off and changes its power smoothly with PWM.
In this tutorial, you will:
- Learn what is inside the AOD4184, LR7843 and FR120N MOSFET modules and how to choose one
- Wire a MOSFET module, a 12V power adapter and a 12V LED strip to the ESP32 S3 Uno
- Turn a 12V load on and off with Arduino code
- Control the power of the load step by step with PWM and analogWrite()

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 ESP32 S3 Uno pin puts out only 3.3V and a tiny current. That is enough for a small LED, but a 12V LED strip, fan or pump needs much more. A MOSFET module fills this gap: your board sends a weak control signal, and the module opens or closes a strong 12V path for the load.
You will find three common versions: AOD4184 (also sold as D4184), LR7843 and FR120N. They share the same board size, the same pins, the same wiring and the same code. Only the MOSFET chip on top is different.
Why Not Just Use a Relay?
A MOSFET module has no moving parts, so it makes no clicking sound. It switches very fast, which means it can handle PWM, so you can dim a light or slow down a fan. A relay can only give full ON or full OFF. With no contacts to wear out, the MOSFET module also lasts much longer.
There is one big limit: the module works with DC loads only. Never connect it to AC mains power. For AC devices, see the ESP32 S3 Uno - Relay tutorial.
Specifications
| 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 |
Which Module Should You Pick?
The LR7843 has the lowest on-resistance, so it stays the coolest under a big current. It is the best pick for strong 12V or 24V loads, such as a long LED strip or a big motor, but it is limited to 30V.
The AOD4184 is a good all-round choice. It handles up to 40V and a strong current, so 12V, 24V and 36V loads all work well.
The FR120N accepts the highest voltage (up to 100V), but its resistance is high. Keep its current small, about 2A without a heatsink. It fits small 24V or 48V loads.
※ NOTE THAT:
Numbers like 50A or 161A are ratings of the bare chip. The small module cannot carry that much, because heat is the real limit. After a few minutes of running, carefully touch the MOSFET. If it is too hot to touch, reduce the current or add a heatsink.
How It Works
Knowing what happens inside the module helps you understand why PWM dims a light and why a low supply voltage causes trouble. The ESP32 S3 Uno signal never touches the MOSFET directly. It travels through a PC817 optocoupler first: D9 → PWM pin → small resistor → LED inside the PC817 → light → phototransistor inside the PC817 → MOSFET gate.
The MOSFET is an N-channel type placed between the LOAD and − terminals. This is called a low-side switch. Your device sits between the + and LOAD terminals. Below are the three possible states of pin D9.
Pin D9 Is LOW (0V): The Device Is Off
- No current flows into the LED inside the optocoupler, so it stays dark.
- The phototransistor stays off, and a resistor on the gate holds the MOSFET gate at 0V.
- The MOSFET is OFF and acts like an open switch between LOAD and −.
- The − wire of the device has no path to ground. No current flows, and the device gets 0V.
In code, you get this state with digitalWrite(MOSFET_PIN, LOW) or analogWrite(MOSFET_PIN, 0).
Pin D9 Is HIGH (3.3V): The Device Gets Full Power
- A few mA flow into the LED inside the optocoupler, and it lights up. It is hidden inside the chip, so you cannot see it.
- The phototransistor turns on. The MOSFET gate now gets about half of the load supply, around 6V from a 12V adapter.
- The MOSFET turns fully ON. It acts like a closed switch with a very low resistance: a few mΩ for the AOD4184 or LR7843, about 0.2Ω for the FR120N.
- Current flows in a loop: adapter + → + terminal → device → LOAD terminal → MOSFET → − terminal → adapter −.
- The device gets almost the full 12V and runs at full power.
In code, use digitalWrite(MOSFET_PIN, HIGH) or analogWrite(MOSFET_PIN, 255). The 3.3V output of the ESP32 S3 Uno is enough, because the optocoupler LED needs only a small current.
Pin D9 Sends PWM: The Device Gets Part of the Power
- Pin D9 switches between LOW and HIGH very fast, about 1000 times per second (1 kHz).
- The MOSFET follows it: ON during every HIGH part, OFF during every LOW part.
- The device receives short 12V pulses. The duty cycle is the share of time the signal is HIGH. The average voltage and average power equal the duty cycle × the full value.
With analogWrite(MOSFET_PIN, value), the value goes from 0 to 255, and the duty cycle is value / 255. With a 12V adapter, you get these results:
| analogWrite value | Duty cycle | Average voltage | Result |
|---|---|---|---|
| 0 | 0% | 0V | always off |
| 64 | about 25% | about 3V | about a quarter of the power |
| 128 | about 50% | about 6V | about half the power |
| 191 | about 75% | about 9V | about three quarters of the power |
| 255 | 100% | 12V | always on, full power |
An LED strip looks dimmer (it actually flickers, but too fast for your eyes). A fan, motor or pump turns slower, because its spinning part smooths out the pulses.
The PWM frequency matters, because the PC817 is a slow part. If the PWM is too fast, the MOSFET cannot switch fully, the device does not get clean pulses, and the MOSFET heats up. The ESP32 S3 Uno uses about 1 kHz with 8-bit resolution for analogWrite() by default, which is inside the safe range. You do not need to change anything.
Other Things to Know
The optocoupler isolates the ESP32 S3 Uno side from the 12V side. The signal GND and the load GND are not joined on the module, so 12V can never reach your board through the control pins.
The gate voltage comes from the load supply, so the load supply must be about 6V or higher. A 5V load supply will not drive the MOSFET well. If the load draws 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

The module has two sides. The small header is for your board, and the screw terminals are for the power and the load. The labels can differ a little between batches, so always read the text printed on your own module.
Control Side (2-pin header, 2.54mm pitch)
- PWM pin: connect to an ESP32 S3 Uno pin. It receives the ON/OFF or PWM signal.
- GND pin: connect to GND of the ESP32 S3 Uno.
Power Side (3 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 the MOSFET switches.
- − pin: connect to the negative wire (ground) of the load power supply.
ESP32 S3 Uno Pinout
The image below shows the pinout diagram of the ESP32 S3 Uno form board. Use it to find the Uno header pins (D9, GND…) and their GPIO numbers when you wire the circuit.

Wiring Diagram
The ESP32 S3 Uno only drives the PWM and GND pins of the module, while the 12V adapter feeds the load through the screw terminals.

This image is created using Fritzing. Click to enlarge image
| From | To |
|---|---|
| ESP32 S3 Uno D9 (GPIO46) | MOSFET module PWM |
| ESP32 S3 Uno 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 |
WARNING
D9 (GPIO46) is a boot strapping pin on the ESP32 S3 Uno. The board reads it at startup to pick the boot mode. The MOSFET module input pulls it gently to LOW, which is safe, but never connect anything that holds D9 HIGH while the board starts, or the board may fail to boot or upload code. If you have trouble uploading, unplug the PWM wire, upload, then plug it back in.
The optocoupler is already on the module, so you do not need an extra transistor or resistor. This keeps the wiring simple. Never connect the 12V wires to any pin of the ESP32 S3 Uno.
More Devices You Can Connect
The LED strip is only one example. A fan, pump, motor or lock works the same way. Keep D9 and GND as they are, and change only the screw terminal side. These rules apply to every device:
- Power adapter: + goes to the + terminal, − goes to the − terminal.
- Device: its + wire goes to the + terminal too (shared with the adapter +), and its − wire goes to LOAD.
- Voltage: match the adapter to the device (12V device, 12V adapter). Never go below 6V.
- Current: the FR120N suits small devices only (about 2A without a heatsink). For bigger loads, choose the AOD4184 or LR7843.
- Diode: any 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 −.
The same code works for all of them. The only change is for solenoids: use full power or off (100% / 0%) and skip the fading.
Wiring Example: 12V Fan

This image is created using Fritzing. Click to enlarge image
Connect the red wire to + and the black wire to LOAD. If your fan has a yellow third wire, that is the speed signal, so leave it unconnected. Add the flyback diode, because it costs almost nothing and protects the module. PWM changes the speed, but start above about 30%, because many fans do not spin at a very low duty cycle.
Wiring Example: 12V LED Strip

This image is created using Fritzing. Click to enlarge image
Connect the strip + (often labeled 12V) to + and the strip − to LOAD. An LED strip has no coil, so no diode is needed. PWM changes the brightness. Long strips draw more current, so check your strip's current before you choose the module. Use a single-color strip, because RGB and addressable strips need different wiring.
Wiring Example: 12V Water Pump

This image is created using Fritzing. Click to enlarge image
Connect the pump + to + and the pump − to LOAD. Put the diode across the pump. PWM changes the flow rate. Never let the pump run dry.
Wiring Example: 12V DC Motor

This image is created using Fritzing. Click to enlarge image
Connect the motor + to + and the motor − to LOAD. Put the diode across the motor, with the stripe on the motor + side. PWM changes the speed, but the motor turns in one direction only. To reverse it, use a motor driver like the L298N, as shown in the ESP32 S3 Uno - DC Motor tutorial.
Wiring Example: 12V Solenoid Lock

This image is created using Fritzing. Click to enlarge image
Connect the lock + to + and the lock − to LOAD. The diode is a must here. Use full ON or OFF only, with no PWM. Do not keep the lock ON for long, or it heats up. A short ON pulse is enough to unlock it.
Wiring Example: 12V Solenoid Valve

This image is created using Fritzing. Click to enlarge image
Connect the valve + to + and the valve − to LOAD. The diode is a must here too. This is a normally closed valve: ON opens it and OFF closes it. Switch it fully ON or OFF, and do not use PWM.
How To Program For MOSFET Module
Controlling the module takes only a few lines, and no library is needed. Everything uses built-in Arduino functions that the ESP32 S3 Uno core supports.
- Define the ESP32 S3 Uno pin that connects to the PWM pin of the module. D9 is GPIO46, so the code uses 46:
- Set the pin as an output:
- Turn the load fully on or fully off:
- Set a power level in percent. First convert 0–100% to the 0–255 range:
If you only need ON and OFF, digitalWrite(MOSFET_PIN, HIGH) and digitalWrite(MOSFET_PIN, LOW) work too.
ESP32 S3 Uno Code - MOSFET Module
This sketch repeats one test cycle forever. It runs the load at full power for 2 seconds, then turns it off for 2 seconds. Next, it raises the power from 10% to 100% in 10% steps every 0.5 seconds, lowers it back from 90% to 0% the same way, waits 1 second and starts again. Each step is printed to the Serial Monitor.
Detailed Instructions
- New to the ESP32 S3 Uno? Follow ESP32 S3 Uno - Getting Started first.
- Wire it up as shown in the diagram. Keep the 12V adapter unplugged for now.
- Connect the board to your computer with a USB Type-C cable.
- Open Arduino IDE, choose the ESP32S3 Dev Module board and the correct COM port.
- Copy the code above and paste it into the Arduino IDE.
- Upload the code by clicking the Upload button.
- Plug in the 12V power adapter.
- Open the Serial Monitor and set the baud rate to 9600.
- Watch the load. The LED strip stays fully bright for 2 seconds, then dark for 2 seconds. After that, it gets brighter step by step, then dimmer step by step. With a fan, you will hear the speed rise and fall.
- Tip: if the upload fails, unplug the wire from D9 (GPIO46), upload again, then reconnect it.
If the LED strip stays dark, check the 12V supply first. Then make sure the PWM and GND wires go to D9 (GPIO46) and GND of the ESP32 S3 Uno.
To learn more about PWM dimming, see the ESP32 S3 Uno - Fade LED tutorial.
Video Tutorial
Watch the video below to see this ESP32 S3 Uno project step by step.
FAQ
Can the ESP32 S3 Uno drive a MOSFET module with only 3.3V?
Yes. The PWM pin of the module drives the LED inside a PC817 optocoupler, which needs only a few mA. The 3.3V HIGH level of the ESP32 S3 Uno is enough to turn the MOSFET fully on. The MOSFET gate itself is powered from the load supply, not from your board.
Is it safe to connect a 12V load to the ESP32 S3 Uno through this module?
Yes, as long as the 12V wires go only to the screw terminals. The optocoupler keeps the 12V side separate from the board side. ESP32 S3 Uno pins are NOT 5V tolerant, so never connect 12V or 5V to any of them.
Why does the code use 46 instead of 9?
On the ESP32 S3 Uno, the Uno header label D9 is connected to GPIO46. In Arduino code you always write the GPIO number. So MOSFET_PIN = 46 means the wire goes to the D9 header pin.
Can I use another pin instead of D9?
Yes. Any ESP32 S3 Uno header pin with PWM works, for example D5 (GPIO20) or D7 (GPIO14). Change MOSFET_PIN to the new GPIO number. These pins also avoid the boot strapping problem of D9 (GPIO46), but the wiring diagram in this tutorial uses D9.
What PWM frequency does the ESP32 S3 Uno use with analogWrite()?
By default it uses about 1 kHz with 8-bit resolution (0–255). This suits the slow PC817 optocoupler on the module. If you raise the frequency a lot with analogWriteFrequency(), the MOSFET may not switch fully and can get hot.
What if my project needs more pins than the Uno headers give?
The ESP32 S3 Uno has two extra rows of holes with more GPIOs: GPIO15 and GPIO16 (I/O, PWM, analog), GPIO45 and GPIO35–GPIO42 (I/O, PWM), and GPIO47/GPIO48 (output only, PWM). Solder pin headers to use them, and write the GPIO number in code. For extra MOSFET modules, GPIO35–GPIO42 or GPIO15/GPIO16 are good choices, because they all support PWM. Be careful with two kinds of pins. First, GPIO47 and GPIO48 may run at 1.8V instead of 3.3V on some modules (especially ones with "V" in the name, like R8V or R16V), so 3.3V devices can be damaged or act strangely. Second, GPIO0, GPIO3 (D6), GPIO45 and GPIO46 (D9) are boot strapping pins, and a wrong connection can stop the board from booting or uploading code. Use the other extra pins first.
Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| No COM port shows up in Arduino IDE | USB driver missing or board not in upload mode | Install the CP210x or CH340 driver, use a data USB cable, or hold BOOT while you press RESET |
| Upload fails or the board does not start | D9 (GPIO46) is a boot strapping pin | Unplug the PWM wire from D9, upload the code, then reconnect it |
| Load never turns on | 12V adapter not plugged in or wires on the wrong terminals | Check the adapter, then check + and − on the module and the load − on LOAD |
| Load stays on all the time | Load − wire is on the − terminal instead of LOAD | Move the load − wire to the LOAD terminal |
| Load is weak or the MOSFET gets very hot | Load supply below 6V or current too high for the module | Use a 9V or 12V supply, add a heatsink, or switch to the LR7843 or AOD4184 |
| Fan does not spin at low power | Duty cycle too low for the fan to start | Start the fan above about 30% power |
| Module fails after running a motor or solenoid | No flyback diode across the coil | Add a 1N5819 or 1N4007 diode with the stripe on the load + side |
| Serial Monitor shows strange characters | Wrong baud rate | Set the Serial Monitor to 9600 baud |