So, I wanted to control a device, with my Arduino. It was a simple enough idea, but the device used more power than the Arduino could handle. The Arduino can only put out so much current, you know? That’s where a relay comes in. It’s basically a switch that can be controlled by a small voltage, but can handle a much larger current.
I’d used mechanical relays before, the kind that click when they switch. They work fine, but they’re kind of bulky and, well, that clicking gets annoying after a while. I’d heard about solid-state relays (SSRs), but they can be a bit pricey. That’s when I stumbled on the idea of making my own relay using a MOSFET.
Getting Started
First things first, I needed a MOSFET. I grabbed an N-channel MOSFET, specifically an IRFZ44N, because I had a bunch of them in my parts bin. I also needed a resistor, a small one will do between 100 and 220 ohms.
Building the Circuit
Wiring it up was pretty straightforward. It’s just three main connections, really:
Arduino to MOSFET: I connected a digital pin from my Arduino to the gate of the MOSFET. But, I didn’t connect it directly! I put that resistor between the Arduino pin and the MOSFET gate. This is important – it limits the current going into the gate.
Ground Connection: I connected the source of the MOSFET to the ground of my Arduino and the ground of the power supply for the device.
Device Connection: I wired the drain of the MOSFET to the negative side of my device.
I double-checked all my connections, I always make sure all the grounds are connected properly, it saves a lot of headaches later. After connected, I connected the positive side of the device to the positive of my power source. So now that my device and MOSFET are both connected to the power source in a closed circuit and waiting for my signal from Arduino.
The Test
Now for the moment of truth! I uploaded a super simple Arduino sketch, one that just toggled the digital pin I was using, HIGH and LOW, every second:
void setup() {
pinMode(7, OUTPUT); // I used pin 7, you can use any digital pin
void loop() {
digitalWrite(7, HIGH);
delay(1000);
digitalWrite(7, LOW);
delay(1000);
I powered everything up, and… it worked! My device was turning on and off, silently and smoothly. No clicking! I watched that for a solid minute, then used it for my Arduino. I was pretty happy with myself.
Final Thoughts
Building a MOSFET relay is a surprisingly easy and useful project. It’s way cheaper than buying a pre-made SSR, and it’s a great way to learn about how MOSFETs work. Just remember to be careful with your wiring, and always use that resistor between the Arduino and the MOSFET gate. Have fun with it!