12. Transistors, MOSFETs & Relays
Switch loads safely without overloading an Arduino pin.
Learning outcomes
- Explain why loads need drivers
- Wire a logic-level N-MOSFET low-side switch
- Place a flyback diode correctly
- Use a relay module only with low-voltage loads
Parts and preparation
Uno, logic-level N-MOSFET, 220 ohm gate resistor, 10 k ohm gate pull-down, diode, low-voltage DC fan or lamp and external supply.
Before power: inspect wiring, confirm supply voltage and ensure all connected circuits share GND.
Driver purpose
Motors, relays and lamps often require more current or voltage than a pin can supply. A transistor uses a small control signal to switch load current from an external supply.
Logic-level MOSFET
An N-channel enhancement MOSFET can act as a low-side switch. Choose a device specified for low RDS(on) at 4.5 V or lowernot only a threshold voltage.
Flyback diode
An inductive load produces a voltage spike when switched off. Place a diode reverse-biased across the coil: cathode to positive, anode to the switched side.
Relay limits
A relay provides isolation between contacts and coil, but contact ratings still matter. This course uses only extra-low-voltage DC; do not wire mains.
Wiring and safe build sequence

- D9 -> 220 ohm -> MOSFET gate
- 10 k ohm from gate -> GND
- MOSFET source -> common GND
- Load between external +V and drain
- Diode across inductive load
- External supply GND -> Uno GND
Worked sketch
Download .ino sketchconst byte loadPin = 9;
void setup() {
pinMode(loadPin, OUTPUT);
}
void loop() {
for (int power = 0; power <= 255; power++) {
analogWrite(loadPin, power);
delay(10);
}
analogWrite(loadPin, 0);
delay(1000);
}How the code works
- The Arduino drives only the gate; the external supply provides load current.
- PWM can control a DC fan or lamp when the driver and load support it.
Test and record evidence
Practical evidence checklist
Common faults and checks
- Confirm MOSFET pin order from its datasheet.
- A non-logic-level MOSFET may overheat at 5 V gate drive.
- Common GND is essential.
Check your understanding
Q1. Why not power a fan from an I/O pin?
Show answer
Its current and inductive behavior exceed the pins safe capability.
Q2. How is a flyback diode oriented?
Show answer
Reverse-biased during normal operation: cathode to positive.