Using an IRF520 MOSFET as a Switch for Arduino

Using an IRF520 MOSFET as a Switch for Arduino

In this tutorial, we will explore how to use the IRF520 MOSFET module as a switch for Arduino projects. The IRF520 is a popular N-channel MOSFET that allows you to control larger loads, such as motors or lights, using a small control signal from your Arduino. By the end of this guide, you’ll be able to turn devices on and off through simple code commands.

This tutorial covers the wiring setup, how to program the Arduino to control the MOSFET, and tips for ensuring reliable operation. For a more visual explanation, check out the video (in video at 00:00).

Hardware Explained

The main component of this setup is the IRF520 MOSFET, which acts as a switch. Its gate receives a low voltage signal from the Arduino, allowing it to control the flow of current from the drain to the source, effectively turning the connected device on or off. This makes it ideal for controlling devices that require more current than the Arduino can supply directly.

In addition to the MOSFET, you will need a resistor to limit the current flowing into the gate, as well as a power supply for the load you intend to control. The IRF520 can handle up to 9.2 A of continuous current, making it suitable for a variety of applications.

Datasheet Details

ManufacturerInternational Rectifier
Part numberIRF520
Logic/IO voltage10 V (Vgs)
Supply voltage100 V (Vds)
Output current (per channel)9.2 A (max)
Peak current (per channel)33 A (max)
PWM frequency guidanceUp to 100 kHz
Input logic thresholds2-4 V (threshold voltage)
Voltage drop / RDS(on) / saturation0.27 Ω (typ.)
Thermal limits175 °C (max junction temperature)
PackageTO-220
Notes / variantsN-channel MOSFET

  • Ensure the gate voltage is sufficient to turn on the MOSFET.
  • Use a resistor (typically 10kΩ) between the Arduino pin and the gate to limit current.
  • Connect the source to ground for proper operation.
  • Be mindful of the maximum voltage and current ratings to prevent damage.
  • Consider using a heat sink if operating near maximum ratings.

Wiring Instructions

Arduino wriing for IRF520 module
Arduino wriing for IRF520 module

To wire the IRF520 MOSFET module, start by connecting VIN and GND to power supply. Connect your load to the the V+ and V-. Connect the SIG pin of the module to Pin 8 of Arduino. Don't forget the GND pin of the module to be connected to the Arduino.

Code Examples & Walkthrough

The code for controlling the IRF520 MOSFET is straightforward. First, we define a control pin using the #define directive. In the setup() function, we set this pin as an output and initialize the serial communication.


#define control 8 // pin that controls the MOSFET

void setup() {
  pinMode(control,OUTPUT); // define control pin as output
  Serial.begin(9600);
}

In the loop() function, we turn the MOSFET on and off with a delay between each action. This allows you to see the switch in action, where the load will be powered for 2 seconds and then turned off for 2 seconds.


void loop() {
  digitalWrite(control,HIGH); // Turn the MOSFET Switch ON
  delay(2000); // Wait for 2000 ms or 2 seconds

  digitalWrite(control,LOW); // Turn the MOSFET Switch OFF
  delay(2000); // Wait for 2000 ms or 2 seconds
}

For the full code and further details, please refer to the loaded code below the article. Make sure to adjust the control pin in the code to match your wiring.

Using an IRF520 MOSFET switch button with an Arduino

Demonstration / What to Expect

When you run the code, you should see the load turn on for 2 seconds and then off for 2 seconds continuously. If the load does not turn on, check your connections and ensure the power supply is adequate. Additionally, confirm that the MOSFET is wired correctly with the source connected to ground.

Be cautious of reversed polarity or floating inputs, which can lead to unexpected behavior. If the MOSFET does not switch properly, ensure that the gate is receiving the correct voltage signal from the Arduino.

Images

Using an IRF520 MOSFET switch button with an Arduino
Using IRF520 MOSFET Switch button for Arduino
Arduino wriing for IRF520 module
Arduino wriing for IRF520 module
IRF520_module-1
IRF520_module-1
IRF520_module-2
IRF520_module-2
IRF520_module-3
IRF520_module-3
105-Using an IRF520 MOSFET as a switch for Arduino
Language: C++
Copied!

Resources & references

Files📁

No files available.