Codey OnlineArduino & ESP32 component library › MOSFET Transistor
MOSFET Transistor
Active parts

MOSFET Transistor

Power MOSFET in TO-220 through-hole package. Available as N-channel (IRFZ44N, IRF540, IRLZ44N — switches loads to GND, low-side) or P-channel (IRF9540, IRF4905 — switches loads to Vcc, high-side). Capable of high currents (10A+). Use logic-level types (IRLZ44N, IRL540N) when driving directly from a 5V or 3.3V Arduino pin; standard MOSFETs (IRFZ44N, IRF540) need ~10V on the gate to fully switch on and require a gate-driver IC or a transistor pre-driver.

Pinout — MOSFET Transistor

Pin Signal Description
G Gate — control input, drive via ~100Ω with a pull-down/up resistor
D Drain — high side of switched current (N-ch: load, P-ch: GND)
S Source — low side of switched current (N-ch: GND, P-ch: Vcc)

Wiring notes

3-pin TO-220 component. Use componentId transistor-mosfet and put the part number + channel type + (optional) 'logic-level' in the label, e.g. 'IRLZ44N N-ch logic-level', 'IRFZ44N N-ch', 'IRF9540 P-ch'. Pins: G (Gate), D (Drain), S (Source). N-channel low-side: Source to GND, Drain to load (load other side to Vcc), Gate to Arduino pin via 100Ω with 10kΩ pull-down to GND. P-channel high-side: Source to Vcc, Drain to load (load other side to GND), Gate via 100Ω with 10kΩ pull-up to Vcc (active-low). For inductive loads (motors, relays, solenoids) ALWAYS add a flyback diode across the load. With a 5V/3.3V Arduino, prefer logic-level parts (IRLZ44N, IRL540N) — standard parts won't fully turn on and will overheat.

Example wiring diagram — MOSFET Transistor

From To Wire
board:D4 r1:1 green
r1:2 x1:G green
x1:S board:GND black
x1:D led1:ANODE blue
led1:CATHODE board:5V red
x1:G r2:1 purple
r2:2 board:GND black

Example Arduino code — MOSFET Transistor

This example was written and compile-checked for the arduino-uno. Codey Online adapts it to any other supported board for you.

const int mosfetGatePin = 4;

void setup() {
  pinMode(mosfetGatePin, OUTPUT);
  digitalWrite(mosfetGatePin, LOW);  // MOSFET off at startup

  Serial.begin(9600);
  Serial.println("MOSFET transistor demo: switching an LED with an N-channel logic-level MOSFET.");
}

void loop() {
  Serial.println("MOSFET ON");
  digitalWrite(mosfetGatePin, HIGH);
  delay(1000);

  Serial.println("MOSFET OFF");
  digitalWrite(mosfetGatePin, LOW);
  delay(1000);
}

Related components

⚙️

BJT Transistor

Build your Arduino or ESP32 project with AI

Describe what you want to build. Codey Online writes the code, draws the wiring diagram, compiles it and flashes your board straight from the browser.

Start for free