How to Use MOSFETs with Arduino | Drive Loads Safely – Onzuu

2025-04-24 13:40:45

If you're working with LEDs, motors, or solenoids and want to control them with an Arduino, using a MOSFET like BSS138 is a reliable and safe way to drive higher current loads. In this guide, you'll learn how to wire, code, and safely operate a MOSFET with your Arduino project.

📌 What Is a MOSFET?

A MOSFET (Metal–Oxide–Semiconductor Field-Effect Transistor) is a switching device used to amplify or switch electronic signals. N-Channel MOSFETs like the BSS138 are commonly used for switching low-side loads.

🔌 Basic Circuit Diagram

MOSFET Arduino Circuit

This diagram shows a simple circuit where an N-channel MOSFET switches a 12V LED strip using a 5V signal from an Arduino.

💡 Arduino Code Example


int mosfetPin = 9;

void setup() {
  pinMode(mosfetPin, OUTPUT);
}

void loop() {
  analogWrite(mosfetPin, 128); // 50% brightness
  delay(1000);
  analogWrite(mosfetPin, 0);   // off
  delay(1000);
}
  

⚙️ Choosing the Right MOSFET

  • Logic-level gate: Ensure it turns on fully with 3.3V or 5V
  • Low RDS(on): For efficient switching
  • VGS(th): Threshold voltage must be lower than your microcontroller's output

📽 Video Guide

📚 Related Guides


Raj Bhatt
Raj Bhatt
Raj Bhatt launched Eletronic Lab in 1999 as a passion project to share his journey in electronics and to contribute to the DIY and maker communities. Over the years, his work has evolved into a valuable resource for hobbyists and enthusiasts, offering detailed tutorials and practical projects that inspire creativity and learning. Raj's expertise and enthusiasm for electronics shine through in every project he shares. His mission is to make electronics accessible and engaging for everyone, especially newcomers to the field. He welcomes feedback, suggestions, and error reports from readers, believing that collaboration and shared knowledge drive continuous improvement. Raj hopes you enjoy exploring his work as much as he enjoys creating it.