Arduino MKR WiFi 1010 - MOSFET Module

In this tutorial, we are going to learn:

Arduino MKR WiFi 1010 AOD4184, LR7843 and FR120N MOSFET Module

Hardware Preparation

1×Arduino MKR WiFi 1010
1×Micro USB Cable
1×Optionally, DC Power Jack
1×MOSFET Module (AOD4184, LR7843 or FR120N)
1×12V LED Strip
1×Alternatively, 12V DC Cooling Fan
1×12V Power Adapter
1×DC Power Jack (for the 12V load)
1×Jumper Wires

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of MOSFET Module

The Arduino MKR WiFi 1010 is a 3.3V board. Its pins are fine for an LED or a sensor, but a 12V fan, a DC motor, a pump, a solenoid valve, a heater or a 12V LED strip needs much more voltage and current. The MOSFET module is the bridge. The MKR only sends a weak control signal. The module then opens or closes the path for the strong current of the load.

This one tutorial works for three modules. The AOD4184 (you may also see it sold as D4184), the LR7843 and the FR120N share one board design. The size, the pins, the wiring and the code are all the same. The only thing that changes is the MOSFET chip on the board.

Good news for MKR users: the control side needs just a few mA, and 3.3V logic is enough to drive it. So you do not need a level shifter or a transistor. You connect the MKR pin straight to the module.

AOD4184 LR7843 FR120N
MOSFET Chip 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
RDS(on) (on-resistance) about 7 mΩ about 3.3 mΩ about 210 mΩ
Current without Heatsink (practical) about 10–15A about 15A about 2A
Control Logic 3.3V / 5V, active HIGH 3.3V / 5V, active HIGH 3.3V / 5V, active HIGH
Input Isolation PC817 optocoupler PC817 optocoupler PC817 optocoupler
PWM Support yes, up to about 1 kHz yes, up to about 1 kHz yes, up to about 1 kHz
Supported Loads DC only DC only DC only

A quick guide to choosing:

  • Small 24V or 48V load, low current? Take the FR120N. It is the only one rated up to 100V. But its on-resistance is the highest of the three, so plan for about 2A without a heatsink.
  • Not sure what you need? The AOD4184 is the safe middle choice. It is rated up to 40V and carries a strong current, so it suits 12V, 24V and 36V loads.
  • Big current at 12V or 24V, like a long high-power LED strip or a large motor? The LR7843 is the best. It has the lowest on-resistance, so it heats up the least. Just remember that it stops at 30V.

Do not trust the big 50A and 161A numbers too much. They describe the bare chip. On this small board, heat is what sets the real limit. Let your load run for a few minutes and then carefully touch the MOSFET. If it feels too hot, lower the current or fit a heatsink.

Pinout

AOD4184, LR7843 and FR120N MOSFET Module Pinout

On one end of the board you find the screw terminals for the power. On the other end there is a small 2-pin header with 2.54mm spacing, which plugs into a breadboard.

Screw terminals (power side, three terminals):

  • + pin: needs to be connected to the + wire of the load power supply (12V in this tutorial) and to the + wire of the load. Both wires share this one terminal.
  • LOAD pin: needs to be connected to the − wire of the load. The MOSFET turns this side on and off.
  • − pin: needs to be connected to the − wire (ground) of the load power supply.

2-pin header (control side):

  • PWM pin: needs to be connected to a PWM-capable pin of Arduino MKR WiFi 1010. The control signal goes in here.
  • GND pin: needs to be connected to a GND pin of Arduino MKR WiFi 1010.

The printed labels can change a little from one batch to another. Check the text on your own board before you wire it.

Inside the Module

The control signal travels like this: MKR pin 6 → PWM pin → small resistor → LED in the PC817 optocoupler → light → phototransistor in the PC817 → gate of the MOSFET. The MOSFET is an N-channel, low-side switch between the LOAD and − terminals. A resistor pulls its gate down to 0V whenever the optocoupler is off.

Because the signal passes through light inside the optocoupler, the MKR side and the 12V side are isolated. The module does NOT join the signal GND and the load GND together.

Now let's see what happens for each kind of signal on pin 6.

Pin 6 is HIGH (3.3V): the load runs at full power

  1. The 3.3V from pin 6 sends a few mA into the LED of the optocoupler. The LED glows inside the chip (you cannot see it from outside).
  2. The phototransistor sees the light and turns on.
  3. The gate of the MOSFET rises to about half of the load supply. With the 12V adapter, that is about 6V.
  4. The MOSFET is now fully ON, like a closed switch. Its resistance is tiny: a few mΩ (AOD4184, LR7843) or about 0.2Ω (FR120N).
  5. Current flows around the loop: adapter + → + terminal → LED strip → LOAD terminal → MOSFET → − terminal → adapter −. The strip gets nearly the full 12V.
  6. Code: digitalWrite(MOSFET_PIN, HIGH); or analogWrite(MOSFET_PIN, 255);

Pin 6 is LOW (0V): the load is off

  1. With 0V on the PWM pin, no current goes into the optocoupler LED, so it stays dark.
  2. The phototransistor stays off, and the gate resistor keeps the MOSFET gate at 0V.
  3. The MOSFET is OFF, like an open switch between LOAD and −.
  4. The − wire of the strip is cut off from the adapter −. No current can flow, so the strip sees 0V and stays dark.
  5. Code: digitalWrite(MOSFET_PIN, LOW); or analogWrite(MOSFET_PIN, 0);

Pin 6 outputs PWM: the load gets part of the power

  1. Pin 6 jumps between 0V and 3.3V very fast, about 500 to 1000 times per second.
  2. The MOSFET copies this rhythm: ON while the signal is HIGH, OFF while it is LOW.
  3. So the load gets short 12V pulses. The duty cycle is the part of the time the signal is HIGH. The average voltage and power are the duty cycle times the full value:
  • 20% duty → analogWrite(MOSFET_PIN, 51); → about 2.4V on average, one fifth of the power
  • 40% duty → analogWrite(MOSFET_PIN, 102); → about 4.8V on average
  • 60% duty → analogWrite(MOSFET_PIN, 153); → about 7.2V on average
  • 80% duty → analogWrite(MOSFET_PIN, 204); → about 9.6V on average, four fifths of the power
  1. Your eye sees the strip as dimmer, because the flicker is too fast to notice. A fan or motor turns slower, because its spinning part smooths out the pulses.
  2. Keep the frequency low, around 500 Hz to 1 kHz. The PC817 is slow. If the pulses come too fast, the MOSFET does not switch fully, the load gets messy pulses, and the MOSFET heats up. The default analogWrite() setting of the MKR is fine for this.
  3. Code: analogWrite(MOSFET_PIN, value); with a value from 0 to 255 (duty = value / 255). The sketch below moves in 10% steps from 10% to 100%.

Keep these rules in mind:

  • Never feed less than about 6V to the load side. The gate voltage comes from the load supply through a voltage divider (step 3 of the HIGH case above). This is why a 5V load supply does not work well. If your load pulls more than a few amps, use 9V or more.
  • This module is for DC only. Do not connect AC mains to it. For AC devices, use a relay instead, as in the Arduino MKR WiFi 1010 - Relay tutorial.
  • The board has NO flyback diode. With a motor, pump, solenoid or relay coil, put your own 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 −.
  • The 12V side must never touch any pin of the MKR. The MKR pins are made for 3.3V only.

Why pick a MOSFET module over a relay for DC loads? It is silent, it has no parts that wear out, it switches very fast and it lasts a long time. Most of all, it can do PWM, which a relay cannot. If you want to learn more about the PC817 chip itself, see the Arduino MKR WiFi 1010 - PC817 Optocoupler tutorial.

Wiring Diagram

The MKR pin 6 goes to the module's PWM pin and an MKR GND goes to the module's GND pin, while the 12V adapter feeds + and − through the DC power jack and the LED strip sits on + and LOAD, as the image below shows. The adapter + and the strip + share the same + terminal.

The wiring diagram between Arduino MKR WiFi 1010  with AOD4184, LR7843 or FR120N MOSFET Module

This image is created using Fritzing. Click to enlarge image

Power the MKR from USB and the LED strip from the 12V adapter. Keep the two power sources apart.

More Devices You Can Control

Want to switch something else? Swap the LED strip for one of the devices below. The two MKR wires (pin 6 to PWM, GND to GND) stay exactly as they are. You only change what is on the screw terminals.

Two things to check first:

  • Voltage: use an adapter with the same voltage as the device (12V device, 12V adapter). It also needs to be 6V or more.
  • Current: the FR120N is fine for about 2A without a heatsink. If your device pulls more, use the AOD4184 or the LR7843.

There is no need to change the code. The sketch above works with every device here. Only for the two solenoids, replace the fade with simple 100% / 0% (HIGH / LOW) steps.

Example 1: 12V Pump

Wiring a 12V pump to the MOSFET module

This image is created using Fritzing. Click to enlarge image

Connect the pump's + wire to + and its − wire to LOAD. The pump has a motor coil, so it needs a flyback diode: put a 1N5819 or 1N4007 across the pump, with the stripe (cathode) on the + wire and the other end (anode) on the − wire. The other coil devices below use the very same diode.

PWM changes the water flow. Do not let the pump run without water.

Example 2: 12V Cooling Fan

The wiring diagram between Arduino MKR MOSFET module cooling fan

This image is created using Fritzing. Click to enlarge image

Black wire to LOAD, red wire to +. Got a yellow third wire? That is the speed signal. You can leave it unconnected.

Fit the diode, like on the pump. A fan is a small motor, and the diode is cheap and safe to add.

PWM changes the speed. Below about 30%, some fans do not start at all, so begin higher.

Example 3: 12V DC Motor

DC motor 12V and MOSFET module wiring

This image is created using Fritzing. Click to enlarge image

Motor − to LOAD, motor + to +, and the diode across the two motor wires (stripe toward motor +).

PWM changes the speed, but only in one direction. The module cannot reverse the motor. For forward and backward, you need a motor driver like the L298N. See the Arduino MKR WiFi 1010 - DC Motor tutorial.

Example 4: 12V Solenoid Valve

12V solenoid valve wired through the MOSFET module

This image is created using Fritzing. Click to enlarge image

Valve + to +, valve − to LOAD. It is a coil, so add the diode.

For a normally closed valve, full power opens it and no power closes it. Only switch it ON or OFF. Do not use PWM on it.

Example 5: 12V Solenoid Lock

The wiring diagram between Solenoid lock 12V  for the MOSFET module

This image is created using Fritzing. Click to enlarge image

Lock − to LOAD, lock + to +, with the diode across the lock.

Give it 100% or 0%, nothing in between. To unlock, turn it on for a short pulse, then off again. If it stays on for long, the coil gets hot.

Example 6: 12V LED Strip (Single Color)

12V single-color LED strip wiring with the MOSFET module

This image is created using Fritzing. Click to enlarge image

This is the same load as in the main diagram. The strip's + (often marked 12V) goes to +, and its − goes to LOAD. No diode is needed here, because a LED strip has no coil.

PWM changes the brightness. A long strip pulls more current, so read its current before you pick the module. RGB and addressable strips are not wired like this.

How To Program For MOSFET Module

  • Include the library: nothing to include. analogWrite() and digitalWrite() are built in.
  • Define the pin: const int MOSFET_PIN = 6; (pin 6 of the MKR WiFi 1010 supports PWM. It is also the built-in LED pin, so the small LED on the board gets brighter and dimmer together with the load.)
  • Configure the pin as an output: pinMode(MOSFET_PIN, OUTPUT);
  • Start with the load OFF: analogWrite(MOSFET_PIN, 0);
  • Map a percent to a PWM value: int duty = map(percent, 0, 100, 0, 255); (0% gives 0, 100% gives 255)
  • Set the power: analogWrite(MOSFET_PIN, duty);. For example, 255 means full power, and about 64 means about a quarter.
  • Simple ON/OFF only: digitalWrite(MOSFET_PIN, HIGH); switches the load on, and digitalWrite(MOSFET_PIN, LOW); switches it off.

The PWM idea is the same one used in the Arduino MKR WiFi 1010 - LED - Fade tutorial. The difference is that here the 3.3V signal controls a 12V load through the module.

Arduino Code - MOSFET Module

This sketch runs in a loop. First it gives the load full power for 2 seconds and cuts it for 2 seconds. Next it raises the power by 10% every half second until it hits 100%. Then it lowers the power the same way down to 0%, rests for 1 second, and starts again. Each change is printed to the Serial Monitor.

/* * This Arduino MKR WiFi 1010 code was developed by newbiely.com * * This Arduino MKR WiFi 1010 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-mkr/arduino-mkr-wifi-1010-mosfet-module */ const int MOSFET_PIN = 6; // Arduino MKR WiFi 1010 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

  • Connect Arduino MKR WiFi 1010 to PC via Micro USB cable.
  • Wire the MOSFET module, the DC power jack and the LED strip as shown in the wiring diagram.
  • Navigate to the Arduino IDE, then select the Arduino MKR WiFi 1010 board and its port.
  • Copy the above code and paste it into Arduino IDE.
  • Click the Upload button to send the code to Arduino MKR WiFi 1010.
  • Plug the 12V adapter into the DC power jack to power the LED strip.
  • Open the Serial Monitor and set the baud rate to 9600.
  • Watch the LED strip. It shines at full brightness, goes dark, then fades up step by step and fades back down.
∞
Newbiely | Arduino IDE 2.3.8
──
☐
✕
File
Edit
Sketch
Tools
Help
Arduino MKR WiFi 1010
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino MKR WiFi 1010' 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 MKR WiFi 1010 on COM15
2

Using the 12V fan instead? Then you will hear it spin at top speed, stop, speed up and slow down again. Wire it as in "Example 2: 12V Cooling Fan" above.

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!