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

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